Skip to content

Commit

Permalink
Separate device name for alexa integration (xoseperez#1727)
Browse files Browse the repository at this point in the history
Allow defining custom device name for alexa integration, other than hostname.
Still uses hostname as a fallback.
  • Loading branch information
m-kozlowski authored and mcspr committed May 23, 2019
1 parent aac2e1e commit 471a638
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/espurna/alexa.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bool _alexaWebSocketOnReceive(const char * key, JsonVariant& value) {
void _alexaWebSocketOnSend(JsonObject& root) {
root["alexaVisible"] = 1;
root["alexaEnabled"] = alexaEnabled();
root["alexaName"] = getSetting("alexaName");
}

void _alexaConfigure() {
Expand Down Expand Up @@ -84,9 +85,11 @@ void alexaSetup() {
alexa.createServer(!WEB_SUPPORT);
alexa.setPort(80);

// Uses hostname as base name for all devices
// TODO: use custom switch name when available
String hostname = getSetting("hostname");
// Use custom alexa hostname if defined, device hostname otherwise
String hostname = getSetting("alexaName", ALEXA_HOSTNAME);
if (hostname.length() == 0) {
hostname = getSetting("hostname");
}

// Lights
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
Expand Down
5 changes: 5 additions & 0 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,11 @@
#define ALEXA_ENABLED 1
#endif

#ifndef ALEXA_HOSTNAME
#define ALEXA_HOSTNAME ""
#endif


// -----------------------------------------------------------------------------
// MQTT RF BRIDGE
// -----------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions code/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ <h2>General configuration values</h2>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="alexaEnabled" /></div>
</div>

<div class="pure-g module module-alexa">
<label class="pure-u-1 pure-u-lg-1-4">Alexa device name</label>
<input name="alexaName" class="pure-u-1 pure-u-lg-1-4" maxlength="31" type="text" action="reboot" tabindex="7" />
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">
This name will be used in Alexa integration.<br />
</div>
</div>


</fieldset>

</div>
Expand Down

0 comments on commit 471a638

Please sign in to comment.