diff --git a/devices/protocols/ZwaveJS/xaal/zwavejs/const.py b/devices/protocols/ZwaveJS/xaal/zwavejs/const.py new file mode 100644 index 0000000000000000000000000000000000000000..f5b1f381abc0c0e2967735dad61ae756f74d2200 --- /dev/null +++ b/devices/protocols/ZwaveJS/xaal/zwavejs/const.py @@ -0,0 +1 @@ +EVT_VALUE_UPDATED = "value updated" diff --git a/devices/protocols/ZwaveJS/xaal/zwavejs/devices.py b/devices/protocols/ZwaveJS/xaal/zwavejs/devices.py new file mode 100644 index 0000000000000000000000000000000000000000..50ada5d0d22c06f6843840fceab07ab9bd657204 --- /dev/null +++ b/devices/protocols/ZwaveJS/xaal/zwavejs/devices.py @@ -0,0 +1,45 @@ +from xaal.schemas import devices + +from zwave_js_server.model.node import Node +from zwave_js_server.event import Event + +from logging import getLogger + +logger = getLogger(__name__) + + +def build_devices(node: Node): + logger.warning(f"{node.node_id} {node.device_config.manufacturer}/{node.device_config.label} ") + # node.on("value updated", self.value_updated) + # pdb.set_trace() + for k in node.values: + value = node.values.get(k) + if value: + print(f"[{k}] {value.endpoint} {value.property_name} => {value.value}") + # pprint(node.data) + + +class ZwaveDevice(object): + def __init__(self, node: Node): + self.node = node + + def setup(self): + pass + + def update(self, event: Event): + pass + + +class PowerRelay(ZwaveDevice): + def __init__(self, node): + super().__init__(node) + self.dev = devices.powerrelay() + + +class PowerMeter(ZwaveDevice): + def __init__(self, node): + super().__init__(node) + self.dev = devices.powermeter() + + def update(self, event: Event): + print(event) diff --git a/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py b/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py index 9b33f22d3f91e9130a187a64c920ed4006c9ea75..cb3d1c9c8e31142ca07459518f182e9c4b177e78 100644 --- a/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py +++ b/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py @@ -2,10 +2,10 @@ import asyncio -# import pdb +import pdb import logging -# from pprint import pprint +from pprint import pprint from zwave_js_server.client import Client as ZwaveClient @@ -15,6 +15,9 @@ from xaal.lib import AsyncEngine from xaal.schemas import devices from .cmdclass import COMMAND_CLASS +from .devices import build_devices +from .const import EVT_VALUE_UPDATED + PACKAGE_NAME = 'xaal.zwavejs' @@ -23,8 +26,10 @@ logger = logging.getLogger(__name__) logging.getLogger("zwave_js_server").setLevel(logging.WARNING) -# URL = "ws://10.77.3.143:3000" -URL = "ws://localhost:3000" +URL = "ws://10.77.3.143:3000" +# URL = "ws://localhost:3000" + +DEBUG = True class GW: @@ -53,26 +58,19 @@ class GW: nodes = self.client.driver.controller.nodes for node in nodes.values(): if node.ready: - logger.warning(f"{node.node_id} {node.device_config.manufacturer}/{node.device_config.label} ") - node.on("value updated", self.on_value_updated) - for k in node.values: - value = node.values.get(k) - if value: - print(f"{k} {value.property_name} => {value.value}") - # pprint(node.data) - - def on_value_updated(self, event): + build_devices(node) + if DEBUG: + node.on(EVT_VALUE_UPDATED, self.dump_event) + + def dump_event(self, event): cmd_class = int(event["args"]["commandClass"]) nodeId = event["nodeId"] value = event["value"] + # pdb.set_trace() prop = event["args"]["property"] if prop in ["value", "currentValue", "targetValue"]: prop = value.property_key_name logger.warning(f"{nodeId}.{value.endpoint} {COMMAND_CLASS(cmd_class)}={prop}=>{event["args"]["newValue"]}") - # if cmd_class == 49 and nodeId == 4: - # pdb.set_trace() - - # print(event) def setup(eng):