mirror of https://github.com/arendst/Tasmota.git
Fix Alexa bug in discovery
This commit is contained in:
parent
342af3d466
commit
21dd58e59f
|
@ -676,7 +676,7 @@ void HueGlobalConfig(String *path) {
|
||||||
CheckHue(&response, appending);
|
CheckHue(&response, appending);
|
||||||
#endif // USE_LIGHT
|
#endif // USE_LIGHT
|
||||||
#ifdef USE_ZIGBEE
|
#ifdef USE_ZIGBEE
|
||||||
ZigbeeCheckHue(&response, appending);
|
ZigbeeCheckHue(response, &appending);
|
||||||
#endif // USE_ZIGBEE
|
#endif // USE_ZIGBEE
|
||||||
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
||||||
HueConfigResponse(&response);
|
HueConfigResponse(&response);
|
||||||
|
@ -914,42 +914,44 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
|
||||||
}
|
}
|
||||||
#endif // USE_LIGHT
|
#endif // USE_LIGHT
|
||||||
|
|
||||||
void HueLights(String *path)
|
void HueLights(String *path_req)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* http://tasmota/api/username/lights/1/state?1={"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40}
|
* http://tasmota/api/username/lights/1/state?1={"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40}
|
||||||
*/
|
*/
|
||||||
String response;
|
String response;
|
||||||
int code = 200;
|
int32_t code = 200;
|
||||||
uint8_t device = 1;
|
uint8_t device = 1;
|
||||||
uint32_t device_id; // the raw device_id used by Hue emulation
|
uint32_t device_id; // the raw device_id used by Hue emulation
|
||||||
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
||||||
|
path_req->remove(0,path_req->indexOf(F("/lights"))); // Remove until /lights
|
||||||
|
String path(*path_req);
|
||||||
|
|
||||||
path->remove(0,path->indexOf(F("/lights"))); // Remove until /lights
|
if (path.endsWith(F("/lights"))) { // Got /lights
|
||||||
if (path->endsWith(F("/lights"))) { // Got /lights
|
|
||||||
response = F("{");
|
response = F("{");
|
||||||
bool appending = false;
|
bool appending = false;
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
CheckHue(&response, appending);
|
CheckHue(&response, appending);
|
||||||
#endif // USE_LIGHT
|
#endif // USE_LIGHT
|
||||||
#ifdef USE_ZIGBEE
|
#ifdef USE_ZIGBEE
|
||||||
ZigbeeCheckHue(&response, appending);
|
ZigbeeCheckHue(response, &appending);
|
||||||
#endif // USE_ZIGBEE
|
#endif // USE_ZIGBEE
|
||||||
#ifdef USE_SCRIPT_HUE
|
#ifdef USE_SCRIPT_HUE
|
||||||
Script_Check_Hue(&response);
|
Script_Check_Hue(&response);
|
||||||
#endif
|
#endif
|
||||||
response += F("}");
|
response += F("}");
|
||||||
}
|
}
|
||||||
else if (path->endsWith(F("/state"))) { // Got ID/state
|
else if (path.endsWith(F("/state"))) { // Got ID/state
|
||||||
path->remove(0,8); // Remove /lights/
|
path.remove(0,8); // Remove /lights/
|
||||||
path->remove(path->indexOf(F("/state"))); // Remove /state
|
path.remove(path.indexOf(F("/state"))); // Remove /state
|
||||||
device_id = atoi(path->c_str());
|
device_id = atoi(path.c_str());
|
||||||
device = DecodeLightId(device_id);
|
device = DecodeLightId(device_id);
|
||||||
#ifdef USE_ZIGBEE
|
#ifdef USE_ZIGBEE
|
||||||
uint16_t shortaddr;
|
uint16_t shortaddr;
|
||||||
device = DecodeLightId(device_id, &shortaddr);
|
device = DecodeLightId(device_id, &shortaddr);
|
||||||
if (shortaddr) {
|
if (shortaddr) {
|
||||||
return ZigbeeHandleHue(shortaddr, device_id, response);
|
code = ZigbeeHandleHue(shortaddr, device_id, response);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif // USE_ZIGBEE
|
#endif // USE_ZIGBEE
|
||||||
|
|
||||||
|
@ -965,16 +967,16 @@ void HueLights(String *path)
|
||||||
#endif // USE_LIGHT
|
#endif // USE_LIGHT
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(path->indexOf(F("/lights/")) >= 0) { // Got /lights/ID
|
else if(path.indexOf(F("/lights/")) >= 0) { // Got /lights/ID
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("/lights path=%s"), path->c_str());
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("/lights path=%s"), path.c_str());
|
||||||
path->remove(0,8); // Remove /lights/
|
path.remove(0,8); // Remove /lights/
|
||||||
device_id = atoi(path->c_str());
|
device_id = atoi(path.c_str());
|
||||||
device = DecodeLightId(device_id);
|
device = DecodeLightId(device_id);
|
||||||
#ifdef USE_ZIGBEE
|
#ifdef USE_ZIGBEE
|
||||||
uint16_t shortaddr;
|
uint16_t shortaddr;
|
||||||
device = DecodeLightId(device_id, &shortaddr);
|
device = DecodeLightId(device_id, &shortaddr);
|
||||||
if (shortaddr) {
|
if (shortaddr) {
|
||||||
ZigbeeHueStatus(&response, shortaddr);
|
code = ZigbeeHueStatus(&response, shortaddr);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif // USE_ZIGBEE
|
#endif // USE_ZIGBEE
|
||||||
|
@ -1000,6 +1002,14 @@ void HueLights(String *path)
|
||||||
code = 406;
|
code = 406;
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
|
if (code < 0) {
|
||||||
|
response = F("{\"error\":{\"type\":");
|
||||||
|
response += -code;
|
||||||
|
response += F(",\"address\":\"");
|
||||||
|
response += *path_req;
|
||||||
|
response += F("\",\"description\":\"\"}}");
|
||||||
|
code = 200;
|
||||||
|
}
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " Result (%s)"), response.c_str());
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " Result (%s)"), response.c_str());
|
||||||
WSSend(code, CT_APP_JSON, response);
|
WSSend(code, CT_APP_JSON, response);
|
||||||
}
|
}
|
||||||
|
@ -1011,7 +1021,7 @@ void HueGroups(String *path)
|
||||||
*/
|
*/
|
||||||
String response(F("{}"));
|
String response(F("{}"));
|
||||||
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
||||||
//AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " HueGroups (%s)"), path->c_str());
|
//AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " HueGroups (%s)"), path.c_str());
|
||||||
|
|
||||||
if (path->endsWith(F("/0"))) {
|
if (path->endsWith(F("/0"))) {
|
||||||
UnishoxStrings msg(HUE_LIGHTS);
|
UnishoxStrings msg(HUE_LIGHTS);
|
||||||
|
|
|
@ -823,7 +823,7 @@ public:
|
||||||
// If light, returns the number of channels, or 0xFF if unknown
|
// If light, returns the number of channels, or 0xFF if unknown
|
||||||
int8_t getLightChannels(void) const {
|
int8_t getLightChannels(void) const {
|
||||||
const Z_Data_Light & light = data.find<Z_Data_Light>(0);
|
const Z_Data_Light & light = data.find<Z_Data_Light>(0);
|
||||||
if (&light != nullptr) {
|
if (&light != &z_data_unk) {
|
||||||
return light.getConfig();
|
return light.getConfig();
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -744,7 +744,7 @@ void Z_Device::jsonLightState(Z_attribute_list & attr_list) const {
|
||||||
if (validPower()) { attr_list.addAttributePMEM(PSTR("Power")).setUInt(getPower()); }
|
if (validPower()) { attr_list.addAttributePMEM(PSTR("Power")).setUInt(getPower()); }
|
||||||
int32_t light_mode = -1;
|
int32_t light_mode = -1;
|
||||||
const Z_Data_Light & light = data.find<Z_Data_Light>(0);
|
const Z_Data_Light & light = data.find<Z_Data_Light>(0);
|
||||||
if (&light != nullptr) {
|
if (&light != &z_data_unk) {
|
||||||
if (light.validConfig()) {
|
if (light.validConfig()) {
|
||||||
light_mode = light.getConfig();
|
light_mode = light.getConfig();
|
||||||
}
|
}
|
||||||
|
@ -912,12 +912,12 @@ void Z_Device::setPower(bool power_on, uint8_t ep) {
|
||||||
|
|
||||||
bool Z_Device::validPower(uint8_t ep) const {
|
bool Z_Device::validPower(uint8_t ep) const {
|
||||||
const Z_Data_OnOff & onoff = data.find<Z_Data_OnOff>(ep);
|
const Z_Data_OnOff & onoff = data.find<Z_Data_OnOff>(ep);
|
||||||
return (&onoff != nullptr);
|
return (&onoff != &z_data_unk);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Z_Device::getPower(uint8_t ep) const {
|
bool Z_Device::getPower(uint8_t ep) const {
|
||||||
const Z_Data_OnOff & onoff = data.find<Z_Data_OnOff>(ep);
|
const Z_Data_OnOff & onoff = data.find<Z_Data_OnOff>(ep);
|
||||||
if (&onoff != nullptr) return onoff.getPower();
|
if (&onoff != &z_data_unk) return onoff.getPower();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ void HueLightStatus1Zigbee(uint16_t shortaddr, uint8_t local_light_subtype, Stri
|
||||||
|
|
||||||
const Z_Device & device = zigbee_devices.findShortAddr(shortaddr);
|
const Z_Device & device = zigbee_devices.findShortAddr(shortaddr);
|
||||||
const Z_Data_Light & light = device.data.find<Z_Data_Light>();
|
const Z_Data_Light & light = device.data.find<Z_Data_Light>();
|
||||||
if (&light != nullptr) {
|
if (&light != &z_data_unk) {
|
||||||
bri = light.getDimmer();
|
bri = light.getDimmer();
|
||||||
colormode = light.getColorMode();
|
colormode = light.getColorMode();
|
||||||
sat = light.getSat();
|
sat = light.getSat();
|
||||||
|
@ -112,13 +112,19 @@ void HueLightStatus2Zigbee(uint16_t shortaddr, String *response)
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigbeeHueStatus(String * response, uint16_t shortaddr) {
|
int32_t ZigbeeHueStatus(String * response, uint16_t shortaddr) {
|
||||||
*response += F("{\"state\":");
|
int8_t bulbtype = zigbee_devices.getHueBulbtype(shortaddr);
|
||||||
HueLightStatus1Zigbee(shortaddr, zigbee_devices.getHueBulbtype(shortaddr), response);
|
if (bulbtype >= 0) { // respond only if eligible
|
||||||
HueLightStatus2Zigbee(shortaddr, response);
|
*response += F("{\"state\":");
|
||||||
|
HueLightStatus1Zigbee(shortaddr, zigbee_devices.getHueBulbtype(shortaddr), response);
|
||||||
|
HueLightStatus2Zigbee(shortaddr, response);
|
||||||
|
return 200;
|
||||||
|
} else {
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigbeeCheckHue(String * response, bool &appending) {
|
void ZigbeeCheckHue(String & response, bool * appending) {
|
||||||
uint32_t zigbee_num = zigbee_devices.devicesSize();
|
uint32_t zigbee_num = zigbee_devices.devicesSize();
|
||||||
for (uint32_t i = 0; i < zigbee_num; i++) {
|
for (uint32_t i = 0; i < zigbee_num; i++) {
|
||||||
uint16_t shortaddr = zigbee_devices.devicesAt(i).shortaddr;
|
uint16_t shortaddr = zigbee_devices.devicesAt(i).shortaddr;
|
||||||
|
@ -126,13 +132,13 @@ void ZigbeeCheckHue(String * response, bool &appending) {
|
||||||
|
|
||||||
if (bulbtype >= 0) {
|
if (bulbtype >= 0) {
|
||||||
// this bulb is advertized
|
// this bulb is advertized
|
||||||
if (appending) { *response += ","; }
|
if (*appending) { response += ","; }
|
||||||
*response += "\"";
|
response += "\"";
|
||||||
*response += EncodeLightId(0, shortaddr);
|
response += EncodeLightId(0, shortaddr);
|
||||||
*response += F("\":{\"state\":");
|
response += F("\":{\"state\":");
|
||||||
HueLightStatus1Zigbee(shortaddr, bulbtype, response); // TODO
|
HueLightStatus1Zigbee(shortaddr, bulbtype, &response); // TODO
|
||||||
HueLightStatus2Zigbee(shortaddr, response);
|
HueLightStatus2Zigbee(shortaddr, &response);
|
||||||
appending = true;
|
*appending = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,16 +229,20 @@ void ZigbeeHueHS(uint16_t shortaddr, uint16_t hue, uint8_t sat) {
|
||||||
light.setHue(hue);
|
light.setHue(hue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
|
int32_t ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
|
||||||
uint8_t bri, sat;
|
uint8_t bri, sat;
|
||||||
uint16_t ct, hue;
|
uint16_t ct, hue;
|
||||||
int code = 200;
|
int code = 200;
|
||||||
|
|
||||||
|
int8_t bulbtype = zigbee_devices.getHueBulbtype(shortaddr);
|
||||||
|
if (bulbtype < 0) { // respond only if eligible
|
||||||
|
response = F("{}");
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
bool resp = false; // is the response non null (add comma between parameters)
|
bool resp = false; // is the response non null (add comma between parameters)
|
||||||
bool on = false;
|
bool on = false;
|
||||||
|
|
||||||
uint8_t bulbtype = zigbee_devices.getHueBulbtype(shortaddr);
|
|
||||||
|
|
||||||
const size_t buf_size = 100;
|
const size_t buf_size = 100;
|
||||||
char * buf = (char*) malloc(buf_size);
|
char * buf = (char*) malloc(buf_size);
|
||||||
UnishoxStrings msg(HUE_LIGHTS);
|
UnishoxStrings msg(HUE_LIGHTS);
|
||||||
|
@ -368,10 +378,8 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
|
||||||
else {
|
else {
|
||||||
response = msg[HUE_ERROR_JSON];
|
response = msg[HUE_ERROR_JSON];
|
||||||
}
|
}
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " Result (%s)"), response.c_str());
|
|
||||||
WSSend(code, CT_APP_JSON, response);
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_WEBSERVER && USE_EMULATION && USE_EMULATION_HUE
|
#endif // USE_WEBSERVER && USE_EMULATION && USE_EMULATION_HUE
|
||||||
|
|
|
@ -1353,7 +1353,7 @@ void ZCLFrame::computeSyntheticAttributes(Z_attribute_list& attr_list) {
|
||||||
uint8_t brightness = 255;
|
uint8_t brightness = 255;
|
||||||
if (device.valid()) {
|
if (device.valid()) {
|
||||||
const Z_Data_Light & light = device.data.find<Z_Data_Light>(_srcendpoint);
|
const Z_Data_Light & light = device.data.find<Z_Data_Light>(_srcendpoint);
|
||||||
if ((&light != nullptr) && (light.validDimmer())) {
|
if ((&light != &z_data_unk) && (light.validDimmer())) {
|
||||||
// Dimmer has a valid value
|
// Dimmer has a valid value
|
||||||
brightness = changeUIntScale(light.getDimmer(), 0, 254, 0, 255); // range is 0..255
|
brightness = changeUIntScale(light.getDimmer(), 0, 254, 0, 255); // range is 0..255
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue