Skip to content

Commit

Permalink
Define an All zone for telnet events which are relevant for all zon…
Browse files Browse the repository at this point in the history
…es (#259)
  • Loading branch information
ol-iver authored Jul 17, 2023
1 parent 6dbd37b commit a3d269c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
16 changes: 11 additions & 5 deletions denonavr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

from .appcommand import AppCommandCmd
from .const import (
ALL_TELNET_EVENTS,
ALL_ZONE_TELNET_EVENTS,
ALL_ZONES,
APPCOMMAND0300_URL,
APPCOMMAND_CMD_TEXT,
APPCOMMAND_NAME,
Expand Down Expand Up @@ -568,7 +571,7 @@ def register_callback(
) -> None:
"""Register a callback handler for an event type."""
# Validate the passed in type
if event != "ALL" and event not in TELNET_EVENTS:
if event != ALL_TELNET_EVENTS and event not in TELNET_EVENTS:
raise ValueError("{} is not a valid callback type.".format(event))

if event not in self._callbacks.keys():
Expand All @@ -589,7 +592,6 @@ def _process_event(self, message: str) -> None:
self._last_message_time = time.monotonic()
if len(message) < 3:
return
zone = MAIN_ZONE

# Event is 2 characters
event = self._get_event(message)
Expand All @@ -603,7 +605,11 @@ def _process_event(self, message: str) -> None:
if parameter[0:3] == "MAX":
return

if event in ("Z2", "Z3"):
# Determine zone
zone = MAIN_ZONE
if event in ALL_ZONE_TELNET_EVENTS:
zone = ALL_ZONES
elif event in {"Z2", "Z3"}:
if event == "Z2":
zone = ZONE2
else:
Expand Down Expand Up @@ -637,8 +643,8 @@ async def _async_run_callbacks(self, event: str, zone: str, parameter: str) -> N
err,
)

if "ALL" in self._callbacks.keys():
for callback in self._callbacks["ALL"]:
if ALL_TELNET_EVENTS in self._callbacks.keys():
for callback in self._callbacks[ALL_TELNET_EVENTS]:
try:
await callback(zone, event, parameter)
except Exception as err: # pylint: disable=broad-except
Expand Down
26 changes: 22 additions & 4 deletions denonavr/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"Spotify": "SPOTIFY",
}

TELNET_SOURCES = [
TELNET_SOURCES = {
"CD",
"PHONO",
"TUNER",
Expand Down Expand Up @@ -145,7 +145,7 @@
"USB/IPOD",
"USB DIRECT",
"IPOD DIRECT",
]
}

TELNET_MAPPING = {
"FAVORITES": "Favorites",
Expand Down Expand Up @@ -414,6 +414,7 @@
)

# Telnet Events
ALL_TELNET_EVENTS = "ALL"
TELNET_EVENTS = {
"CV",
"DC",
Expand Down Expand Up @@ -450,6 +451,22 @@
"Z2",
"Z3",
}
ALL_ZONE_TELNET_EVENTS = {
"DIM",
"HD",
"NS",
"NSA",
"NSE",
"MN",
"PW",
"RM",
"SY",
"TF",
"TM",
"TP",
"TR",
"UG",
}

DENONAVR_TELNET_COMMANDS = TelnetCommands(
command_sel_src="SI",
Expand Down Expand Up @@ -503,17 +520,18 @@
POWER_ON = "ON"
POWER_OFF = "OFF"
POWER_STANDBY = "STANDBY"
POWER_STATES = [POWER_ON, POWER_OFF, POWER_STANDBY]
POWER_STATES = {POWER_ON, POWER_OFF, POWER_STANDBY}
STATE_ON = "on"
STATE_OFF = "off"
STATE_PLAYING = "playing"
STATE_PAUSED = "paused"

# Zones
ALL_ZONES = "All"
MAIN_ZONE = "Main"
ZONE2 = "Zone2"
ZONE3 = "Zone3"
VALID_ZONES = [MAIN_ZONE, ZONE2, ZONE3]
VALID_ZONES = {MAIN_ZONE, ZONE2, ZONE3}

# Setup additional zones
NO_ZONES = None
Expand Down

0 comments on commit a3d269c

Please sign in to comment.