python-linkplay 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {python_linkplay-0.0.1/src/python_linkplay.egg-info → python_linkplay-0.0.2}/PKG-INFO +1 -1
  2. python_linkplay-0.0.2/src/linkplay/__version__.py +1 -0
  3. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/consts.py +1 -0
  4. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/discovery.py +29 -6
  5. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/utils.py +4 -1
  6. {python_linkplay-0.0.1 → python_linkplay-0.0.2/src/python_linkplay.egg-info}/PKG-INFO +1 -1
  7. python_linkplay-0.0.1/src/linkplay/__version__.py +0 -1
  8. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/LICENSE +0 -0
  9. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/README.md +0 -0
  10. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/pyproject.toml +0 -0
  11. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/setup.cfg +0 -0
  12. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/setup.py +0 -0
  13. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/__init__.py +0 -0
  14. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/__main__.py +0 -0
  15. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/bridge.py +0 -0
  16. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/linkplay/exceptions.py +0 -0
  17. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/python_linkplay.egg-info/SOURCES.txt +0 -0
  18. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/python_linkplay.egg-info/dependency_links.txt +0 -0
  19. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/python_linkplay.egg-info/not-zip-safe +0 -0
  20. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/python_linkplay.egg-info/requires.txt +0 -0
  21. {python_linkplay-0.0.1 → python_linkplay-0.0.2}/src/python_linkplay.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_linkplay
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: A Python Library for Seamless LinkPlay Device Control
5
5
  Author: Velleman Group nv
6
6
  License: MIT
@@ -0,0 +1 @@
1
+ __version__ = '0.0.2'
@@ -285,3 +285,4 @@ class MultiroomAttribute(StrEnum):
285
285
  NUM_FOLLOWERS = "slaves"
286
286
  FOLLOWER_LIST = "slave_list"
287
287
  UUID = "uuid"
288
+ IP = "ip"
@@ -23,7 +23,7 @@ async def linkplay_factory_bridge(ip_address: str, session: ClientSession) -> Li
23
23
 
24
24
  async def discover_linkplay_bridges(session: ClientSession) -> list[LinkPlayBridge]:
25
25
  """Attempts to discover LinkPlay devices on the local network."""
26
- devices: list[LinkPlayBridge] = []
26
+ bridges: dict[str, LinkPlayBridge] = {}
27
27
 
28
28
  async def add_linkplay_device_to_list(upnp_device: CaseInsensitiveDict):
29
29
  ip_address: str | None = upnp_device.get('_host')
@@ -32,19 +32,27 @@ async def discover_linkplay_bridges(session: ClientSession) -> list[LinkPlayBrid
32
32
  return
33
33
 
34
34
  if bridge := await linkplay_factory_bridge(ip_address, session):
35
- devices.append(bridge)
35
+ bridges[bridge.device.uuid] = bridge
36
36
 
37
37
  await async_search(
38
38
  search_target=UPNP_DEVICE_TYPE,
39
39
  async_callback=add_linkplay_device_to_list
40
40
  )
41
41
 
42
- return devices
42
+ # Discover additional bridges through grouped multirooms
43
+ multiroom_discovered_bridges: dict[str, LinkPlayBridge] = {}
44
+ for bridge in bridges.values():
45
+ for new_bridge in await discover_bridges_through_multiroom(bridge, session):
46
+ multiroom_discovered_bridges[new_bridge.device.uuid] = new_bridge
47
+
48
+ bridges = bridges | multiroom_discovered_bridges
49
+ return list(bridges.values())
43
50
 
44
51
 
45
52
  async def discover_multirooms(bridges: list[LinkPlayBridge]) -> list[LinkPlayMultiroom]:
46
53
  """Discovers multirooms through the list of provided bridges."""
47
54
  multirooms: list[LinkPlayMultiroom] = []
55
+ bridges_dict: dict[str, LinkPlayBridge] = {bridge.device.uuid: bridge for bridge in bridges}
48
56
 
49
57
  for bridge in bridges:
50
58
  properties: dict[Any, Any] = await bridge.json_request(LinkPlayCommand.MULTIROOM_LIST)
@@ -54,10 +62,25 @@ async def discover_multirooms(bridges: list[LinkPlayBridge]) -> list[LinkPlayMul
54
62
 
55
63
  followers: list[LinkPlayBridge] = []
56
64
  for follower in properties[MultiroomAttribute.FOLLOWER_LIST]:
57
- follower_uuid = follower[MultiroomAttribute.UUID]
58
- if follower_bridge := next((b for b in bridges if b.device.uuid == follower_uuid), None):
59
- followers.append(follower_bridge)
65
+ if follower[MultiroomAttribute.UUID] in bridges_dict:
66
+ followers.append(bridges_dict[follower[MultiroomAttribute.UUID]])
60
67
 
61
68
  multirooms.append(LinkPlayMultiroom(bridge, followers))
62
69
 
63
70
  return multirooms
71
+
72
+
73
+ async def discover_bridges_through_multiroom(bridge: LinkPlayBridge,
74
+ session: ClientSession) -> list[LinkPlayBridge]:
75
+ """Discovers bridges through the multiroom of the provided bridge."""
76
+ properties: dict[Any, Any] = await bridge.json_request(LinkPlayCommand.MULTIROOM_LIST)
77
+
78
+ if int(properties[MultiroomAttribute.NUM_FOLLOWERS]) == 0:
79
+ return []
80
+
81
+ followers: list[LinkPlayBridge] = []
82
+ for follower in properties[MultiroomAttribute.FOLLOWER_LIST]:
83
+ if new_bridge := await linkplay_factory_bridge(follower[MultiroomAttribute.IP], session):
84
+ followers.append(new_bridge)
85
+
86
+ return followers
@@ -56,4 +56,7 @@ async def session_call_api_ok(endpoint: str, session: ClientSession, command: st
56
56
 
57
57
  def decode_hexstr(hexstr: str) -> str:
58
58
  """Decode a hex string."""
59
- return bytes.fromhex(hexstr).decode("utf-8")
59
+ try:
60
+ return bytes.fromhex(hexstr).decode("utf-8")
61
+ except ValueError:
62
+ return hexstr
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_linkplay
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: A Python Library for Seamless LinkPlay Device Control
5
5
  Author: Velleman Group nv
6
6
  License: MIT
@@ -1 +0,0 @@
1
- __version__ = '0.0.1'
File without changes