Merge pull request #8412 from s-hadinger/hue_modelid

Change Philips Hue emulation now exposes modelId and manufacturerId
This commit is contained in:
Theo Arends 2020-05-10 20:38:30 +02:00 committed by GitHub
commit 9f2f01529b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 7 deletions

View File

@ -14,6 +14,7 @@
- Change default PWM Frequency to 977 Hz from 223 Hz - Change default PWM Frequency to 977 Hz from 223 Hz
- Change minimum PWM Frequency from 100 Hz to 40 Hz - Change minimum PWM Frequency from 100 Hz to 40 Hz
- Change PWM updated to the latest version of Arduino PR #7231 - Change PWM updated to the latest version of Arduino PR #7231
- Change Philips Hue emulation now exposes modelId and manufacturerId
### 8.2.0.5 20200425 ### 8.2.0.5 20200425

View File

@ -144,9 +144,9 @@ const char HUE_LIGHTS_STATUS_JSON1_SUFFIX[] PROGMEM =
const char HUE_LIGHTS_STATUS_JSON2[] PROGMEM = const char HUE_LIGHTS_STATUS_JSON2[] PROGMEM =
",\"type\":\"Extended color light\"," ",\"type\":\"Extended color light\","
"\"name\":\"%s\"," "\"name\":\"%s\","
"\"modelid\":\"LCT007\"," "\"modelid\":\"%s\","
"\"uniqueid\":\"%s\"," "\"manufacturername\":\"%s\","
"\"swversion\":\"5.50.1.19085\"}"; "\"uniqueid\":\"%s\"}";
const char HUE_GROUP0_STATUS_JSON[] PROGMEM = const char HUE_GROUP0_STATUS_JSON[] PROGMEM =
"{\"name\":\"Group 0\"," "{\"name\":\"Group 0\","
"\"lights\":[{l1]," "\"lights\":[{l1],"
@ -358,7 +358,7 @@ bool HueActive(uint8_t device) {
void HueLightStatus2(uint8_t device, String *response) void HueLightStatus2(uint8_t device, String *response)
{ {
const size_t buf_size = 192; const size_t buf_size = 300;
char * buf = (char*) malloc(buf_size); char * buf = (char*) malloc(buf_size);
const size_t max_name_len = 32; const size_t max_name_len = 32;
char fname[max_name_len + 1]; char fname[max_name_len + 1];
@ -376,7 +376,11 @@ void HueLightStatus2(uint8_t device, String *response)
} }
fname[fname_len] = 0x00; fname[fname_len] = 0x00;
} }
snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON2, fname, GetHueDeviceId(device).c_str()); snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON2,
escapeJSONString(fname).c_str(),
escapeJSONString(Settings.user_template_name).c_str(),
PSTR("Tasmota"),
GetHueDeviceId(device).c_str());
*response += buf; *response += buf;
free(buf); free(buf);
} }

View File

@ -127,6 +127,7 @@ public:
void setFriendlyName(uint16_t shortaddr, const char * str); void setFriendlyName(uint16_t shortaddr, const char * str);
const char * getFriendlyName(uint16_t shortaddr) const; const char * getFriendlyName(uint16_t shortaddr) const;
const char * getModelId(uint16_t shortaddr) const; const char * getModelId(uint16_t shortaddr) const;
const char * getManufacturerId(uint16_t shortaddr) const;
void setReachable(uint16_t shortaddr, bool reachable); void setReachable(uint16_t shortaddr, bool reachable);
// get next sequence number for (increment at each all) // get next sequence number for (increment at each all)
@ -589,6 +590,15 @@ const char * Z_Devices::getModelId(uint16_t shortaddr) const {
return nullptr; return nullptr;
} }
const char * Z_Devices::getManufacturerId(uint16_t shortaddr) const {
int32_t found = findShortAddr(shortaddr);
if (found >= 0) {
const Z_Device & device = devicesAt(found);
return device.manufacturerId;
}
return nullptr;
}
void Z_Devices::setReachable(uint16_t shortaddr, bool reachable) { void Z_Devices::setReachable(uint16_t shortaddr, bool reachable) {
Z_Device & device = getShortAddr(shortaddr); Z_Device & device = getShortAddr(shortaddr);
if (&device == nullptr) { return; } // don't crash if not found if (&device == nullptr) { return; } // don't crash if not found

View File

@ -75,16 +75,21 @@ void HueLightStatus1Zigbee(uint16_t shortaddr, uint8_t local_light_subtype, Stri
void HueLightStatus2Zigbee(uint16_t shortaddr, String *response) void HueLightStatus2Zigbee(uint16_t shortaddr, String *response)
{ {
const size_t buf_size = 192; const size_t buf_size = 300;
char * buf = (char*) malloc(buf_size); char * buf = (char*) malloc(buf_size);
const char * friendlyName = zigbee_devices.getFriendlyName(shortaddr); const char * friendlyName = zigbee_devices.getFriendlyName(shortaddr);
const char * modelId = zigbee_devices.getModelId(shortaddr);
const char * manufacturerId = zigbee_devices.getManufacturerId(shortaddr);
char shortaddrname[8]; char shortaddrname[8];
snprintf_P(shortaddrname, sizeof(shortaddrname), PSTR("0x%04X"), shortaddr); snprintf_P(shortaddrname, sizeof(shortaddrname), PSTR("0x%04X"), shortaddr);
snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON2, snprintf_P(buf, buf_size, HUE_LIGHTS_STATUS_JSON2,
(friendlyName) ? friendlyName : shortaddrname, (friendlyName) ? escapeJSONString(friendlyName).c_str() : shortaddrname,
(modelId) ? escapeJSONString(modelId).c_str() : PSTR("Unknown"),
(manufacturerId) ? escapeJSONString(manufacturerId).c_str() : PSTR("Tasmota"),
GetHueDeviceId(shortaddr).c_str()); GetHueDeviceId(shortaddr).c_str());
*response += buf; *response += buf;
free(buf); free(buf);
} }