mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Subscribe to zwave_js node status updates in device panel (#12916)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
6c5cf2a0ec
commit
529e27992e
@ -275,6 +275,12 @@ export interface ZWaveJSRouteStatistics {
|
|||||||
route_failed_between: [string, string] | null;
|
route_failed_between: [string, string] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ZWaveJSNodeStatusUpdatedMessage {
|
||||||
|
event: "ready" | "wake up" | "sleep" | "dead" | "alive";
|
||||||
|
ready: boolean;
|
||||||
|
status: NodeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ZWaveJSRemovedNode {
|
export interface ZWaveJSRemovedNode {
|
||||||
node_id: number;
|
node_id: number;
|
||||||
manufacturer: string;
|
manufacturer: string;
|
||||||
@ -473,6 +479,19 @@ export const fetchZwaveNodeStatus = (
|
|||||||
device_id,
|
device_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const subscribeZwaveNodeStatus = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_id: string,
|
||||||
|
callbackFunction: (message: ZWaveJSNodeStatusUpdatedMessage) => void
|
||||||
|
): Promise<UnsubscribeFunc> =>
|
||||||
|
hass.connection.subscribeMessage(
|
||||||
|
(message: any) => callbackFunction(message),
|
||||||
|
{
|
||||||
|
type: "zwave_js/subscribe_node_status",
|
||||||
|
device_id,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const fetchZwaveNodeMetadata = (
|
export const fetchZwaveNodeMetadata = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_id: string
|
device_id: string
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import "../../../../../../components/ha-expansion-panel";
|
import "../../../../../../components/ha-expansion-panel";
|
||||||
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
getConfigEntries,
|
getConfigEntries,
|
||||||
@ -17,13 +18,15 @@ import {
|
|||||||
fetchZwaveNodeStatus,
|
fetchZwaveNodeStatus,
|
||||||
nodeStatus,
|
nodeStatus,
|
||||||
SecurityClass,
|
SecurityClass,
|
||||||
|
subscribeZwaveNodeStatus,
|
||||||
ZWaveJSNodeStatus,
|
ZWaveJSNodeStatus,
|
||||||
} from "../../../../../../data/zwave_js";
|
} from "../../../../../../data/zwave_js";
|
||||||
import { haStyle } from "../../../../../../resources/styles";
|
import { haStyle } from "../../../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../../../types";
|
import { HomeAssistant } from "../../../../../../types";
|
||||||
|
import { SubscribeMixin } from "../../../../../../mixins/subscribe-mixin";
|
||||||
|
|
||||||
@customElement("ha-device-info-zwave_js")
|
@customElement("ha-device-info-zwave_js")
|
||||||
export class HaDeviceInfoZWaveJS extends LitElement {
|
export class HaDeviceInfoZWaveJS extends SubscribeMixin(LitElement) {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public device!: DeviceRegistryEntry;
|
@property({ attribute: false }) public device!: DeviceRegistryEntry;
|
||||||
@ -41,6 +44,21 @@ export class HaDeviceInfoZWaveJS extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hassSubscribe(): Array<UnsubscribeFunc | Promise<UnsubscribeFunc>> {
|
||||||
|
return [
|
||||||
|
subscribeZwaveNodeStatus(this.hass, this.device!.id, (message) => {
|
||||||
|
if (!this._node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._node = {
|
||||||
|
...this._node,
|
||||||
|
status: message.status,
|
||||||
|
ready: message.ready,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
protected async _fetchNodeDetails() {
|
protected async _fetchNodeDetails() {
|
||||||
if (!this.device) {
|
if (!this.device) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user