Skip to content
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

Add zwave expert UI / Installer settings #21897

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export interface ZWaveJSNodeStatus {
has_firmware_update_cc: boolean;
}

export type ZWaveJSNodeCapabilities = {
[endpoint: number]: ZWaveJSEndpointCapability[];
};

export interface ZWaveJSEndpointCapability {
id: number;
name: string;
version: number;
is_secure: boolean;
}

export interface ZwaveJSNodeMetadata {
node_id: number;
exclusion: string;
Expand Down Expand Up @@ -403,6 +414,25 @@ export interface RequestedGrant {
clientSideAuth: boolean;
}

export const invokeZwaveCCApi = (
wendevlin marked this conversation as resolved.
Show resolved Hide resolved
hass: HomeAssistant,
device_id: string,
command_class: number,
endpoint: number | undefined,
method_name: string,
parameters: any[],
wait_for_result?: boolean
): Promise<unknown> =>
hass.callWS({
type: "zwave_js/invoke_cc_api",
device_id,
command_class,
endpoint,
method_name,
parameters,
wait_for_result,
});
wendevlin marked this conversation as resolved.
Show resolved Hide resolved

export const fetchZwaveNetworkStatus = (
hass: HomeAssistant,
device_or_entry_id: {
Expand Down Expand Up @@ -578,6 +608,15 @@ export const fetchZwaveNodeStatus = (
device_id,
});

export const fetchZwaveNodeCapabilities = (
hass: HomeAssistant,
device_id: string
): Promise<ZWaveJSNodeCapabilities> =>
hass.callWS({
type: "zwave_js/node_capabilities",
device_id,
});

export const subscribeZwaveNodeStatus = (
hass: HomeAssistant,
device_id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
mdiHospitalBox,
mdiInformation,
mdiUpload,
mdiWrench,
} from "@mdi/js";
import { getConfigEntries } from "../../../../../../data/config_entries";
import { DeviceRegistryEntry } from "../../../../../../data/device_registry";
Expand Down Expand Up @@ -98,6 +99,13 @@ export const getZwaveDeviceActions = async (
showZWaveJSNodeStatisticsDialog(el, {
device,
}),
},
{
label: hass.localize(
"ui.panel.config.zwave_js.device_info.installer_settings"
),
icon: mdiWrench,
href: `/config/zwave_js/node_installer/${device.id}?config_entry=${entryId}`,
wendevlin marked this conversation as resolved.
Show resolved Hide resolved
}
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../../../../components/ha-button";
import { DeviceRegistryEntry } from "../../../../../../data/device_registry";
import { HomeAssistant } from "../../../../../../types";
import { invokeZwaveCCApi } from "../../../../../../data/zwave_js";

@customElement("zwave_js-capability-control-multilevel_switch")
class ZWaveJSCapabilityMultiLevelSwitch extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property({ attribute: false }) public device!: DeviceRegistryEntry;

@property({ type: Number }) public endpoint!: number;

@property({ type: Number }) public command_class!: number;

@property({ type: Number }) public version!: number;

protected render() {
return html`<h3>Transition</h3>
<ha-select label="Direction" id="direction">
<mwc-list-item .value=${"up"} selected>Up</mwc-list-item>
<mwc-list-item .value=${"down"}>Down</mwc-list-item>
</ha-select>
<ha-formfield label="Ignore start level">
<ha-switch id="ignore_start_level"></ha-switch>
</ha-formfield>
<ha-textfield
type="number"
id="start_level"
value="0"
label="Start level"
></ha-textfield>
<ha-button @click=${this._startTransition}>Start transition</ha-button>
<ha-button @click=${this._stopTransition}>Stop transition</ha-button>`;
}
wendevlin marked this conversation as resolved.
Show resolved Hide resolved

private async _startTransition() {
const direction = (this.shadowRoot!.getElementById("direction") as any)
.value;

const ignoreStartLevel = (
this.shadowRoot!.getElementById("ignore_start_level") as any
).checked;

const startLevel = Number(
(this.shadowRoot!.getElementById("start_level") as any).value
);

await invokeZwaveCCApi(
this.hass,
this.device.id,
this.command_class,
this.endpoint,
"startLevelChange",
[{ direction, ignoreStartLevel, startLevel }],
true
);
}
wendevlin marked this conversation as resolved.
Show resolved Hide resolved

private async _stopTransition() {
const direction = (this.shadowRoot!.getElementById("direction") as any)
.value;

const ignoreStartLevel = (
this.shadowRoot!.getElementById("ignore_start_level") as any
).checked;

const startLevel = Number(
(this.shadowRoot!.getElementById("start_level") as any).value
);

await invokeZwaveCCApi(
this.hass,
this.device.id,
this.command_class,
this.endpoint,
"stopLevelChange",
[{ direction, ignoreStartLevel, startLevel }],
true
);
wendevlin marked this conversation as resolved.
Show resolved Hide resolved
}

static styles = css`
ha-select,
ha-formfield,
ha-textfield {
display: block;
margin-bottom: 8px;
}
`;
}

declare global {
interface HTMLElementTagNameMap {
"zwave_js-capability-control-multilevel_switch": ZWaveJSCapabilityMultiLevelSwitch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class ZWaveJSConfigRouter extends HassRouterPage {
tag: "zwave_js-node-config",
load: () => import("./zwave_js-node-config"),
},
node_installer: {
tag: "zwave_js-node-installer",
load: () => import("./zwave_js-node-installer"),
},
logs: {
tag: "zwave_js-logs",
load: () => import("./zwave_js-logs"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import "@material/mwc-button/mwc-button";
import "@material/mwc-list/mwc-list-item";
import {
CSSResultGroup,
LitElement,
PropertyValues,
TemplateResult,
css,
html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { dynamicElement } from "../../../../../common/dom/dynamic-element-directive";
import "../../../../../components/ha-alert";
import "../../../../../components/ha-card";
import "../../../../../components/ha-icon-next";
import "../../../../../components/ha-select";
import "../../../../../components/ha-settings-row";
import "../../../../../components/ha-svg-icon";
import "../../../../../components/ha-switch";
import "../../../../../components/ha-textfield";
import { computeDeviceName } from "../../../../../data/device_registry";
import {
ZWaveJSNodeCapabilities,
ZwaveJSNodeMetadata,
fetchZwaveNodeCapabilities,
fetchZwaveNodeMetadata,
} from "../../../../../data/zwave_js";
import "../../../../../layouts/hass-error-screen";
import "../../../../../layouts/hass-loading-screen";
import "../../../../../layouts/hass-tabs-subpage";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant, Route } from "../../../../../types";
import "../../../ha-config-section";
import { configTabs } from "./zwave_js-config-router";
import "./capability-controls/zwave_js-capability-control-multilevel-switch";

const CAPABILITY_CONTROLS = {
38: "multilevel_switch",
};

@customElement("zwave_js-node-installer")
class ZWaveJSNodeInstaller extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property({ attribute: false }) public route!: Route;

@property({ type: Boolean }) public narrow = false;

@property({ type: Boolean }) public isWide = false;

@property() public configEntryId?: string;

@property() public deviceId!: string;

@state() private _nodeMetadata?: ZwaveJSNodeMetadata;

@state() private _capabilities?: ZWaveJSNodeCapabilities;

@state() private _error?: string;

public connectedCallback(): void {
super.connectedCallback();
this.deviceId = this.route.path.substr(1);
}

protected updated(changedProps: PropertyValues): void {
wendevlin marked this conversation as resolved.
Show resolved Hide resolved
if (!this._capabilities || changedProps.has("deviceId")) {
this._fetchData();
}
}

protected render(): TemplateResult {
if (this._error) {
return html`<hass-error-screen
.hass=${this.hass}
.error=${this.hass.localize(
`ui.panel.config.zwave_js.node_config.error_${this._error}`
)}
></hass-error-screen>`;
}

if (!this._capabilities || !this._nodeMetadata) {
return html`<hass-loading-screen></hass-loading-screen>`;
}

const device = this.hass.devices[this.deviceId];

return html`
<hass-tabs-subpage
.hass=${this.hass}
.narrow=${this.narrow}
.route=${this.route}
.tabs=${configTabs}
>
<ha-config-section
.narrow=${this.narrow}
.isWide=${this.isWide}
vertical
>
<div slot="header">
${this.hass.localize(
"ui.panel.config.zwave_js.node_installer.header"
)}
</div>

<div slot="introduction">
${device
? html`
<div class="device-info">
<h2>${computeDeviceName(device, this.hass)}</h2>
<p>${device.manufacturer} ${device.model}</p>
</div>
`
: ``}
${this.hass.localize(
"ui.panel.config.zwave_js.node_installer.introduction"
)}
</div>
${Object.entries(this._capabilities).map(([endpoint, capabilities]) =>
capabilities.map(
(capability) =>
html`Endpoint: ${endpoint}<br />Command Class:
${capability.name}<br />
${capability.id in CAPABILITY_CONTROLS
? dynamicElement(
`zwave_js-capability-control-${CAPABILITY_CONTROLS[capability.id]}`,
{
hass: this.hass,
device: device,
endpoint: endpoint,
command_class: capability.id,
version: capability.version,
is_secure: capability.is_secure,
}
)
: nothing}
<hr />
<br />`
)
)}
</ha-config-section>
</hass-tabs-subpage>
`;
}
wendevlin marked this conversation as resolved.
Show resolved Hide resolved

private async _fetchData() {
if (!this.configEntryId) {
return;
}

const device = this.hass.devices[this.deviceId];
if (!device) {
this._error = "device_not_found";
return;
}

[this._nodeMetadata, this._capabilities] = await Promise.all([
fetchZwaveNodeMetadata(this.hass, device.id),
fetchZwaveNodeCapabilities(this.hass, device.id),
]);
}
wendevlin marked this conversation as resolved.
Show resolved Hide resolved

static get styles(): CSSResultGroup {
return [haStyle, css``];
}
}

declare global {
interface HTMLElementTagNameMap {
"zwave_js-node-installer": ZWaveJSNodeInstaller;
}
}
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4781,6 +4781,7 @@
"node_id": "ID",
"node_ready": "Ready",
"device_config": "Configure",
"installer_settings": "Installer settings",
"reinterview_device": "Re-interview",
"rebuild_routes": "Rebuild routes",
"remove_failed": "Remove failed",
Expand Down
Loading