Update xdrv_20_hue.ino

This commit is contained in:
gemu2015 2019-09-30 10:31:13 +02:00
parent 6eb3c74689
commit 768c264d04
1 changed files with 38 additions and 16 deletions

View File

@ -276,6 +276,12 @@ void HueLightStatus1(uint8_t device, String *response)
if (bri > 254) bri = 254; // Philips Hue bri is between 1 and 254
if (bri < 1) bri = 1;
#ifdef USE_SHUTTER
if (ShutterState(device)) {
bri = (float)(Settings.shutter_invert[device-1] ? 100 - Settings.shutter_position[device-1] : Settings.shutter_position[device-1]) / 100;
}
#endif
if (light_type) {
light_state.getHSB(&hue, &sat, nullptr);
@ -452,7 +458,6 @@ void HueGlobalConfig(String *path)
response += ",\"";
}
}
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
HueConfigResponse(&response);
response += "}";
@ -502,7 +507,6 @@ void HueLights(String *path)
Script_Check_Hue(&response);
#endif
response += "}";
}
else if (path->endsWith("/state")) { // Got ID/state
path->remove(0,8); // Remove /lights/
@ -531,6 +535,16 @@ void HueLights(String *path)
response.replace("{id", String(EncodeLightId(device)));
response.replace("{cm", "on");
#ifdef USE_SHUTTER
if (ShutterState(device)) {
if (!change) {
on = hue_json["on"];
bri = on ? 1.0f : 0.0f; // when bri is not part of this request then calculate it
change = true;
}
response.replace("{re", on ? "true" : "false");
} else {
#endif
on = hue_json["on"];
switch(on)
{
@ -544,6 +558,9 @@ void HueLights(String *path)
break;
}
resp = true;
#ifdef USE_SHUTTER
}
#endif // USE_SHUTTER
}
if (light_type && (local_light_subtype >= LST_SINGLE)) {
@ -649,6 +666,12 @@ void HueLights(String *path)
resp = true;
}
if (change) {
#ifdef USE_SHUTTER
if (ShutterState(device)) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Settings.shutter_invert: %d"), Settings.shutter_invert[device-1]);
SetShutterPosition(device, bri * 100.0f );
} else
#endif
if (light_type && (local_light_subtype > LST_NONE)) { // not relay
if (!Settings.flag3.pwm_multi_channels) {
if (g_gotct) {
@ -696,7 +719,6 @@ void HueLights(String *path)
response += F("{\"state\":");
HueLightStatus1(device, &response);
HueLightStatus2(device, &response);
}
else {
response = "{}";