ha: discovery refactoring

- retain setting
- generate topic and message in the discovery object instead of
creating them all at once
- re-implement relays, lights and sensors discovery
- rework name normalization, use relative magnitude indexes
- replace original lights code with schema: json, subscribe to a special
topic to handle lights instead of using the common API
(still wip - colors, hs, temperature settings)

resolve #630
resolve #1564
resolve #2403
This commit is contained in:
Maxim Prokhorov
2021-01-26 00:50:45 +03:00
parent 0b43af8ed9
commit 4d157ccd5b
26 changed files with 23234 additions and 23031 deletions

View File

@@ -809,15 +809,6 @@ function doScan() {
return false;
}
function doHAConfig() {
$("#haConfig")
.text("")
.height(0)
.show();
sendAction("haconfig", {});
return false;
}
function doDebugCommand() {
var el = $("input[name='dbgcmd']");
var command = el.val();
@@ -1965,18 +1956,6 @@ function processData(data) {
$("#scanResult").show();
}
// -----------------------------------------------------------------------------
// Home Assistant
// -----------------------------------------------------------------------------
if ("haConfig" === key) {
send("{}");
$("#haConfig")
.append(new Text(value))
.height($("#haConfig")[0].scrollHeight);
return;
}
// -----------------------------------------------------------------------------
// Relays scheduler
// -----------------------------------------------------------------------------
@@ -2371,7 +2350,6 @@ $(function() {
$(".button-generate-password").on("click", doGeneratePassword);
$(".button-reboot").on("click", doReboot);
$(".button-reconnect").on("click", doReconnect);
$(".button-ha-config").on("click", doHAConfig);
$(".button-dbgcmd").on("click", doDebugCommand);
$("input[name='dbgcmd']").enterKey(doDebugCommand);
$(".button-dbg-clear").on("click", doDebugClear);

View File

@@ -1433,40 +1433,41 @@
<div class="page">
<fieldset>
<legend>Discover</legend>
<legend><a rel="noopener" target="_blank" href="https://www.home-assistant.io/docs/mqtt/discovery/">Discovery</a></legend>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Discover</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="haEnabled" tabindex="14" /></div>
<label class="pure-u-1 pure-u-lg-1-4">Enabled</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="haEnabled" /></div>
<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">
Home Assistant auto-discovery feature. Enable and save to add the device to your HA console.
Home Assistant MQTT discovery. Enable / disable, then save to trigger the update.
</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Prefix</label>
<input class="pure-u-1 pure-u-lg-1-4" name="haPrefix" type="text" tabindex="15" />
</div>
<legend>Configuration</legend>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Configuration</label>
<div class="pure-u-1-4 pure-u-lg-3-4"><button type="button" class="pure-button button-ha-config pure-u-1-3">Show</button></div>
<input class="pure-u-1 pure-u-lg-1-4" name="haPrefix" type="text" />
<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">
These are the settings you should copy to your Home Assistant "configuration.yaml" file.
If any of the sections below (switch, light, sensor) already exists, do not duplicate it,
simply copy the contents of the section below the ones already present.
The prefix for the discovery topic e.g. <code><strong>&lt;prefix&gt;</strong>/switch/espurna-123456/config</code>
</div>
</div>
<div class="pure-g">
<textarea class="pure-u-1 terminal" id="haConfig" name="haConfig" wrap="off" readonly></textarea>
</div>
<legend>MQTT</legend>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Retain</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="haRetain" /></div>
<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">
Set the <strong>Retain</strong> flag when sending the messages.
</div>
</div>
</fieldset>
</div>