Add ability to set Zwave protection commandclass#1433
Add ability to set Zwave protection commandclass#1433balloob merged 5 commits intohome-assistant:masterfrom
Conversation
|
|
||
| <!--Config card--> | ||
| <zwave-node-config hass="[[hass]]" nodes="[[nodes]]" selected-node="[[selectedNode]]" config="[[config]]"></zwave-node-config> | ||
| <zwave-node-config hass="[[hass]]" nodes="[[nodes]]" selected-node="[[selectedNode]]" config="[[config]]" protection="[[protection]]"></zwave-node-config> |
There was a problem hiding this comment.
Add some new lines please.these long lines are really unreadable
| value: false, | ||
| }, | ||
|
|
||
| protectionNode: { |
There was a problem hiding this comment.
All these protection options and html should be extracted in their own web component
|
|
||
| apiCalled(ev) { | ||
| if (ev.detail.success) { | ||
| var foo = this; |
There was a problem hiding this comment.
Foo...
Just use an arrow function and this will be set to defining context
|
|
||
| refreshProtection(selectedNode) { | ||
| var protectionValues = []; | ||
| this.hass.callApi('GET', 'zwave/protection/' + this.nodes[selectedNode].attributes.node_id).then(function (protections) { |
There was a problem hiding this comment.
We've been adopting async and await syntax.
async refreshProtection() {
const protections = await this.hass.callApi(...);
}|
|
||
| <!--Config card--> | ||
| <zwave-node-config hass="[[hass]]" nodes="[[nodes]]" selected-node="[[selectedNode]]" config="[[config]]"></zwave-node-config> | ||
| <zwave-node-config hass="[[hass]]" nodes="[[nodes]]" selected-node="[[selectedNode]]" |
There was a problem hiding this comment.
Style like this:
<zwave-node-config
hass="[[hass]]"
nodes="[[nodes]]"
></zwave-node-config>|
|
||
| </style> | ||
| <div class="content"> | ||
| <template is="dom-if" if="[[protectionNode]]"> |
There was a problem hiding this comment.
This is weird, it would make more sense that this complete web component doesn't get rendered if no protection node. So add the if statement to the component that renders this component.
| this.notifyPath('hasNodeUserCodes'); | ||
| }); | ||
| this.protectionNode = false; | ||
| this.notifyPath('protectionNode'); |
There was a problem hiding this comment.
This should not be needed since protectionNode is a property.
| }, | ||
| }, | ||
|
|
||
| protectionNode: { |
There was a problem hiding this comment.
Please prefix anything that is internal (not set by a component rendering this component) with an _. So make it _protectionNode
| value: false, | ||
| }, | ||
|
|
||
| protectionValueID: { |
There was a problem hiding this comment.
This and all properties below it are internal and should be prefixed with an _
| value: 0, | ||
| }, | ||
|
|
||
| protection: { |
There was a problem hiding this comment.
You're setting protection so it's an internval variable, name should be prefixed with _
| } | ||
|
|
||
| async refreshProtection(selectedNode) { | ||
| var protectionValues = []; |
There was a problem hiding this comment.
Don't use var. Either use const or let.
| async refreshProtection(selectedNode) { | ||
| var protectionValues = []; | ||
| const resp = await this.hass.callApi('GET', 'zwave/protection/' + this.nodes[selectedNode].attributes.node_id); | ||
| var protections = resp; |
There was a problem hiding this comment.
? why not assign directly to this?
34f545c to
a4e20da
Compare
|
ok to merge when backend PR has been merged |
|
|
||
| _protection: { | ||
| type: Array, | ||
| value: function () { |
| this.hass.callApi('GET', 'zwave/protection/' + this.nodes[selectedNode].attributes.node_id).then((protections) => { | ||
| this.protection = this._objToArray(protections); | ||
| if (this.protection) { | ||
| if (this.protection[0] === undefined) { |
|
|
||
| static get properties() { | ||
| return { | ||
| hass: { |
| value: { }, | ||
| }, | ||
|
|
||
| _nodePath: { |
| observer: 'computeProtectionData', | ||
| }, | ||
|
|
||
| _protectionOptions: { |
| } | ||
| } | ||
|
|
||
| customElements.define('zwave-node-protection', ZwaveProtectionConfig); |
| _selectedProtectionParameter: { | ||
| type: Number, | ||
| value: -1, | ||
| observer: 'computeProtectionData', |
| selectedNode: { | ||
| type: Number, | ||
| value: -1, | ||
| observer: 'nodesChanged' |
There was a problem hiding this comment.
use "complex" observer
static get observers() {
return [
'_nodesChanged(nodes, selectedNode)'
];
}| <div class="content"> | ||
| <paper-card heading="Node protection"> | ||
| <div class="device-picker"> | ||
| <paper-dropdown-menu label="Protection" dynamic-align="" class="flex" placeholder="{{_loadedProtectionValue}}"> |
| .device-picker { | ||
| @apply --layout-horizontal; | ||
| @apply --layout-center-center; | ||
| padding-left: 24px; |
| hass="[[hass]]" | ||
| nodes="[[nodes]]" | ||
| selected-node="[[selectedNode]]" | ||
| _protection="[[_protection]]" |
There was a problem hiding this comment.
should be protection="[[_protection]]" then
There was a problem hiding this comment.
So, ok. There seems to be different views on this. You say it's not going to have and underscore, and balloob says it to have underscore.
My opinion is without underscore, because we pass it up to zwave-node-protection card for further processing, thus not only an internal property.
There was a problem hiding this comment.
Correct - If anproperty is public/ passed in, we don't use the underscore.
| return { | ||
| hass: Object, | ||
|
|
||
| nodes: { |
| if (!this.nodes) return; | ||
| if (this._protection) { | ||
| if (this._protection.length === 0) { return; } | ||
| this.setProperties({ protectionNode: true }); |
There was a problem hiding this comment.
you can set multiple at once
this.setProperties({
protectionNode: true,
_protectionOptions: this._protection[0].value,
_loadedProtectionValue: this._protection[1].value,
_protectionValueID: this._protection[2].value
});
Allows the user via zwave control panel to set values of protection commandclass.
This is needed in some cases to allow programming of some devices.
See home-assistant/core#11137 for reference.
Accompanying PR for backend: home-assistant/core#15390