-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use device_id instead of config entry id and node id for zwave_js #12658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4596fe4
f3630b7
bbe9dc6
1d82222
bee56e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,15 +11,14 @@ import { customElement, property, state } from "lit/decorators"; | |||||||||
| import { DeviceRegistryEntry } from "../../../../../../data/device_registry"; | ||||||||||
| import { | ||||||||||
| fetchZwaveNodeStatus, | ||||||||||
| getZwaveJsIdentifiersFromDevice, | ||||||||||
| ZWaveJSNodeIdentifiers, | ||||||||||
| ZWaveJSNodeStatus, | ||||||||||
| } from "../../../../../../data/zwave_js"; | ||||||||||
| import { haStyle } from "../../../../../../resources/styles"; | ||||||||||
| import { HomeAssistant } from "../../../../../../types"; | ||||||||||
| import { showZWaveJSReinterviewNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node"; | ||||||||||
| import { showZWaveJSHealNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node"; | ||||||||||
| import { showZWaveJSRemoveFailedNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-failed-node"; | ||||||||||
| import { getConfigEntries } from "../../../../../../data/config_entries"; | ||||||||||
|
|
||||||||||
| @customElement("ha-device-actions-zwave_js") | ||||||||||
| export class HaDeviceActionsZWaveJS extends LitElement { | ||||||||||
|
|
@@ -29,34 +28,37 @@ export class HaDeviceActionsZWaveJS extends LitElement { | |||||||||
|
|
||||||||||
| @state() private _entryId?: string; | ||||||||||
|
|
||||||||||
| @state() private _nodeId?: number; | ||||||||||
|
|
||||||||||
| @state() private _node?: ZWaveJSNodeStatus; | ||||||||||
|
|
||||||||||
| protected updated(changedProperties: PropertyValues) { | ||||||||||
| public willUpdate(changedProperties: PropertyValues) { | ||||||||||
| super.willUpdate(changedProperties); | ||||||||||
| if (changedProperties.has("device")) { | ||||||||||
| const identifiers: ZWaveJSNodeIdentifiers | undefined = | ||||||||||
| getZwaveJsIdentifiersFromDevice(this.device); | ||||||||||
| if (!identifiers) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| this._nodeId = identifiers.node_id; | ||||||||||
| this._entryId = this.device.config_entries[0]; | ||||||||||
|
|
||||||||||
| this._fetchNodeDetails(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| protected async _fetchNodeDetails() { | ||||||||||
| if (!this._nodeId || !this._entryId) { | ||||||||||
| if (!this.device) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| this._node = await fetchZwaveNodeStatus( | ||||||||||
| this.hass, | ||||||||||
| this._entryId, | ||||||||||
| this._nodeId | ||||||||||
| this._node = undefined; | ||||||||||
|
|
||||||||||
| const configEntries = await getConfigEntries(this.hass, { | ||||||||||
| domain: "zwave_js", | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const configEntry = configEntries.find((entry) => | ||||||||||
| this.device.config_entries.includes(entry.entry_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| if (!configEntry) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| this._entryId = configEntry.entry_id; | ||||||||||
|
|
||||||||||
| this._node = await fetchZwaveNodeStatus(this.hass, this.device.id); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| protected render(): TemplateResult { | ||||||||||
|
|
@@ -96,33 +98,30 @@ export class HaDeviceActionsZWaveJS extends LitElement { | |||||||||
| } | ||||||||||
|
|
||||||||||
| private async _reinterviewClicked() { | ||||||||||
| if (!this._nodeId || !this._entryId) { | ||||||||||
| if (!this.device) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| showZWaveJSReinterviewNodeDialog(this, { | ||||||||||
| entry_id: this._entryId, | ||||||||||
| node_id: this._nodeId, | ||||||||||
| device_id: this.device.id, | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private async _healNodeClicked() { | ||||||||||
| if (!this._nodeId || !this._entryId) { | ||||||||||
| if (!this.device) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| showZWaveJSHealNodeDialog(this, { | ||||||||||
| entry_id: this._entryId, | ||||||||||
| node_id: this._nodeId, | ||||||||||
| entry_id: this._entryId!, | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the entry ID is still needed by frontend/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-node.ts Lines 205 to 208 in bbe9dc6
dialog-zwave_js-heal-node but we currently already have to figure out entry ID in ha-device-actions-zwave_js so that we can add it to the URL, so why recalculate it? Is it necessary to add it to the URL though? I couldn't figure out why we do that, and if it's not necessary, we can just pass the device ID in and only calculate entry ID in the heal node dialog
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another alternative would be to allow
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like the nicest approach
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Want to merge this and do that in a new PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea |
||||||||||
| device: this.device, | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private async _removeFailedNode() { | ||||||||||
| if (!this._nodeId || !this._entryId) { | ||||||||||
| if (!this.device) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| showZWaveJSRemoveFailedNodeDialog(this, { | ||||||||||
| entry_id: this._entryId, | ||||||||||
| node_id: this._nodeId, | ||||||||||
| device_id: this.device.id, | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.