Skip to content

Commit

Permalink
feat: add config fetching for zone and source properties
Browse files Browse the repository at this point in the history
  • Loading branch information
noahhusby committed Jul 22, 2024
1 parent 7f6d3b5 commit 91d5855
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
13 changes: 12 additions & 1 deletion aiorussound/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ class FeatureFlag(Enum):

VERSIONS_BY_FLAGS = defaultdict(list)

ZONE_PROPERTIES = [
'volume', 'bass', 'treble', 'balance', 'loudness', 'turnOnVolume', 'doNotDisturb', 'partyMode', 'status', 'mute',
'sharedSource', 'lastError', 'page', 'sleepTimeDefault', 'sleepTimeRemaining', 'enabled'
]

SOURCE_PROPERTIES = [
'type', 'channel', 'coverArtURL', 'channelName', 'genre', 'artistName', 'albumName', 'playlistName', 'songName',
'programServiceName', 'radioText', 'shuffleMode', 'repeatMode', 'mode', 'playStatus', 'sampleRate', 'bitRate',
'bitDepth', 'playTime', 'trackTime'
]

for version, flags in FLAGS_BY_VERSION.items():
for flag in flags:
VERSIONS_BY_FLAGS[flag] = version
VERSIONS_BY_FLAGS[flag] = version
27 changes: 23 additions & 4 deletions aiorussound/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from asyncio import StreamWriter, StreamReader, AbstractEventLoop

from aiorussound.const import FeatureFlag, MINIMUM_API_SUPPORT, FLAGS_BY_VERSION, RESPONSE_REGEX, DEFAULT_PORT, \
RECONNECT_DELAY
RECONNECT_DELAY, ZONE_PROPERTIES, SOURCE_PROPERTIES
from aiorussound.exceptions import UncachedVariable, CommandException, UnsupportedRussoundVersion
from aiorussound.util import is_feature_supported, is_fw_version_higher, zone_device_str, source_device_str, \
controller_device_str
Expand Down Expand Up @@ -284,8 +284,8 @@ def __init__(self, instance: Russound, controller_id: int, mac_address: str, con
# TODO: Metadata fetching

async def fetch_configuration(self):
await self._init_zones()
await self._init_sources()
await self._init_zones()

def __str__(self):
return f"{self.controller_id}"
Expand All @@ -307,7 +307,10 @@ async def _init_zones(self):
device_str = zone_device_str(self.controller_id, zone_id)
name = await self.instance.get_variable(device_str, "name")
if name:
self.zones[zone_id] = Zone(self.instance, self, zone_id, name)
zone = Zone(self.instance, self, zone_id, name)
await zone.fetch_configuration()
self.zones[zone_id] = zone

except CommandException:
break

Expand All @@ -319,7 +322,9 @@ async def _init_sources(self):
device_str = source_device_str(source_id)
name = await self.instance.get_variable(device_str, "name")
if name:
self.sources[source_id] = Source(self.instance, self, source_id, name)
source = Source(self.instance, self, source_id, name)
await source.fetch_configuration()
self.sources[source_id] = source
except CommandException:
break

Expand All @@ -344,6 +349,13 @@ def __init__(self, instance: Russound, controller: Controller, zone_id: int, nam
self.zone_id = int(zone_id)
self.name = name

async def fetch_configuration(self):
for prop in ZONE_PROPERTIES:
try:
await self.instance.get_variable(self.device_str(), prop)
except CommandException:
continue

def __str__(self):
return f"{self.controller.mac_address} > Z{self.zone_id}"

Expand Down Expand Up @@ -477,6 +489,13 @@ def __init__(self, instance: Russound, controller: Controller, source_id: int, n
self.source_id = int(source_id)
self.name = name

async def fetch_configuration(self):
for prop in SOURCE_PROPERTIES:
try:
await self.instance.get_variable(self.device_str(), prop)
except CommandException:
continue

def __str__(self):
return f"{self.controller.mac_address} > S{self.source_id}"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='aiorussound',
version='2.0.4',
version='2.0.5',
packages=['aiorussound'],
license='MIT',
author='Noah Husby',
Expand Down

0 comments on commit 91d5855

Please sign in to comment.