UNPKG

zwave-js

Version:

Z-Wave driver written entirely in JavaScript/TypeScript

59 lines 2.43 kB
import { NodeNamingAndLocationCCLocationGet, NodeNamingAndLocationCCLocationReport, NodeNamingAndLocationCCLocationSet, NodeNamingAndLocationCCNameGet, NodeNamingAndLocationCCNameReport, NodeNamingAndLocationCCNameSet, } from "@zwave-js/cc/NodeNamingCC"; import { CommandClasses } from "@zwave-js/core"; const defaultCapabilities = {}; const STATE_KEY_PREFIX = "NodeNamingAndLocation_"; const StateKeys = { name: `${STATE_KEY_PREFIX}name`, location: `${STATE_KEY_PREFIX}location`, }; const respondToNodeNameGet = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof NodeNamingAndLocationCCNameGet) { const capabilities = self.getCCCapabilities(CommandClasses["Node Naming and Location"], 0) ?? defaultCapabilities; const cc = new NodeNamingAndLocationCCNameReport({ nodeId: controller.ownNodeId, name: self.state.get(StateKeys.name) ?? capabilities.name ?? "", }); return { action: "sendCC", cc }; } }, }; const respondToNodeNameSet = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof NodeNamingAndLocationCCNameSet) { self.state.set(StateKeys.name, receivedCC.name); return { action: "ok" }; } }, }; const respondToNodeLocationGet = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof NodeNamingAndLocationCCLocationGet) { const capabilities = self.getCCCapabilities(CommandClasses["Node Naming and Location"], 0) ?? defaultCapabilities; const cc = new NodeNamingAndLocationCCLocationReport({ nodeId: controller.ownNodeId, location: self.state.get(StateKeys.location) ?? capabilities.location ?? "", }); return { action: "sendCC", cc }; } }, }; const respondToNodeLocationSet = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof NodeNamingAndLocationCCLocationSet) { self.state.set(StateKeys.location, receivedCC.location); return { action: "ok" }; } }, }; export const NodeNamingAndLocationCCBehaviors = [ respondToNodeNameGet, respondToNodeNameSet, respondToNodeLocationGet, respondToNodeLocationSet, ]; //# sourceMappingURL=NodeNamingAndLocation.js.map