From 65eaff20f62feb68d37b932665dc908c9a2bbf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jaworski?= Date: Tue, 27 Feb 2024 23:16:39 +0100 Subject: [PATCH] cover test api response update, fix wrong seeding of light tests --- blebox_uniapi/box.py | 5 ----- tests/conftest.py | 9 ++++++--- tests/test_cover.py | 26 +++++++++++++++++++++++--- tests/test_light.py | 21 ++++++++------------- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/blebox_uniapi/box.py b/blebox_uniapi/box.py index b352b15..5b207da 100644 --- a/blebox_uniapi/box.py +++ b/blebox_uniapi/box.py @@ -117,15 +117,10 @@ def __init__( self._firmware_version = firmware_version self._hardware_version = hardware_version self._api_version = level - self._model = config.get("model", type) - self._api = config.get("api", {}) - self._features = self.create_features(config, info, extended_state) - self._config = config - self._update_last_data(extended_state) def create_features( diff --git a/tests/conftest.py b/tests/conftest.py index 6839250..89a6230 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -154,11 +154,14 @@ async def allow_get_info(self, aioclient_mock, info=None): json_get_expect( aioclient_mock, f"http://{self.IP}:80/api/device/state", json=data ) - if hasattr(self, "DEVICE_EXTENDED_INFO"): - data = self.DEVICE_EXTENDED_INFO if info is None else info + if ( + (hasattr(self, "DEVICE_EXTENDED_INFO")) and + (path := getattr(self, "DEVICE_EXTENDED_INFO_PATH")) + ): + data = self.DEVICE_EXTENDED_INFO or info json_get_expect( aioclient_mock, - f"http://{self.IP}:80{self.DEVICE_EXTENDED_INFO_PATH}", + f"http://{self.IP}:80/{path.lstrip('/')}", json=data, ) diff --git a/tests/test_cover.py b/tests/test_cover.py index f076af7..c3c43fc 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -480,7 +480,7 @@ async def test_unkown_position(self, aioclient_mock): class TestGateBoxB(CoverTest): """Tests for cover devices representing a BleBox gateBoxB subgroup.""" - DEV_INFO_PATH = "state" + DEV_INFO_PATH = "state/extended" DEVICE_INFO = json.loads( """ @@ -512,7 +512,17 @@ class TestGateBoxB(CoverTest): STATE_DEFAULT = json.loads( """ { - "gate": {"currentPos": 0} + "gate": { + "currentPos": 0, + "openCloseMode": 0, + "gateType": 1, + "gatePulseTimeMs": 1500, + "gateOutputState": 0, + "extraButtonType": 1, + "extraButtonPulseTimeMs": 1500, + "extraButtonOutputState": 0, + "inputsType": 0 + } } """ ) @@ -524,7 +534,17 @@ class TestGateBoxB(CoverTest): STATE_UNKNOWN = json.loads( """ { - "gate": {"currentPos": -1} + "gate": { + "currentPos": -1, + "openCloseMode": 0, + "gateType": 1, + "gatePulseTimeMs": 1500, + "gateOutputState": 0, + "extraButtonType": 1, + "extraButtonPulseTimeMs": 1500, + "extraButtonOutputState": 0, + "inputsType": 0 + } } """ ) diff --git a/tests/test_light.py b/tests/test_light.py index 2fa5b7d..f306f79 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -444,7 +444,7 @@ class TestWLightBoxS(DefaultBoxTest): DEVICE_EXTENDED_INFO = { "rgbw": { "desiredColor": "f5", - "currentColor": "f5", + "currentColor": "f5", # 245 in decimal "lastOnColor": "f5", "durationsMs": {"colorFade": 1000, "effectFade": 1000, "effectStep": 1000}, "effectID": 0, @@ -542,9 +542,8 @@ async def test_init(self, aioclient_mock): assert entity.name == "My wLightBoxS (wLightBoxS#brightness_mono1)" assert entity.unique_id == "BleBox-wLightBoxS-1afe34e750b8-brightness_mono1" - assert entity.brightness is None - - assert entity.is_on is None + assert entity.brightness == 0xf5 + assert entity.is_on async def test_device_info(self, aioclient_mock): await self.allow_get_info(aioclient_mock, self.DEVICE_INFO) @@ -863,16 +862,12 @@ async def test_init(self, aioclient_mock): assert entity.name == "My light 1 (wLightBox#color_RGBorW)" assert entity.unique_id == "BleBox-wLightBox-1afe34e750b8-color_RGBorW" # In current state of master branch white_value is not property of BleBoxLightEntity, fake test... dissapointing - # assert entity.supported_features & SUPPORT_WHITE_VALUE - # assert entity.white_value is None - - # assert entity.supported_features & SUPPORT_COLOR - # assert entity.hs_color is None - # assert entity.white_value is None + assert entity._feature.supports_white + assert entity._feature.white_value == 0x3A - # assert entity.supported_features & SUPPORT_BRIGHTNESS - # assert entity.brightness == 123 - assert entity.is_on is None + assert entity._feature.supports_color + assert entity.brightness == 0xFA + assert entity.is_on is True async def test_device_info(self, aioclient_mock): await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)