python-linkplay 0.0.2__tar.gz → 0.0.4__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.
- {python_linkplay-0.0.2/src/python_linkplay.egg-info → python_linkplay-0.0.4}/PKG-INFO +1 -1
- python_linkplay-0.0.4/src/linkplay/__main__.py +20 -0
- python_linkplay-0.0.4/src/linkplay/__version__.py +1 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/bridge.py +18 -4
- python_linkplay-0.0.4/src/linkplay/controller.py +54 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/discovery.py +9 -28
- {python_linkplay-0.0.2 → python_linkplay-0.0.4/src/python_linkplay.egg-info}/PKG-INFO +1 -1
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/SOURCES.txt +1 -0
- python_linkplay-0.0.2/src/linkplay/__main__.py +0 -14
- python_linkplay-0.0.2/src/linkplay/__version__.py +0 -1
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/LICENSE +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/README.md +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/pyproject.toml +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/setup.cfg +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/setup.py +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/__init__.py +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/consts.py +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/exceptions.py +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/linkplay/utils.py +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/dependency_links.txt +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/not-zip-safe +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/requires.txt +0 -0
- {python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/top_level.txt +0 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
import asyncio
|
2
|
+
import aiohttp
|
3
|
+
|
4
|
+
from linkplay.controller import LinkPlayController
|
5
|
+
|
6
|
+
|
7
|
+
async def main():
|
8
|
+
async with aiohttp.ClientSession() as session:
|
9
|
+
controller = LinkPlayController(session)
|
10
|
+
|
11
|
+
await controller.discover_bridges()
|
12
|
+
for bridge in controller.bridges:
|
13
|
+
print(bridge)
|
14
|
+
|
15
|
+
await controller.discover_multirooms()
|
16
|
+
for multiroom in controller.multirooms:
|
17
|
+
print(multiroom.followers)
|
18
|
+
|
19
|
+
if __name__ == "__main__":
|
20
|
+
asyncio.run(main())
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = '0.0.4'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
|
2
|
+
from typing import Any
|
3
3
|
from aiohttp import ClientSession
|
4
4
|
|
5
5
|
from linkplay.consts import (
|
@@ -15,8 +15,10 @@ from linkplay.consts import (
|
|
15
15
|
InputMode,
|
16
16
|
SpeakerType,
|
17
17
|
PlayingMode,
|
18
|
-
INPUT_MODE_MAP
|
18
|
+
INPUT_MODE_MAP,
|
19
|
+
MultiroomAttribute
|
19
20
|
)
|
21
|
+
|
20
22
|
from linkplay.utils import session_call_api_json, session_call_api_ok, decode_hexstr
|
21
23
|
|
22
24
|
|
@@ -243,9 +245,21 @@ class LinkPlayMultiroom():
|
|
243
245
|
leader: LinkPlayBridge
|
244
246
|
followers: list[LinkPlayBridge]
|
245
247
|
|
246
|
-
def __init__(self, leader: LinkPlayBridge
|
248
|
+
def __init__(self, leader: LinkPlayBridge):
|
247
249
|
self.leader = leader
|
248
|
-
self.followers =
|
250
|
+
self.followers = []
|
251
|
+
|
252
|
+
async def update_status(self, bridges: list[LinkPlayBridge]) -> None:
|
253
|
+
"""Updates the multiroom status."""
|
254
|
+
properties: dict[Any, Any] = await self.leader.json_request(LinkPlayCommand.MULTIROOM_LIST)
|
255
|
+
|
256
|
+
self.followers = []
|
257
|
+
if int(properties[MultiroomAttribute.NUM_FOLLOWERS]) == 0:
|
258
|
+
return
|
259
|
+
|
260
|
+
follower_uuids = [follower[MultiroomAttribute.UUID] for follower in properties[MultiroomAttribute.FOLLOWER_LIST]]
|
261
|
+
new_followers = [bridge for bridge in bridges if bridge.device.uuid in follower_uuids]
|
262
|
+
self.followers.extend(new_followers)
|
249
263
|
|
250
264
|
async def ungroup(self) -> None:
|
251
265
|
"""Ungroups the multiroom group."""
|
@@ -0,0 +1,54 @@
|
|
1
|
+
from aiohttp import ClientSession
|
2
|
+
|
3
|
+
from linkplay.bridge import LinkPlayBridge, LinkPlayMultiroom
|
4
|
+
from linkplay.discovery import discover_linkplay_bridges
|
5
|
+
|
6
|
+
|
7
|
+
class LinkPlayController():
|
8
|
+
"""Represents a LinkPlay controller to manage the devices and multirooms."""
|
9
|
+
|
10
|
+
session: ClientSession
|
11
|
+
bridges: list[LinkPlayBridge]
|
12
|
+
multirooms: list[LinkPlayMultiroom]
|
13
|
+
|
14
|
+
def __init__(self, session: ClientSession):
|
15
|
+
self.session = session
|
16
|
+
self.bridges = []
|
17
|
+
self.multirooms = []
|
18
|
+
|
19
|
+
async def discover_bridges(self) -> None:
|
20
|
+
"""Attempts to discover LinkPlay devices on the local network."""
|
21
|
+
|
22
|
+
# Discover new bridges
|
23
|
+
discovered_bridges = await discover_linkplay_bridges(self.session)
|
24
|
+
current_bridges = [bridge.device.uuid for bridge in self.bridges]
|
25
|
+
new_bridges = [discovered_bridge for discovered_bridge in discovered_bridges if discovered_bridge.device.uuid not in current_bridges]
|
26
|
+
self.bridges.extend(new_bridges)
|
27
|
+
|
28
|
+
async def discover_multirooms(self) -> None:
|
29
|
+
"""Attempts to discover multirooms on the local network."""
|
30
|
+
|
31
|
+
# Create new multirooms from new bridges
|
32
|
+
new_multirooms = []
|
33
|
+
for bridge in self.bridges:
|
34
|
+
has_multiroom = any(multiroom for multiroom in self.multirooms if multiroom.leader == bridge)
|
35
|
+
|
36
|
+
if has_multiroom:
|
37
|
+
continue
|
38
|
+
|
39
|
+
multiroom = LinkPlayMultiroom(bridge)
|
40
|
+
await multiroom.update_status(self.bridges)
|
41
|
+
if len(multiroom.followers) > 0:
|
42
|
+
new_multirooms.append(multiroom)
|
43
|
+
|
44
|
+
# Update existing multirooms
|
45
|
+
for multiroom in self.multirooms:
|
46
|
+
await multiroom.update_status(self.bridges)
|
47
|
+
|
48
|
+
# Remove multirooms if they have no followers
|
49
|
+
empty_multirooms = [multiroom for multiroom in self.multirooms if not multiroom.followers]
|
50
|
+
for empty_multiroom in empty_multirooms:
|
51
|
+
self.multirooms.remove(empty_multiroom)
|
52
|
+
|
53
|
+
# Add new multirooms
|
54
|
+
self.multirooms.extend(new_multirooms)
|
@@ -5,7 +5,7 @@ from async_upnp_client.search import async_search
|
|
5
5
|
from async_upnp_client.utils import CaseInsensitiveDict
|
6
6
|
|
7
7
|
from linkplay.consts import UPNP_DEVICE_TYPE, LinkPlayCommand, MultiroomAttribute
|
8
|
-
from linkplay.bridge import LinkPlayBridge
|
8
|
+
from linkplay.bridge import LinkPlayBridge
|
9
9
|
from linkplay.exceptions import LinkPlayRequestException
|
10
10
|
|
11
11
|
|
@@ -21,7 +21,7 @@ async def linkplay_factory_bridge(ip_address: str, session: ClientSession) -> Li
|
|
21
21
|
return bridge
|
22
22
|
|
23
23
|
|
24
|
-
async def discover_linkplay_bridges(session: ClientSession) -> list[LinkPlayBridge]:
|
24
|
+
async def discover_linkplay_bridges(session: ClientSession, discovery_through_multiroom: bool = True) -> list[LinkPlayBridge]:
|
25
25
|
"""Attempts to discover LinkPlay devices on the local network."""
|
26
26
|
bridges: dict[str, LinkPlayBridge] = {}
|
27
27
|
|
@@ -40,34 +40,15 @@ async def discover_linkplay_bridges(session: ClientSession) -> list[LinkPlayBrid
|
|
40
40
|
)
|
41
41
|
|
42
42
|
# Discover additional bridges through grouped multirooms
|
43
|
-
|
44
|
-
|
45
|
-
for
|
46
|
-
|
43
|
+
if discovery_through_multiroom:
|
44
|
+
multiroom_discovered_bridges: dict[str, LinkPlayBridge] = {}
|
45
|
+
for bridge in bridges.values():
|
46
|
+
for new_bridge in await discover_bridges_through_multiroom(bridge, session):
|
47
|
+
multiroom_discovered_bridges[new_bridge.device.uuid] = new_bridge
|
47
48
|
|
48
|
-
|
49
|
-
return list(bridges.values())
|
50
|
-
|
51
|
-
|
52
|
-
async def discover_multirooms(bridges: list[LinkPlayBridge]) -> list[LinkPlayMultiroom]:
|
53
|
-
"""Discovers multirooms through the list of provided bridges."""
|
54
|
-
multirooms: list[LinkPlayMultiroom] = []
|
55
|
-
bridges_dict: dict[str, LinkPlayBridge] = {bridge.device.uuid: bridge for bridge in bridges}
|
56
|
-
|
57
|
-
for bridge in bridges:
|
58
|
-
properties: dict[Any, Any] = await bridge.json_request(LinkPlayCommand.MULTIROOM_LIST)
|
49
|
+
bridges = bridges | multiroom_discovered_bridges
|
59
50
|
|
60
|
-
|
61
|
-
continue
|
62
|
-
|
63
|
-
followers: list[LinkPlayBridge] = []
|
64
|
-
for follower in properties[MultiroomAttribute.FOLLOWER_LIST]:
|
65
|
-
if follower[MultiroomAttribute.UUID] in bridges_dict:
|
66
|
-
followers.append(bridges_dict[follower[MultiroomAttribute.UUID]])
|
67
|
-
|
68
|
-
multirooms.append(LinkPlayMultiroom(bridge, followers))
|
69
|
-
|
70
|
-
return multirooms
|
51
|
+
return list(bridges.values())
|
71
52
|
|
72
53
|
|
73
54
|
async def discover_bridges_through_multiroom(bridge: LinkPlayBridge,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import aiohttp
|
3
|
-
|
4
|
-
from linkplay.discovery import discover_linkplay_bridges, discover_multirooms
|
5
|
-
|
6
|
-
|
7
|
-
async def main():
|
8
|
-
async with aiohttp.ClientSession() as session:
|
9
|
-
bridges = await discover_linkplay_bridges(session)
|
10
|
-
multirooms = await discover_multirooms(bridges)
|
11
|
-
return bridges, multirooms
|
12
|
-
|
13
|
-
if __name__ == "__main__":
|
14
|
-
asyncio.run(main())
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = '0.0.2'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{python_linkplay-0.0.2 → python_linkplay-0.0.4}/src/python_linkplay.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|