From 50dd845ea8700d45b1f36710e256609b9449b3bc Mon Sep 17 00:00:00 2001 From: nyro Date: Mon, 7 Nov 2022 18:56:06 +0100 Subject: [PATCH 1/4] Add base_device_url and corresponding tests --- pyoverkiz/models.py | 5 +++++ tests/test_client.py | 1 + tests/test_models.py | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pyoverkiz/models.py b/pyoverkiz/models.py index 6717716f..85a62c95 100644 --- a/pyoverkiz/models.py +++ b/pyoverkiz/models.py @@ -144,6 +144,7 @@ class Device: enabled: bool label: str = field(repr=obfuscate_string) device_url: str = field(repr=obfuscate_id) + base_device_url: str = field(repr=obfuscate_id) gateway_id: str = field(repr=obfuscate_id) device_address: str = field(repr=obfuscate_id) subsystem_id: int | None = None @@ -201,6 +202,10 @@ def __init__( self.gateway_id = match.group("gatewayId") self.device_address = match.group("deviceAddress") + self.base_device_url = ( + self.protocol + "://" + self.gateway_id + "/" + self.device_address + ) + if match.group("subsystemId"): self.subsystem_id = int(match.group("subsystemId")) self.is_sub_device = self.subsystem_id > 1 diff --git a/tests/test_client.py b/tests/test_client.py index db999a85..200a022b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -151,6 +151,7 @@ async def test_get_setup(self, client, fixture_name: str, device_count: int): assert device.gateway_id assert device.device_address assert device.protocol + assert device.base_device_url class MockResponse: diff --git a/tests/test_models.py b/tests/test_models.py index fc0f968a..857e2069 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -65,9 +65,10 @@ class TestDevice: @pytest.mark.parametrize( - "device_url, protocol, gateway_id, device_address, subsystem_id, is_sub_device", + "device_url, base_device_url, protocol, gateway_id, device_address, subsystem_id, is_sub_device", [ ( + "io://1234-5678-9012/10077486", "io://1234-5678-9012/10077486", Protocol.IO, "1234-5678-9012", @@ -77,6 +78,7 @@ class TestDevice: ), ( "io://1234-5678-9012/10077486#8", + "io://1234-5678-9012/10077486", Protocol.IO, "1234-5678-9012", "10077486", @@ -84,6 +86,7 @@ class TestDevice: True, ), ( + "hue://1234-1234-4411/001788676dde/lights/10", "hue://1234-1234-4411/001788676dde/lights/10", Protocol.HUE, "1234-1234-4411", @@ -93,6 +96,7 @@ class TestDevice: ), ( "hue://1234-1234-4411/001788676dde/lights/10#5", + "hue://1234-1234-4411/001788676dde/lights/10", Protocol.HUE, "1234-1234-4411", "001788676dde/lights/10", @@ -100,6 +104,7 @@ class TestDevice: True, ), ( + "upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400", "upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400", Protocol.UPNP_CONTROL, "1234-1234-4411", @@ -109,6 +114,7 @@ class TestDevice: ), ( "upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400#7", + "upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400", Protocol.UPNP_CONTROL, "1234-1234-4411", "uuid:RINCON_000E586B571601400", @@ -116,6 +122,7 @@ class TestDevice: True, ), ( + "zigbee://1234-1234-1234/9876/1", "zigbee://1234-1234-1234/9876/1", Protocol.ZIGBEE, "1234-1234-1234", @@ -125,6 +132,7 @@ class TestDevice: ), ( "zigbee://1234-1234-1234/9876/1#2", + "zigbee://1234-1234-1234/9876/1", Protocol.ZIGBEE, "1234-1234-1234", "9876/1", @@ -136,6 +144,7 @@ class TestDevice: def test_base_url_parsing( self, device_url: str, + base_device_url: str, protocol: Protocol, gateway_id: str, device_address: str, @@ -149,6 +158,7 @@ def test_base_url_parsing( hump_device = humps.decamelize(test_device) device = Device(**hump_device) + assert device.base_device_url == base_device_url assert device.protocol == protocol assert device.gateway_id == gateway_id assert device.device_address == device_address From 5401425b7d50c817f3783d4577f944db3f5321c8 Mon Sep 17 00:00:00 2001 From: nyro Date: Thu, 3 Aug 2023 22:14:15 +0200 Subject: [PATCH 2/4] Update for linter --- pyoverkiz/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyoverkiz/models.py b/pyoverkiz/models.py index 8e460b5b..91ab2a82 100644 --- a/pyoverkiz/models.py +++ b/pyoverkiz/models.py @@ -514,8 +514,7 @@ def __init__( self.protocol_type = protocol_type self.name = EventName(name) self.failure_type_code = ( - None if failure_type_code is None else FailureType( - failure_type_code) + None if failure_type_code is None else FailureType(failure_type_code) ) @@ -621,8 +620,7 @@ def __init__( self.time_reliable = time_reliable self.connectivity = Connectivity(**connectivity) self.up_to_date = up_to_date - self.update_status = UpdateBoxStatus( - update_status) if update_status else None + self.update_status = UpdateBoxStatus(update_status) if update_status else None self.sync_in_progress = sync_in_progress self.partners = [Partner(**p) for p in partners] if partners else [] self.type = GatewayType(type) if type else None From 93e264d9c205e30c4a39b4479ca993080c0a1beb Mon Sep 17 00:00:00 2001 From: nyro Date: Thu, 3 Aug 2023 20:24:41 +0000 Subject: [PATCH 3/4] Update models.py for linter From 2acfeb9bb8f5ed21dbc87446dab7d6f418c6dbca Mon Sep 17 00:00:00 2001 From: nyro Date: Thu, 3 Aug 2023 20:31:42 +0000 Subject: [PATCH 4/4] FIx missing device URL tests --- tests/test_models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index ced80a22..ada51d04 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -140,6 +140,7 @@ class TestDevice: True, ), ( + "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", Protocol.ELIOT, "ELIOT-000000000000000000000000000ABCDE", @@ -149,6 +150,7 @@ class TestDevice: ), ( "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc#1", + "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", Protocol.ELIOT, "ELIOT-000000000000000000000000000ABCDE", "00000000000000000000000000125abc", @@ -158,6 +160,7 @@ class TestDevice: # Wrong device urls: ( "foo://whatever-blah/12", + "unknown://whatever-blah/12", Protocol.UNKNOWN, "whatever-blah", "12", @@ -170,6 +173,7 @@ class TestDevice: None, None, None, + None, False, ), ],