diff --git a/pyoverkiz/models.py b/pyoverkiz/models.py index ab681326..91ab2a82 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 | None = field(repr=obfuscate_id) gateway_id: str | None = field(repr=obfuscate_id) device_address: str | None = field(repr=obfuscate_id) subsystem_id: int | None = None @@ -190,6 +191,7 @@ def __init__( self.type = ProductType(type) self.place_oid = place_oid + self.base_device_url = None self.protocol = None self.gateway_id = None self.device_address = None @@ -204,6 +206,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 54e2101a..8ad547b8 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -180,6 +180,7 @@ async def test_get_setup( assert device.gateway_id assert device.device_address assert device.protocol + assert device.base_device_url @pytest.mark.parametrize( "fixture_name", diff --git a/tests/test_models.py b/tests/test_models.py index 02caa9f2..ada51d04 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", @@ -132,6 +140,7 @@ class TestDevice: True, ), ( + "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", Protocol.ELIOT, "ELIOT-000000000000000000000000000ABCDE", @@ -141,6 +150,7 @@ class TestDevice: ), ( "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc#1", + "eliot://ELIOT-000000000000000000000000000ABCDE/00000000000000000000000000125abc", Protocol.ELIOT, "ELIOT-000000000000000000000000000ABCDE", "00000000000000000000000000125abc", @@ -150,6 +160,7 @@ class TestDevice: # Wrong device urls: ( "foo://whatever-blah/12", + "unknown://whatever-blah/12", Protocol.UNKNOWN, "whatever-blah", "12", @@ -162,6 +173,7 @@ class TestDevice: None, None, None, + None, False, ), ], @@ -169,6 +181,7 @@ class TestDevice: def test_base_url_parsing( self, device_url: str, + base_device_url: str, protocol: Protocol, gateway_id: str, device_address: str, @@ -182,6 +195,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