Skip to content

Add ability to set Zwave protection commandclass#1433

Merged
balloob merged 5 commits intohome-assistant:masterfrom
turbokongen:zwave-protection
Jul 23, 2018
Merged

Add ability to set Zwave protection commandclass#1433
balloob merged 5 commits intohome-assistant:masterfrom
turbokongen:zwave-protection

Conversation

@turbokongen
Copy link
Copy Markdown
Contributor

@turbokongen turbokongen commented Jul 9, 2018

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


<!--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>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some new lines please.these long lines are really unreadable

value: false,
},

protectionNode: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these protection options and html should be extracted in their own web component


apiCalled(ev) {
if (ev.detail.success) {
var foo = this;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]]"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style like this:

<zwave-node-config
  hass="[[hass]]"
  nodes="[[nodes]]"
></zwave-node-config>


</style>
<div class="content">
<template is="dom-if" if="[[protectionNode]]">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Copy Markdown
Member

@balloob balloob Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed since protectionNode is a property.

},
},

protectionNode: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix anything that is internal (not set by a component rendering this component) with an _. So make it _protectionNode

value: false,
},

protectionValueID: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and all properties below it are internal and should be prefixed with an _

value: 0,
},

protection: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're setting protection so it's an internval variable, name should be prefixed with _

}

async refreshProtection(selectedNode) {
var protectionValues = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? why not assign directly to this?

@balloob
Copy link
Copy Markdown
Member

balloob commented Jul 13, 2018

ok to merge when backend PR has been merged


_protection: {
type: Array,
value: function () {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

() => []

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protection.length === 0


static get properties() {
return {
hass: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hass: Object

value: { },
},

_nodePath: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short syntax

observer: 'computeProtectionData',
},

_protectionOptions: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short syntax

}
}

customElements.define('zwave-node-protection', ZwaveProtectionConfig);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use same name

_selectedProtectionParameter: {
type: Number,
value: -1,
observer: 'computeProtectionData',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'_computeProtectionData'

selectedNode: {
type: Number,
value: -1,
observer: 'nodesChanged'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}}">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic-align class="flex"

.device-picker {
@apply --layout-horizontal;
@apply --layout-center-center;
padding-left: 24px;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding: 0 24px 24px 24px;

hass="[[hass]]"
nodes="[[nodes]]"
selected-node="[[selectedNode]]"
_protection="[[_protection]]"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be protection="[[_protection]]" then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - If anproperty is public/ passed in, we don't use the underscore.

return {
hass: Object,

nodes: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodes: Array,

if (!this.nodes) return;
if (this._protection) {
if (this._protection.length === 0) { return; }
this.setProperties({ protectionNode: true });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
 });

@balloob balloob merged commit 0aee48c into home-assistant:master Jul 23, 2018
@ghost ghost removed the in progress label Jul 23, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants