-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
610ba04
commit d91fb12
Showing
10 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script type="text/html" data-template-name="ha-mqtt-lawn_mower"> | ||
<div class="form-row"> | ||
<label for="node-input-server" data-i18n="node-red-contrib-ha-mqtt/common:label.mqttServer"></label> | ||
<select id="node-input-server"></select> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-device" data-i18n="node-red-contrib-ha-mqtt/common:label.deviceName"></label> | ||
<select type="text" id="node-input-device" data-i18n="[placeholder]node-red-contrib-ha-mqtt/common:label.deviceName"></select> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-name" data-i18n="node-red-contrib-ha-mqtt/common:label.entityName"></label> | ||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red-contrib-ha-mqtt/common:label.entityName"> | ||
</div> | ||
<div class="form-row"> | ||
<a href="https://www.home-assistant.io/integrations/lawn_mower.mqtt/" target="_blank" style="color:blue;"> | ||
<label for="node-input-config" data-i18n="node-red-contrib-ha-mqtt/common:label.config"></label> | ||
</a> | ||
<input type="text" id="node-input-config" data-i18n="[placeholder]node-red-contrib-ha-mqtt/common:label.config"> | ||
</div> | ||
</script> | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('ha-mqtt-lawn_mower', { | ||
category: RED._("node-red-contrib-ha-mqtt/common:homeAssistantCategory"), | ||
color: '#C0DEED', | ||
icon: "font-awesome/fa-scissors", | ||
paletteLabel: 'Lawn Mower', | ||
defaults: { | ||
server: { value: "", type: "mqtt-broker", required: true }, | ||
device: { value: "", type: "ha-mqtt-device" , required: true}, | ||
name: { value: "", required: true }, | ||
config: { value: "" } | ||
}, | ||
inputs: 1, | ||
outputs: 3, | ||
inputLabels: RED._("node-red-contrib-ha-mqtt/common:ioLabels.state"), | ||
outputLabels: [ | ||
RED._("node-red-contrib-ha-mqtt/common:ioLabels.start"), | ||
RED._("node-red-contrib-ha-mqtt/common:ioLabels.pause"), | ||
RED._("node-red-contrib-ha-mqtt/common:ioLabels.dock") | ||
], | ||
label: function () { | ||
return this.name || "lawn_mower"; | ||
}, | ||
oneditprepare: function () { | ||
$("#node-input-config").typedInput({ type: "json", types: ["json"] }) | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const HomeAssistant = require('../HomeAssistant') | ||
|
||
module.exports = function (RED) { | ||
RED.nodes.registerType('ha-mqtt-lawn_mower', function (cfg) { | ||
RED.nodes.createNode(this, cfg); | ||
this.server = RED.nodes.getNode(cfg.server); | ||
if (this.server) { | ||
this.server.register(this) | ||
const deviceNode = RED.nodes.getNode(cfg.device); | ||
const ha = new HomeAssistant(this, cfg, deviceNode.device_info) | ||
|
||
const { state_topic, pause_command_topic, dock_command_topic, start_mowing_command_topic } = ha.config | ||
|
||
const node = this | ||
node.on('input', function (msg) { | ||
const { payload, attributes } = msg | ||
try { | ||
if (payload) { | ||
ha.publish(state_topic, payload, RED._(`node-red-contrib-ha-mqtt/common:publish.state`)) | ||
} | ||
if (attributes) { | ||
ha.publish(ha.config.json_attr_t, attributes, RED._(`node-red-contrib-ha-mqtt/common:publish.attributes`)) | ||
} | ||
} catch (ex) { | ||
node.status({ fill: "red", shape: "ring", text: ex }); | ||
} | ||
}) | ||
|
||
ha.subscribe(start_mowing_command_topic, (payload) => { | ||
ha.send_payload(payload, 1, 3) | ||
|
||
ha.publish(state_topic, 'mowing', RED._(`node-red-contrib-ha-mqtt/common:publish.state`)) | ||
}) | ||
ha.subscribe(pause_command_topic, (payload) => { | ||
ha.send_payload(payload, 2, 3) | ||
|
||
ha.publish(state_topic, 'paused', RED._(`node-red-contrib-ha-mqtt/common:publish.state`)) | ||
}) | ||
ha.subscribe(dock_command_topic, (payload) => { | ||
ha.send_payload(payload, 3, 3) | ||
|
||
ha.publish(state_topic, 'docked', RED._(`node-red-contrib-ha-mqtt/common:publish.state`)) | ||
}) | ||
|
||
try { | ||
const discoveryConfig = { | ||
state_topic: null, | ||
activity_state_topic: state_topic, | ||
pause_command_topic, | ||
dock_command_topic, | ||
start_mowing_command_topic | ||
} | ||
ha.discovery(discoveryConfig, () => { | ||
this.status({ fill: "green", shape: "ring", text: `node-red-contrib-ha-mqtt/common:publish.config` }); | ||
}) | ||
} catch (ex) { | ||
this.status({ fill: "red", shape: "ring", text: `${ex}` }); | ||
} | ||
} else { | ||
this.status({ fill: "red", shape: "ring", text: `node-red-contrib-ha-mqtt/common:errors.mqttNotConfigured` }); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script type="text/html" data-help-name="ha-mqtt-lawn_mower"> | ||
<p>Lawn Mower</p> | ||
<h3>Input</h3> | ||
<dl class="message-properties"> | ||
<dt>payload <span class="property-type">string</span></dt> | ||
<dt>attributes <span class="property-type">object</span></dt> | ||
</dl> | ||
<h3>Details</h3> | ||
<p>Generate a Lawn Mower entity in Home Assistant</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script type="text/html" data-help-name="ha-mqtt-lawn_mower"> | ||
<p>割草机</p> | ||
<h3>输入</h3> | ||
<dl class="message-properties"> | ||
<dt>payload <span class="property-type">string</span></dt> | ||
<dt>attributes <span class="property-type">object</span></dt> | ||
</dl> | ||
<h3>详情</h3> | ||
<p>在HomeAssistant中生成Lawn Mower实体</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters