diff --git a/denonavr/api.py b/denonavr/api.py index e21ba33..ed53b5a 100644 --- a/denonavr/api.py +++ b/denonavr/api.py @@ -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, @@ -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(): @@ -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) @@ -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: @@ -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 diff --git a/denonavr/const.py b/denonavr/const.py index 910f77e..311d4cf 100644 --- a/denonavr/const.py +++ b/denonavr/const.py @@ -113,7 +113,7 @@ "Spotify": "SPOTIFY", } -TELNET_SOURCES = [ +TELNET_SOURCES = { "CD", "PHONO", "TUNER", @@ -145,7 +145,7 @@ "USB/IPOD", "USB DIRECT", "IPOD DIRECT", -] +} TELNET_MAPPING = { "FAVORITES": "Favorites", @@ -414,6 +414,7 @@ ) # Telnet Events +ALL_TELNET_EVENTS = "ALL" TELNET_EVENTS = { "CV", "DC", @@ -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", @@ -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