Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyoverkiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -77,13 +78,15 @@ class TestDevice:
),
(
"io://1234-5678-9012/10077486#8",
"io://1234-5678-9012/10077486",
Protocol.IO,
"1234-5678-9012",
"10077486",
8,
True,
),
(
"hue://1234-1234-4411/001788676dde/lights/10",
"hue://1234-1234-4411/001788676dde/lights/10",
Protocol.HUE,
"1234-1234-4411",
Expand All @@ -93,13 +96,15 @@ 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",
5,
True,
),
(
"upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400",
"upnpcontrol://1234-1234-4411/uuid:RINCON_000E586B571601400",
Protocol.UPNP_CONTROL,
"1234-1234-4411",
Expand All @@ -109,13 +114,15 @@ 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",
7,
True,
),
(
"zigbee://1234-1234-1234/9876/1",
"zigbee://1234-1234-1234/9876/1",
Protocol.ZIGBEE,
"1234-1234-1234",
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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
Expand Down