Add zwave per-node entity. (#6690)
* Add zwave per-node entity. * Disable lint import error * Add tests for base class * More tests * More tests * Sort .coveragerc * more tests * Move location, battery and wakeup to node entity * More tests * Cleanup * Make zwave node entity visible by default * Remove battery sensor * Fix tests
This commit is contained in:
1 parent
20c5f9de4b
commit
8a86ec5b74
11 files changed
+408
-133
No files matched your search
+34
-1
@@ -4,6 +4,8 @@ from unittest.mock import MagicMock
|
||||
from pydispatch import dispatcher
|
||||
|
||||
SIGNAL_VALUE_CHANGED = 'mock_value_changed'
|
||||
SIGNAL_NODE = 'mock_node'
|
||||
SIGNAL_NOTIFICATION = 'mock_notification'
|
||||
|
||||
|
||||
def value_changed(value):
|
||||
@@ -16,6 +18,24 @@ def value_changed(value):
|
||||
)
|
||||
|
||||
|
||||
def node_changed(node):
|
||||
"""Fire a node changed."""
|
||||
dispatcher.send(
|
||||
SIGNAL_NODE,
|
||||
node=node,
|
||||
network=node._network
|
||||
)
|
||||
|
||||
|
||||
def notification(node_id, network=None):
|
||||
"""Fire a notification."""
|
||||
dispatcher.send(
|
||||
SIGNAL_NOTIFICATION,
|
||||
args={'nodeId': node_id},
|
||||
network=network
|
||||
)
|
||||
|
||||
|
||||
class MockNode(MagicMock):
|
||||
"""Mock Z-Wave node."""
|
||||
|
||||
@@ -25,7 +45,9 @@ class MockNode(MagicMock):
|
||||
manufacturer_id='ABCD',
|
||||
product_id='123',
|
||||
product_type='678',
|
||||
command_classes=None):
|
||||
command_classes=None,
|
||||
can_wake_up_value=True,
|
||||
**kwargs):
|
||||
"""Initialize a Z-Wave mock node."""
|
||||
super().__init__()
|
||||
self.node_id = node_id
|
||||
@@ -33,12 +55,23 @@ class MockNode(MagicMock):
|
||||
self.manufacturer_id = manufacturer_id
|
||||
self.product_id = product_id
|
||||
self.product_type = product_type
|
||||
self.can_wake_up_value = can_wake_up_value
|
||||
self._command_classes = command_classes or []
|
||||
for attr_name in kwargs:
|
||||
setattr(self, attr_name, kwargs[attr_name])
|
||||
|
||||
def has_command_class(self, command_class):
|
||||
"""Test if mock has a command class."""
|
||||
return command_class in self._command_classes
|
||||
|
||||
def get_battery_level(self):
|
||||
"""Return mock battery level."""
|
||||
return 42
|
||||
|
||||
def can_wake_up(self):
|
||||
"""Return whether the node can wake up."""
|
||||
return self.can_wake_up_value
|
||||
|
||||
def _get_child_mock(self, **kw):
|
||||
"""Create child mocks with right MagicMock class."""
|
||||
return MagicMock(**kw)
|
||||
|
||||
Reference in new issue
Block a user