From ad3b3ce3dce3811cdc06e87585914c60c91e02af Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Fri, 19 May 2017 02:37:28 +0200 Subject: [PATCH] [WIP] Zwave panel (#260) * Add Node card * Add Node selection dropdown * Add refresh node service and auto visible options * Add replace node and replace failed node to node options * Add node information * Add node group configuration * Add Wakeup and fix group associations * Make Node info expandable * Add refresh entity * Cleanup * Add set_config and print_config parameter * styling * indention * lint error * thank you @adgelbfish * Hide correctly * Add Entity info * Indents * Add Group fetched from API * Add API to get config options * Initialize empty array * Add config handling * add OZW log * missing style * Bug in other groupmembers * Fix set-configparameter * Fix set-association * Tweaks to associations * Add usercodes * Tweaks * Tweaks * Target node text * Move computed servicedata to property * Start splitting * Split part 2, network * Splitting 3 * cleanup * refresh on setting with delay * fix servicedata * Splitting 4 groups * Splitting 5 config and wakeup * Splitting done. * Final tweaks, lint and removal of logging --- panels/zwave/ha-panel-zwave.html | 381 ++++++++++++++++++++--- panels/zwave/zwave-groups.html | 222 +++++++++++++ panels/zwave/zwave-log.html | 52 ++++ panels/zwave/zwave-network.html | 86 +++++ panels/zwave/zwave-node-config.html | 312 +++++++++++++++++++ panels/zwave/zwave-node-information.html | 81 +++++ panels/zwave/zwave-usercodes.html | 171 ++++++++++ 7 files changed, 1266 insertions(+), 39 deletions(-) create mode 100644 panels/zwave/zwave-groups.html create mode 100644 panels/zwave/zwave-log.html create mode 100644 panels/zwave/zwave-network.html create mode 100644 panels/zwave/zwave-node-config.html create mode 100644 panels/zwave/zwave-node-information.html create mode 100644 panels/zwave/zwave-usercodes.html diff --git a/panels/zwave/ha-panel-zwave.html b/panels/zwave/ha-panel-zwave.html index c52aad08a4..f19fdd5dd2 100644 --- a/panels/zwave/ha-panel-zwave.html +++ b/panels/zwave/ha-panel-zwave.html @@ -4,9 +4,19 @@ + + + + + + + + + + @@ -112,6 +225,196 @@ Polymer({ type: Boolean, value: false, }, + + nodes: { + type: Array, + computed: 'computeNodes(hass)' + }, + + selectedNode: { + type: Number, + value: -1, + observer: 'selectedNodeChanged' + }, + + config: { + type: Array, + value: function () { + return []; + } + }, + + entities: { + type: Array, + computed: 'computeEntities(selectedNode)', + }, + + entityInfoActive: { + type: Boolean, + }, + + selectedEntity: { + type: Number, + value: -1, + observers: ['computeIsEntitySelected', + 'computeRefreshEntityServiceData'] + }, + + selectedEntityAttrs: { + type: Array, + computed: 'computeSelectedEntityAttrs(selectedEntity)' + }, + + groups: { + type: Array, + }, + + newNodeNameInput: { + type: String, + }, + + userCodes: { + type: Array, + value: function () { + return []; + }, + }, + + hasNodeUserCodes: { + type: Boolean, + value: false + }, + }, + + computeNodes: function (hass) { + return Object.keys(hass.states) + .map(function (key) { return hass.states[key]; }) + .filter(function (ent) { + return (!ent.attributes.hidden && + (ent.entity_id).match('zwave[.]')); + }) + .sort(function (entityA, entityB) { + if (entityA.entity_id < entityB.entity_id) { + return -1; + } + if (entityA.entity_id > entityB.entity_id) { + return 1; + } + return 0; + }); + }, + + computeEntities: function (selectedNode) { + if (!this.nodes || selectedNode === -1) return -1; + var hass = this.hass; + var nodeid = this.nodes[this.selectedNode].attributes.node_id; + return Object.keys(hass.states) + .map(function (key) { return hass.states[key]; }) + .filter(function (ent) { + if (ent.attributes.node_id === undefined) { + return false; + } + return (!ent.attributes.hidden && + 'node_id' in ent.attributes && + ent.attributes.node_id === nodeid && + (!(ent.entity_id).match('zwave[.]'))); + }) + .sort(function (entityA, entityB) { + if (entityA.entity_id < entityB.entity_id) { + return -1; + } + if (entityA.entity_id > entityB.entity_id) { + return 1; + } + return 0; + }); + }, + + selectedNodeChanged: function (selectedNode) { + if (selectedNode === -1) return; + this.selectedConfigParameter = -1; + this.selectedConfigParameterValue = -1; + this.selectedGroup = -1; + var configData = []; + this.hass.callApi('GET', 'zwave/config/' + this.nodes[selectedNode].attributes.node_id).then(function (configs) { + Object.entries(configs).forEach(([key, value]) => { + configData.push({ key, value }); + }); + this.config = configData; + }.bind(this)); + var groupData = []; + this.hass.callApi('GET', 'zwave/groups/' + this.nodes[selectedNode].attributes.node_id).then(function (groups) { + Object.entries(groups).forEach(([key, value]) => { + groupData.push({ key, value }); + }); + this.groups = groupData; + }.bind(this)); + var userCodes = []; + this.hasNodeUserCodes = false; + this.notifyPath('hasNodeUserCodes'); + this.hass.callApi('GET', 'zwave/usercodes/' + this.nodes[selectedNode].attributes.node_id).then(function (usercodes) { + Object.entries(usercodes).forEach(([key, value]) => { + userCodes.push({ key, value }); + }); + this.userCodes = userCodes; + if (Object.keys(userCodes).length === 0) { + this.hasNodeUserCodes = false; + } else { + this.hasNodeUserCodes = true; + } + this.notifyPath('hasNodeUserCodes'); + }.bind(this)); + }, + + computeSelectedEntityAttrs: function (selectedEntity) { + if (selectedEntity === -1) return 'No entity selected'; + var entityAttrs = this.entities[selectedEntity].attributes; + var att = []; + Object.entries(entityAttrs).forEach(([key, value]) => { + att.push(key + ': ' + value); + }); + return att.sort(); + }, + + computeSelectCaption: function (stateObj) { + return window.hassUtil.computeStateName(stateObj) + ' (Node:' + + stateObj.attributes.node_id + ' ' + + stateObj.attributes.query_stage + ')'; + }, + + computeSelectCaptionEnt: function (stateObj) { + return (window.hassUtil.computeDomain(stateObj) + '.' + + window.hassUtil.computeStateName(stateObj)); + }, + + computeIsNodeSelected: function () { + return (!this.nodes || this.selectedNode === -1); + }, + + computeIsEntitySelected: function (selectedEntity) { + return (selectedEntity === -1); + }, + + computeNodeServiceData: function (selectedNode) { + return { node_id: this.nodes[selectedNode].attributes.node_id }; + }, + + computeGetNodeName: function (selectedNode) { + if (this.selectedNode === -1 || + !this.nodes[selectedNode].entity_id) return -1; + var str = (this.nodes[selectedNode].entity_id); + var name = str.replace('zwave.', ''); + return name; + }, + + computeNodeNameServiceData: function (newNodeNameInput) { + return { node_id: this.nodes[this.selectedNode].attributes.node_id, + name: newNodeNameInput }; + }, + + computeRefreshEntityServiceData: function (selectedEntity) { + if (selectedEntity === -1) return -1; + return { entity_id: this.entities[selectedEntity].entity_id }; }, }); diff --git a/panels/zwave/zwave-groups.html b/panels/zwave/zwave-groups.html new file mode 100644 index 0000000000..9a0d130023 --- /dev/null +++ b/panels/zwave/zwave-groups.html @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + diff --git a/panels/zwave/zwave-log.html b/panels/zwave/zwave-log.html new file mode 100644 index 0000000000..909360cee3 --- /dev/null +++ b/panels/zwave/zwave-log.html @@ -0,0 +1,52 @@ + + + + + + + + diff --git a/panels/zwave/zwave-network.html b/panels/zwave/zwave-network.html new file mode 100644 index 0000000000..3a4914d643 --- /dev/null +++ b/panels/zwave/zwave-network.html @@ -0,0 +1,86 @@ + + + + + + + + diff --git a/panels/zwave/zwave-node-config.html b/panels/zwave/zwave-node-config.html new file mode 100644 index 0000000000..d988e5f088 --- /dev/null +++ b/panels/zwave/zwave-node-config.html @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + diff --git a/panels/zwave/zwave-node-information.html b/panels/zwave/zwave-node-information.html new file mode 100644 index 0000000000..3dcab761d0 --- /dev/null +++ b/panels/zwave/zwave-node-information.html @@ -0,0 +1,81 @@ + + + + + + + diff --git a/panels/zwave/zwave-usercodes.html b/panels/zwave/zwave-usercodes.html new file mode 100644 index 0000000000..3f82358ee9 --- /dev/null +++ b/panels/zwave/zwave-usercodes.html @@ -0,0 +1,171 @@ + + + + + + + + + + + + +