Skip to content

Commit

Permalink
Improve typing (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dukeofphilberg authored Mar 15, 2024
1 parent c65eb2b commit 2c99f21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
from typing import Dict, List

from aiohttp import ClientSession

Expand All @@ -24,7 +23,7 @@ class LinkPlayDevice():
"""Represents a LinkPlay device."""

bridge: LinkPlayBridge
properties: Dict[DeviceAttribute, str] = dict.fromkeys(DeviceAttribute.__members__.values(), "")
properties: dict[DeviceAttribute, str] = dict.fromkeys(DeviceAttribute.__members__.values(), "")

def __init__(self, bridge: LinkPlayBridge):
self.bridge = bridge
Expand Down Expand Up @@ -62,7 +61,7 @@ class LinkPlayPlayer():
"""Represents a LinkPlay player."""

bridge: LinkPlayBridge
properties: Dict[PlayerAttribute, str] = dict.fromkeys(PlayerAttribute.__members__.values(), "")
properties: dict[PlayerAttribute, str] = dict.fromkeys(PlayerAttribute.__members__.values(), "")

def __init__(self, bridge: LinkPlayBridge):
self.bridge = bridge
Expand Down Expand Up @@ -229,7 +228,7 @@ def endpoint(self) -> str:
"""Returns the current player endpoint."""
return f"{self.protocol}://{self.ip_address}"

async def json_request(self, command: str) -> Dict[str, str]:
async def json_request(self, command: str) -> dict[str, str]:
"""Performs a GET request on the given command and returns the result as a JSON object."""
return await session_call_api_json(self.endpoint, self.session, command)

Expand All @@ -243,9 +242,9 @@ class LinkPlayMultiroom():
The leader is the device that controls the group."""

leader: LinkPlayBridge
followers: List[LinkPlayBridge]
followers: list[LinkPlayBridge]

def __init__(self, leader: LinkPlayBridge, followers: List[LinkPlayBridge]):
def __init__(self, leader: LinkPlayBridge, followers: list[LinkPlayBridge]):
self.leader = leader
self.followers = followers

Expand Down
14 changes: 7 additions & 7 deletions src/linkplay/discovery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List
from typing import Any

from aiohttp import ClientSession
from async_upnp_client.search import async_search
Expand All @@ -21,9 +21,9 @@ async def linkplay_factory_bridge(ip_address: str, session: ClientSession) -> Li
return bridge


async def discover_linkplay_bridges(session: ClientSession) -> List[LinkPlayBridge]:
async def discover_linkplay_bridges(session: ClientSession) -> list[LinkPlayBridge]:
"""Attempts to discover LinkPlay devices on the local network."""
devices: List[LinkPlayBridge] = []
devices: list[LinkPlayBridge] = []

async def add_linkplay_device_to_list(upnp_device: CaseInsensitiveDict):
ip_address: str | None = upnp_device.get('_host')
Expand All @@ -42,17 +42,17 @@ async def add_linkplay_device_to_list(upnp_device: CaseInsensitiveDict):
return devices


async def discover_multirooms(bridges: List[LinkPlayBridge]) -> List[LinkPlayMultiroom]:
async def discover_multirooms(bridges: list[LinkPlayBridge]) -> list[LinkPlayMultiroom]:
"""Discovers multirooms through the list of provided bridges."""
multirooms: List[LinkPlayMultiroom] = []
multirooms: list[LinkPlayMultiroom] = []

for bridge in bridges:
properties: Dict[Any, Any] = await bridge.json_request(LinkPlayCommand.MULTIROOM_LIST)
properties: dict[Any, Any] = await bridge.json_request(LinkPlayCommand.MULTIROOM_LIST)

if int(properties[MultiroomAttribute.NUM_FOLLOWERS]) == 0:
continue

followers: List[LinkPlayBridge] = []
followers: list[LinkPlayBridge] = []
for follower in properties[MultiroomAttribute.FOLLOWER_LIST]:
follower_uuid = follower[MultiroomAttribute.UUID]
if follower_bridge := next((b for b in bridges if b.device.uuid == follower_uuid), None):
Expand Down

0 comments on commit 2c99f21

Please sign in to comment.