Skip to content

Commit cd1a7e0

Browse files
authored
adaptive lighting support for CCT lights (#1028)
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.
1 parent f53a3de commit cd1a7e0

8 files changed

+1294
-7
lines changed

mos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ libs:
145145
- location: https://github.com/mongoose-os-libs/core
146146
- location: https://github.com/mongoose-os-libs/file-logger
147147
- location: https://github.com/mongoose-os-libs/homekit-adk
148+
version: pull/10/head # use unmerged changes from https://github.com/mongoose-os-libs/homekit-adk/pull/10
148149
- location: https://github.com/mongoose-os-libs/http-server
149150
- location: https://github.com/mongoose-os-libs/ota-http-server
150151
- location: https://github.com/mongoose-os-libs/rpc-service-config
@@ -187,6 +188,7 @@ conds:
187188
# XXX: fix size calculation with and without BLE
188189
XHAP_ACCESSORY_SERVER_SIZE: 1680
189190
HAP_LOG_LEVEL: 0 # This saves 36K on esp8266.
191+
HAP_TLV_NO_LOG: 1 # Saves us stack
190192
HAP_DISABLE_ASSERTS: 1 # 32K
191193
HAP_DISABLE_PRECONDITIONS: 1 # 40K
192194

src/ShellyDuo/shelly_init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
4949
return;
5050
}
5151

52+
// Use adaptive lightning when possible (CCT)
53+
std::unique_ptr<hap::AdaptiveLighting> adaptive_light;
54+
adaptive_light.reset(new hap::AdaptiveLighting(hap_light.get(), lb_cfg));
55+
auto st = adaptive_light->Init();
56+
if (st.ok()) {
57+
hap_light->SetAdaptiveLight(std::move(adaptive_light));
58+
}
59+
5260
mgos::hap::Accessory *pri_acc = accs->front().get();
5361
shelly::hap::LightBulb *light_ref = hap_light.get();
5462
hap_light->set_primary(true);

src/ShellyRGBW2/shelly_init.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "shelly_cct_controller.hpp"
19+
#include "shelly_hap_adaptive_lighting.hpp"
1920
#include "shelly_hap_input.hpp"
2021
#include "shelly_hap_light_bulb.hpp"
2122
#include "shelly_input_pin.hpp"
@@ -114,6 +115,14 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
114115
return;
115116
}
116117

118+
// Use adaptive lightning when possible (CCT)
119+
std::unique_ptr<hap::AdaptiveLighting> adaptive_light;
120+
adaptive_light.reset(new hap::AdaptiveLighting(hap_light.get(), lb_cfg));
121+
st = adaptive_light->Init();
122+
if (st.ok()) {
123+
hap_light->SetAdaptiveLight(std::move(adaptive_light));
124+
}
125+
117126
bool to_pri_acc = (ndev == 1); // only device will become primary accessory
118127
// regardless of sw_hidden status
119128
bool sw_hidden = is_optional && lb_cfg->svc_hidden;

src/shelly_common.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
#define SHELLY_HAP_IID_BASE_TEMPERATURE_SENSOR 0xd00
6767
#define SHELLY_HAP_IID_BASE_LEAK_SENSOR 0xe00
6868
#define SHELLY_HAP_IID_BASE_SMOKE_SENSOR 0xf00
69+
#define SHELLY_HAP_IID_BASE_ADAPTIVE_LIGHTING 0x1000
70+
71+
#define kChangeReasonAuto "AUTO"
72+
#define kChangeReasonAutoWithNotification "AUTO_NOTIFICATION"
73+
#define kCHangeReasonHAP "HAP"
6974

7075
namespace shelly {
7176

0 commit comments

Comments
 (0)