Skip to content
Snippets Groups Projects
Commit fec899c3 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Starting devices

parent 89d03149
No related branches found
No related tags found
No related merge requests found
EVT_VALUE_UPDATED = "value updated"
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)
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
import asyncio import asyncio
# import pdb import pdb
import logging import logging
# from pprint import pprint from pprint import pprint
from zwave_js_server.client import Client as ZwaveClient from zwave_js_server.client import Client as ZwaveClient
...@@ -15,6 +15,9 @@ from xaal.lib import AsyncEngine ...@@ -15,6 +15,9 @@ from xaal.lib import AsyncEngine
from xaal.schemas import devices from xaal.schemas import devices
from .cmdclass import COMMAND_CLASS from .cmdclass import COMMAND_CLASS
from .devices import build_devices
from .const import EVT_VALUE_UPDATED
PACKAGE_NAME = 'xaal.zwavejs' PACKAGE_NAME = 'xaal.zwavejs'
...@@ -23,8 +26,10 @@ logger = logging.getLogger(__name__) ...@@ -23,8 +26,10 @@ logger = logging.getLogger(__name__)
logging.getLogger("zwave_js_server").setLevel(logging.WARNING) logging.getLogger("zwave_js_server").setLevel(logging.WARNING)
# URL = "ws://10.77.3.143:3000" URL = "ws://10.77.3.143:3000"
URL = "ws://localhost:3000" # URL = "ws://localhost:3000"
DEBUG = True
class GW: class GW:
...@@ -53,26 +58,19 @@ class GW: ...@@ -53,26 +58,19 @@ class GW:
nodes = self.client.driver.controller.nodes nodes = self.client.driver.controller.nodes
for node in nodes.values(): for node in nodes.values():
if node.ready: if node.ready:
logger.warning(f"{node.node_id} {node.device_config.manufacturer}/{node.device_config.label} ") build_devices(node)
node.on("value updated", self.on_value_updated) if DEBUG:
for k in node.values: node.on(EVT_VALUE_UPDATED, self.dump_event)
value = node.values.get(k)
if value: def dump_event(self, event):
print(f"{k} {value.property_name} => {value.value}")
# pprint(node.data)
def on_value_updated(self, event):
cmd_class = int(event["args"]["commandClass"]) cmd_class = int(event["args"]["commandClass"])
nodeId = event["nodeId"] nodeId = event["nodeId"]
value = event["value"] value = event["value"]
# pdb.set_trace()
prop = event["args"]["property"] prop = event["args"]["property"]
if prop in ["value", "currentValue", "targetValue"]: if prop in ["value", "currentValue", "targetValue"]:
prop = value.property_key_name prop = value.property_key_name
logger.warning(f"{nodeId}.{value.endpoint} {COMMAND_CLASS(cmd_class)}={prop}=>{event["args"]["newValue"]}") 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): def setup(eng):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment