Skip to content

Commit

Permalink
Merge pull request #6798 from s-hadinger/alexa_hide_dev
Browse files Browse the repository at this point in the history
Add hide Alexa objects with friendlyname starting with '$'
  • Loading branch information
arendst authored Oct 31, 2019
2 parents 50e1038 + d36d38a commit c797f06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions tasmota/_changelog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add command SetOption73 0/1 to re-enable HTTP Cross-Origin Resource Sharing (CORS) now default disabled (#6767)
* Add frequency to ADE7953 energy monitor as used in Shelly 2.5 by ljakob (#6778)
* Add command SetOption74 0/1 to enable DS18x20 internal pull-up and remove define DS18B20_INTERNAL_PULLUP (#6795)
* Add hide Alexa objects with friendlyname starting with '$' (#6722, #6762)
*
* 6.7.1.1 20191026
* Change ArduinoSlave to TasmotaSlave (Experimental)
Expand Down
44 changes: 28 additions & 16 deletions tasmota/xdrv_20_hue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ void HueLightStatus1(uint8_t device, String *response)
response->replace("{light_status}", light_status);
}

// Check whether this device should be reported to Alexa or considered hidden.
// Any device whose friendly name start with "$" is considered hidden
bool HueActive(uint8_t device) {
if (device > MAX_FRIENDLYNAMES) { device = MAX_FRIENDLYNAMES; }
return '$' != Settings.friendlyname[device-1][0];
}

void HueLightStatus2(uint8_t device, String *response)
{
*response += FPSTR(HUE_LIGHTS_STATUS_JSON2);
Expand Down Expand Up @@ -442,20 +449,22 @@ uint32_t findEchoGeneration(void) {
return gen;
}

void HueGlobalConfig(String *path)
{
void HueGlobalConfig(String *path) {
String response;
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;

path->remove(0,1); // cut leading / to get <id>
response = F("{\"lights\":{\"");
response = F("{\"lights\":{");
bool appending = false; // do we need to add a comma to append
for (uint32_t i = 1; i <= maxhue; i++) {
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
HueLightStatus2(i, &response);
if (i < maxhue) {
response += ",\"";
if (HueActive(i)) {
if (appending) { response += ","; }
response += "\"";
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
HueLightStatus2(i, &response);
appending = true;
}
}
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
Expand Down Expand Up @@ -493,14 +502,17 @@ void HueLights(String *path)

path->remove(0,path->indexOf("/lights")); // Remove until /lights
if (path->endsWith("/lights")) { // Got /lights
response = "{\"";
response = "{";
bool appending = false;
for (uint32_t i = 1; i <= maxhue; i++) {
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
HueLightStatus2(i, &response);
if (i < maxhue) {
response += ",\"";
if (HueActive(i)) {
if (appending) { response += ","; }
response += "\"";
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
HueLightStatus2(i, &response);
appending = true;
}
}
#ifdef USE_SCRIPT_HUE
Expand Down

0 comments on commit c797f06

Please sign in to comment.