Skip to content

Commit

Permalink
adaptive lighting support for CCT lights (#1028)
Browse files Browse the repository at this point in the history
this adds the homekit feature adaptive lightning.
as this is a non-officially documented feature by apple homekit
specification, it relies on the reverse engineering done by homebridge.
  • Loading branch information
markirb authored Jan 25, 2023
1 parent f53a3de commit cd1a7e0
Show file tree
Hide file tree
Showing 8 changed files with 1,294 additions and 7 deletions.
2 changes: 2 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ libs:
- location: https://github.com/mongoose-os-libs/core
- location: https://github.com/mongoose-os-libs/file-logger
- location: https://github.com/mongoose-os-libs/homekit-adk
version: pull/10/head # use unmerged changes from https://github.com/mongoose-os-libs/homekit-adk/pull/10
- location: https://github.com/mongoose-os-libs/http-server
- location: https://github.com/mongoose-os-libs/ota-http-server
- location: https://github.com/mongoose-os-libs/rpc-service-config
Expand Down Expand Up @@ -187,6 +188,7 @@ conds:
# XXX: fix size calculation with and without BLE
XHAP_ACCESSORY_SERVER_SIZE: 1680
HAP_LOG_LEVEL: 0 # This saves 36K on esp8266.
HAP_TLV_NO_LOG: 1 # Saves us stack
HAP_DISABLE_ASSERTS: 1 # 32K
HAP_DISABLE_PRECONDITIONS: 1 # 40K

Expand Down
8 changes: 8 additions & 0 deletions src/ShellyDuo/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
return;
}

// Use adaptive lightning when possible (CCT)
std::unique_ptr<hap::AdaptiveLighting> adaptive_light;
adaptive_light.reset(new hap::AdaptiveLighting(hap_light.get(), lb_cfg));
auto st = adaptive_light->Init();
if (st.ok()) {
hap_light->SetAdaptiveLight(std::move(adaptive_light));
}

mgos::hap::Accessory *pri_acc = accs->front().get();
shelly::hap::LightBulb *light_ref = hap_light.get();
hap_light->set_primary(true);
Expand Down
9 changes: 9 additions & 0 deletions src/ShellyRGBW2/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "shelly_cct_controller.hpp"
#include "shelly_hap_adaptive_lighting.hpp"
#include "shelly_hap_input.hpp"
#include "shelly_hap_light_bulb.hpp"
#include "shelly_input_pin.hpp"
Expand Down Expand Up @@ -114,6 +115,14 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
return;
}

// Use adaptive lightning when possible (CCT)
std::unique_ptr<hap::AdaptiveLighting> adaptive_light;
adaptive_light.reset(new hap::AdaptiveLighting(hap_light.get(), lb_cfg));
st = adaptive_light->Init();
if (st.ok()) {
hap_light->SetAdaptiveLight(std::move(adaptive_light));
}

bool to_pri_acc = (ndev == 1); // only device will become primary accessory
// regardless of sw_hidden status
bool sw_hidden = is_optional && lb_cfg->svc_hidden;
Expand Down
5 changes: 5 additions & 0 deletions src/shelly_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
#define SHELLY_HAP_IID_BASE_TEMPERATURE_SENSOR 0xd00
#define SHELLY_HAP_IID_BASE_LEAK_SENSOR 0xe00
#define SHELLY_HAP_IID_BASE_SMOKE_SENSOR 0xf00
#define SHELLY_HAP_IID_BASE_ADAPTIVE_LIGHTING 0x1000

#define kChangeReasonAuto "AUTO"
#define kChangeReasonAutoWithNotification "AUTO_NOTIFICATION"
#define kCHangeReasonHAP "HAP"

namespace shelly {

Expand Down
Loading

0 comments on commit cd1a7e0

Please sign in to comment.