Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { HomeAssistant } from "../types";
import { DeviceRegistryEntry } from "./device_registry";

export enum InclusionState {
/** The controller isn't doing anything regarding inclusion. */
Idle,
/** The controller is waiting for a node to be included. */
Including,
/** The controller is waiting for a node to be excluded. */
Excluding,
/** The controller is busy including or excluding a node. */
Busy,
/** The controller listening for SmartStart nodes to announce themselves. */
SmartStart,
}

export const enum InclusionStrategy {
/**
* Always uses Security S2 if supported, otherwise uses Security S0 for certain devices which don't work without encryption and uses no encryption otherwise.
Expand Down Expand Up @@ -106,16 +119,33 @@ export interface ZWaveJSNetwork {
}

export interface ZWaveJSClient {
state: string;
state: "connected" | "disconnected";
ws_server_url: string;
server_version: string;
driver_version: string;
}

export interface ZWaveJSController {
home_id: string;
nodes: number[];
home_id: number;
library_version: string;
type: number;
own_node_id: number;
is_secondary: boolean;
is_using_home_id_from_other_network: boolean;
is_sis_present: boolean;
was_real_primary: boolean;
is_static_update_controller: boolean;
is_slave: boolean;
serial_api_version: string;
manufacturer_id: number;
product_id: number;
product_type: number;
supported_function_types: number[];
suc_node_id: number;
supports_timers: boolean;
is_heal_network_active: boolean;
inclusion_state: InclusionState;
nodes: number[];
}

export interface ZWaveJSNodeStatus {
Expand Down Expand Up @@ -308,6 +338,12 @@ export const stopZwaveInclusion = (hass: HomeAssistant, entry_id: string) =>
entry_id,
});

export const stopZwaveExclusion = (hass: HomeAssistant, entry_id: string) =>
hass.callWS({
type: "zwave_js/stop_exclusion",
entry_id,
});

export const zwaveGrantSecurityClasses = (
hass: HomeAssistant,
entry_id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
fetchZwaveNetworkStatus,
fetchZwaveNodeStatus,
fetchZwaveProvisioningEntries,
InclusionState,
setZwaveDataCollectionPreference,
stopZwaveExclusion,
stopZwaveInclusion,
ZWaveJSClient,
ZWaveJSNetwork,
ZWaveJSNodeStatus,
ZwaveJSProvisioningEntry,
Expand Down Expand Up @@ -60,7 +64,7 @@ class ZWaveJSConfigDashboard extends LitElement {

@state() private _provisioningEntries?: ZwaveJSProvisioningEntry[];

@state() private _status = "unknown";
@state() private _status?: ZWaveJSClient["state"];

@state() private _icon = mdiCircle;

Expand Down Expand Up @@ -107,27 +111,52 @@ class ZWaveJSConfigDashboard extends LitElement {
"ui.panel.config.zwave_js.dashboard.introduction"
)}
</div>
${this._network &&
this._status === "connected" &&
(this._network?.controller.inclusion_state ===
InclusionState.Including ||
this._network?.controller.inclusion_state ===
InclusionState.Excluding)
? html`
<ha-alert alert-type="info">
${this.hass.localize(
`ui.panel.config.zwave_js.common.in_progress_inclusion_exclusion`
)}
<mwc-button
slot="action"
.label=${this.hass.localize(
`ui.panel.config.zwave_js.common.cancel_inclusion_exclusion`
)}
@click=${this._network?.controller.inclusion_state ===
InclusionState.Including
? this._cancelInclusion
: this._cancelExclusion}
>
</mwc-button>
</ha-alert>
`
: ""}
${this._network
? html`
<ha-card class="content network-status">
<div class="card-content">
<div class="heading">
<div class="icon">
${this._status === "connecting"
${this._status === "disconnected"
? html`<ha-circular-progress
active
></ha-circular-progress>`
: html`
<ha-svg-icon
.path=${this._icon}
class="network-status-icon ${classMap({
[this._status]: true,
[this._status!]: true,
})}"
slot="item-icon"
></ha-svg-icon>
`}
</div>
${this._status !== "connecting"
${this._status !== "disconnected"
? html`
<div class="details">
${this.hass.localize(
Expand Down Expand Up @@ -207,24 +236,23 @@ class ZWaveJSConfigDashboard extends LitElement {
<div class="card-actions">
<mwc-button
@click=${this._removeNodeClicked}
.disabled=${this._status === "connecting"}
.disabled=${this._status !== "connected" ||
this._network?.controller.inclusion_state !==
InclusionState.Idle}
>
${this.hass.localize(
"ui.panel.config.zwave_js.common.remove_node"
)}
</mwc-button>
<mwc-button
@click=${this._healNetworkClicked}
.disabled=${this._status === "connecting"}
.disabled=${this._status === "disconnected"}
>
${this.hass.localize(
"ui.panel.config.zwave_js.common.heal_network"
)}
</mwc-button>
<mwc-button
@click=${this._openOptionFlow}
.disabled=${this._status === "connecting"}
>
<mwc-button @click=${this._openOptionFlow}>
${this.hass.localize(
"ui.panel.config.zwave_js.common.reconfigure_server"
)}
Expand Down Expand Up @@ -272,10 +300,11 @@ class ZWaveJSConfigDashboard extends LitElement {
.label=${this.hass.localize(
"ui.panel.config.zwave_js.common.add_node"
)}
.disabled=${this._status === "connecting"}
extended
?rtl=${computeRTL(this.hass)}
@click=${this._addNodeClicked}
.disabled=${this._status !== "connected" ||
this._network?.controller.inclusion_state !== InclusionState.Idle}
>
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</ha-fab>
Expand Down Expand Up @@ -412,6 +441,16 @@ class ZWaveJSConfigDashboard extends LitElement {
});
}

private async _cancelInclusion() {
stopZwaveInclusion(this.hass!, this.configEntryId!);
await this._fetchData();
}

private async _cancelExclusion() {
stopZwaveExclusion(this.hass!, this.configEntryId!);
await this._fetchData();
}

private _dataCollectionToggled(ev) {
setZwaveDataCollectionPreference(
this.hass!,
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,9 @@
"add_node": "Add device",
"remove_node": "Remove device",
"reconfigure_server": "Re-configure Server",
"heal_network": "Heal Network"
"heal_network": "Heal Network",
"in_progress_inclusion_exclusion": "Z-Wave JS is searching for devices",
"cancel_inclusion_exclusion": "Stop Searching"
},
"dashboard": {
"header": "Manage your Z-Wave Network",
Expand Down