Skip to content

Commit

Permalink
Merge pull request #41 from noahhusby/refact/rename-instance
Browse files Browse the repository at this point in the history
Rename instance to client
  • Loading branch information
noahhusby authored Sep 24, 2024
2 parents 56c7438 + dfa4e76 commit 31dadb4
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions aiorussound/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ class Controller:

def __init__(
self,
instance: RussoundClient,
client: RussoundClient,
parent_controller: Controller,
controller_id: int,
mac_address: str,
controller_type: str,
firmware_version: str,
) -> None:
"""Initialize the controller."""
self.instance = instance
self.client = client
self.parent_controller = parent_controller
self.controller_id = controller_id
self.mac_address = mac_address
Expand Down Expand Up @@ -291,9 +291,9 @@ async def _init_zones(self) -> None:
for zone_id in range(1, self.max_zones + 1):
try:
device_str = zone_device_str(self.controller_id, zone_id)
name = await self.instance.get_variable(device_str, "name")
name = await self.client.get_variable(device_str, "name")
if name:
zone = Zone(self.instance, self, zone_id, name)
zone = Zone(self.client, self, zone_id, name)
await zone.fetch_configuration()
self.zones[zone_id] = zone

Expand All @@ -310,10 +310,10 @@ class Zone:
"""

def __init__(
self, instance: RussoundClient, controller: Controller, zone_id: int, name: str
self, client: RussoundClient, controller: Controller, zone_id: int, name: str
) -> None:
"""Initialize a zone object."""
self.instance = instance
self.client = client
self.controller = controller
self.zone_id = int(zone_id)
self.name = name
Expand All @@ -322,7 +322,7 @@ async def fetch_configuration(self) -> None:
"""Fetches zone configuration from controller."""
for prop in ZONE_PROPERTIES:
try:
await self.instance.get_variable(self.device_str(), prop)
await self.client.get_variable(self.device_str(), prop)
except CommandError:
continue

Expand Down Expand Up @@ -355,28 +355,28 @@ async def watch(self) -> str:
state changes (and those of the source they are currently connected to)
back to the client.
"""
return await self.instance.watch(self.device_str())
return await self.client.watch(self.device_str())

async def unwatch(self) -> str:
"""Remove a zone from the watchlist."""
return await self.instance.unwatch(self.device_str())
return await self.client.unwatch(self.device_str())

async def send_event(self, event_name, *args) -> str:
"""Send an event to a zone."""
cmd = f"EVENT {self.device_str()}!{event_name} {" ".join(str(x) for x in args)}"
return await self.instance.connection_handler.send(cmd)
return await self.client.connection_handler.send(cmd)

def _get(self, variable, default=None) -> str:
return self.instance.get_cached_variable(self.device_str(), variable, default)
return self.client.get_cached_variable(self.device_str(), variable, default)

def fetch_current_source(self) -> Source:
"""Return the current source as a source object."""
current_source = int(self.properties.current_source)
return self.instance.sources[current_source]
return self.client.sources[current_source]

@property
def properties(self) -> ZoneProperties:
return ZoneProperties.from_dict(self.instance.get_cache(self.device_str()))
return ZoneProperties.from_dict(self.client.get_cache(self.device_str()))

async def mute(self) -> str:
"""Mute the zone."""
Expand Down Expand Up @@ -434,17 +434,17 @@ async def select_source(self, source: int) -> str:
class Source:
"""Uniquely identifies a Source."""

def __init__(self, instance: RussoundClient, source_id: int, name: str) -> None:
def __init__(self, client: RussoundClient, source_id: int, name: str) -> None:
"""Initialize a Source."""
self.instance = instance
self.client = client
self.source_id = int(source_id)
self.name = name

async def fetch_configuration(self) -> None:
"""Fetch the current configuration of the source."""
for prop in SOURCE_PROPERTIES:
try:
await self.instance.get_variable(self.device_str(), prop)
await self.client.get_variable(self.device_str(), prop)
except CommandError:
continue

Expand Down Expand Up @@ -472,22 +472,22 @@ async def watch(self) -> str:
state changes (and those of the source they are currently connected to)
back to the client.
"""
return await self.instance.watch(self.device_str())
return await self.client.watch(self.device_str())

async def unwatch(self) -> str:
"""Remove a source from the watchlist."""
return await self.instance.unwatch(self.device_str())
return await self.client.unwatch(self.device_str())

async def send_event(self, event_name: str, *args: tuple[str, ...]) -> str:
"""Send an event to a source."""
cmd = (
f"EVENT {self.device_str()}!{event_name} %{" ".join(str(x) for x in args)}"
)
return await self.instance.connection_handler.send(cmd)
return await self.client.connection_handler.send(cmd)

def _get(self, variable: str) -> str:
return self.instance.get_cached_variable(self.device_str(), variable)
return self.client.get_cached_variable(self.device_str(), variable)

@property
def properties(self) -> SourceProperties:
return SourceProperties.from_dict(self.instance.get_cache(self.device_str()))
return SourceProperties.from_dict(self.client.get_cache(self.device_str()))

0 comments on commit 31dadb4

Please sign in to comment.