Leverage zigpy for IEEE address conversions (#27972)

* Refactor EUI64 conversions.

* Update ZHA dependencies.

* Update tests.
This commit is contained in:
Alexei Chetroi authored and David F. Mulcahey committed 2019-10-21 13:14:17 -04:00
1 parent 643257d911
commit a0c50f4794
13 files changed
+135 -81

No files matched your search

+13 -4
View File
@@ -3,6 +3,8 @@ import time
from unittest.mock import Mock, patch
from asynctest import CoroutineMock
from zigpy.types.named import EUI64
import zigpy.zcl.foundation as zcl_f
from homeassistant.components.zha.core.const import (
DATA_ZHA,
@@ -10,7 +12,6 @@ from homeassistant.components.zha.core.const import (
DATA_ZHA_CONFIG,
DATA_ZHA_DISPATCHERS,
)
from homeassistant.components.zha.core.helpers import convert_ieee
from homeassistant.util import slugify
from tests.common import mock_coro
@@ -21,7 +22,7 @@ class FakeApplication:
def __init__(self):
"""Init fake application."""
self.ieee = convert_ieee("00:15:8d:00:02:32:4f:32")
self.ieee = EUI64.convert("00:15:8d:00:02:32:4f:32")
self.nwk = 0x087D
@@ -71,7 +72,6 @@ def patch_cluster(cluster):
cluster.configure_reporting = CoroutineMock(return_value=[0])
cluster.deserialize = Mock()
cluster.handle_cluster_request = Mock()
cluster.handle_cluster_general_request = Mock()
cluster.read_attributes = CoroutineMock()
cluster.read_attributes_raw = Mock()
cluster.unbind = CoroutineMock(return_value=[0])
@@ -83,7 +83,7 @@ class FakeDevice:
def __init__(self, ieee, manufacturer, model):
"""Init fake device."""
self._application = APPLICATION
self.ieee = convert_ieee(ieee)
self.ieee = EUI64.convert(ieee)
self.nwk = 0xB79C
self.zdo = Mock()
self.endpoints = {0: self.zdo}
@@ -230,3 +230,12 @@ async def async_test_device_join(
domain, zigpy_device, cluster, use_suffix=device_type is None
)
assert hass.states.get(entity_id) is not None
def make_zcl_header(command_id: int, global_command: bool = True) -> zcl_f.ZCLHeader:
"""Cluster.handle_message() ZCL Header helper."""
if global_command:
frc = zcl_f.FrameControl(zcl_f.FrameType.GLOBAL_COMMAND)
else:
frc = zcl_f.FrameControl(zcl_f.FrameType.CLUSTER_COMMAND)
return zcl_f.ZCLHeader(frc, tsn=1, command_id=command_id)