From 622d5af1dfe794e25d3c389b71d77c92bd99710b Mon Sep 17 00:00:00 2001 From: TB-1993 <109213741+TB-1993@users.noreply.github.com> Date: Thu, 1 May 2025 15:56:04 +0000 Subject: [PATCH 01/10] Fix #164 - Fixed bug in StreamLogger's readUntil method Changed the readUntil method to increment one last time after finding the search string to prevent the same line being searched twice on consecutive calls. --- framework/core/streamToFile.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/core/streamToFile.py b/framework/core/streamToFile.py index f0df434..0f1840f 100644 --- a/framework/core/streamToFile.py +++ b/framework/core/streamToFile.py @@ -21,8 +21,6 @@ def writeStreamToFile(self, inputStream: IOBase) -> None: Args: inputStream (IOBase): The input stream to be read from. - outFileName (str): The path of the output file where the stream data will be written. - If only a file name is given, the file will be written in the current tests log directory. """ self._fileHandle = open(self._filePath, 'a+', encoding='utf-8') self._stopThread = False @@ -84,10 +82,9 @@ def readUntil(self, searchString:str, retries: int = 5) -> None: if read_line == write_line: time.sleep(1) else: - while read_line < write_line: + while read_line < write_line and len(result) == 0: if searchString in out_lines[read_line]: result = out_lines[:read_line] - break read_line+=1 retry += 1 self._readLine = read_line From a9ae712b19cadf82df8b1271511fcfdb6ecf5286 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Wed, 18 Jun 2025 20:12:47 +0100 Subject: [PATCH 02/10] add audio amp controller and initial test --- framework/core/audioAmplifier/__init__.py | 0 framework/core/audioAmplifier/base.py | 23 ++++++++++ .../core/audioAmplifier/denon_controller.py | 44 +++++++++++++++++++ tests/audioAmp_test.py | 21 +++++++++ 4 files changed, 88 insertions(+) create mode 100644 framework/core/audioAmplifier/__init__.py create mode 100644 framework/core/audioAmplifier/base.py create mode 100644 framework/core/audioAmplifier/denon_controller.py create mode 100644 tests/audioAmp_test.py diff --git a/framework/core/audioAmplifier/__init__.py b/framework/core/audioAmplifier/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/framework/core/audioAmplifier/base.py b/framework/core/audioAmplifier/base.py new file mode 100644 index 0000000..fd60af7 --- /dev/null +++ b/framework/core/audioAmplifier/base.py @@ -0,0 +1,23 @@ +from abc import ABC, abstractmethod + +class AudioAmplifier(ABC): + @abstractmethod + async def power_on(self): pass + + @abstractmethod + async def power_off(self): pass + + @abstractmethod + async def set_volume(self, volume: float): pass + + @abstractmethod + async def mute(self, state: bool): pass + + @abstractmethod + async def set_input(self, input_name: str): pass + + @abstractmethod + async def update_state(self): pass + + @abstractmethod + def get_status(self) -> dict: pass diff --git a/framework/core/audioAmplifier/denon_controller.py b/framework/core/audioAmplifier/denon_controller.py new file mode 100644 index 0000000..49664cb --- /dev/null +++ b/framework/core/audioAmplifier/denon_controller.py @@ -0,0 +1,44 @@ +from denonavr import DenonAVR +from .base import AudioAmplifier + +class DenonAVRController(AudioAmplifier): + def __init__(self, host: str): + self.receiver = DenonAVR(host) + self._init = False + + async def _ensure_setup(self): + if not self._init: + await self.receiver.async_setup() + self._init = True + + async def power_on(self): + await self._ensure_setup() + await self.receiver.async_power_on() + + async def power_off(self): + await self._ensure_setup() + await self.receiver.async_power_off() + + async def set_volume(self, volume: float): + await self._ensure_setup() + await self.receiver.async_set_volume(volume) + + async def mute(self, state: bool): + await self._ensure_setup() + await self.receiver.async_mute(state) + + async def set_input(self, input_name: str): + await self._ensure_setup() + await self.receiver.async_set_input_func(input_name) + + async def update_state(self): + await self._ensure_setup() + await self.receiver.async_update() + + def get_status(self): + return { + "power": self.receiver.power, + "volume": self.receiver.volume, + "input": self.receiver.input_func, + "muted": self.receiver.muted, + } diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py new file mode 100644 index 0000000..869fef4 --- /dev/null +++ b/tests/audioAmp_test.py @@ -0,0 +1,21 @@ +import asyncio + +import os +import sys + +# Add the framework path to system +dir_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(dir_path+"/../") + +from framework.core.audioAmplifier.denon_controller import DenonAVRController + +async def main(): + controller = DenonAVRController("10.242.30.236") + await controller.update_state() # Fetch current state + status = controller.get_status() + print("Power:", status["power"]) + print("Volume:", status["volume"]) + print("Input:", status["input"]) + print("Muted:", status["muted"]) + +asyncio.run(main()) From fcef34bce72d1213c65f9f7c3e9a67d1ab379e96 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Wed, 25 Jun 2025 11:29:33 +0100 Subject: [PATCH 03/10] update denon_controller class, add docstrings and test --- framework/core/audioAmplifier/base.py | 109 ++++++++++++++++-- .../core/audioAmplifier/denon_controller.py | 64 +++++++--- tests/audioAmp_test.py | 86 ++++++++++++-- 3 files changed, 225 insertions(+), 34 deletions(-) diff --git a/framework/core/audioAmplifier/base.py b/framework/core/audioAmplifier/base.py index fd60af7..7295531 100644 --- a/framework/core/audioAmplifier/base.py +++ b/framework/core/audioAmplifier/base.py @@ -1,23 +1,118 @@ from abc import ABC, abstractmethod class AudioAmplifier(ABC): + """ + Abstract base class defining the interface for an audio amplifier controller. + + Implementations must provide async methods for controlling power, volume, + input source, mute state, sound mode, and retrieving status information. + """ + + @classmethod @abstractmethod - async def power_on(self): pass + async def create(cls, host: str): + """ + Async factory method to create and initialize an instance. + + :param host: IP address or hostname of the audio amplifier. + :return: An initialized instance of AudioAmplifier. + """ + pass @abstractmethod - async def power_off(self): pass + async def power_on(self): + """Power on the amplifier.""" + pass @abstractmethod - async def set_volume(self, volume: float): pass + async def power_off(self): + """Power off the amplifier.""" + pass @abstractmethod - async def mute(self, state: bool): pass + async def set_volume(self, volume: float): + """ + Set the amplifier volume. + + :param volume: Desired volume level. + """ + pass + + @abstractmethod + async def mute(self, state: bool): + """ + Mute or unmute the amplifier. + + :param state: True to mute, False to unmute. + """ + pass @abstractmethod - async def set_input(self, input_name: str): pass + async def get_available_inputs(self) -> list[str]: + """ + Get the list of available input sources supported by the amplifier. + """ + pass @abstractmethod - async def update_state(self): pass + async def get_available_sound_modes(self) -> list[str]: + """ + Get the list of available sound modes supported by the amplifier. + """ + pass + + @abstractmethod + async def set_input(self, input_name: str): + """ + Set the input source of the amplifier. + + :param input_name: Name of the input source (e.g., "TV", "CD"). + """ + pass + + @abstractmethod + async def set_sound_mode(self, input_name: str): + """ + Set the sound mode of the amplifier. + + :param input_name: Name of the sound mode (e.g., "TV", "CD"). + """ + pass @abstractmethod - def get_status(self) -> dict: pass + async def update_state(self): + """ + Refresh the internal state from the amplifier. + + Typically required before retrieving status properties. + """ + pass + + @abstractmethod + async def get_power(self) -> str: + """Get the current power state (e.g., "ON", "OFF").""" + pass + + @abstractmethod + async def get_volume(self) -> float: + """Get the current volume level.""" + pass + + @abstractmethod + async def get_input(self) -> str: + """Get the currently selected input source.""" + pass + + @abstractmethod + async def is_muted(self) -> bool: + """Check whether the amplifier is muted.""" + pass + + @abstractmethod + async def get_status(self) -> dict: + """ + Get a dictionary of key status information (power, volume, input, mute). + + :return: Dictionary of current amplifier state. + """ + pass diff --git a/framework/core/audioAmplifier/denon_controller.py b/framework/core/audioAmplifier/denon_controller.py index 49664cb..af03677 100644 --- a/framework/core/audioAmplifier/denon_controller.py +++ b/framework/core/audioAmplifier/denon_controller.py @@ -2,43 +2,71 @@ from .base import AudioAmplifier class DenonAVRController(AudioAmplifier): - def __init__(self, host: str): - self.receiver = DenonAVR(host) - self._init = False + def __init__(self, receiver: DenonAVR): + self.receiver = receiver - async def _ensure_setup(self): - if not self._init: - await self.receiver.async_setup() - self._init = True + @classmethod + async def create(cls, host: str): + receiver = DenonAVR(host) + await receiver.async_setup() + return cls(receiver) async def power_on(self): - await self._ensure_setup() await self.receiver.async_power_on() async def power_off(self): - await self._ensure_setup() await self.receiver.async_power_off() async def set_volume(self, volume: float): - await self._ensure_setup() await self.receiver.async_set_volume(volume) async def mute(self, state: bool): - await self._ensure_setup() await self.receiver.async_mute(state) + async def get_available_inputs(self) -> list[str]: + await self.update_state() + return self.receiver.input_func_list + + async def get_available_sound_modes(self) -> list[str]: + await self.update_state() + return self.receiver.sound_mode_list + async def set_input(self, input_name: str): - await self._ensure_setup() + available = await self.get_available_inputs() + if input_name not in available: + raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") await self.receiver.async_set_input_func(input_name) + async def set_sound_mode(self, mode: str): + available = await self.get_available_sound_modes() + if mode not in available: + raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") + await self.receiver.async_set_sound_mode(mode) + async def update_state(self): - await self._ensure_setup() await self.receiver.async_update() - def get_status(self): + async def get_power(self) -> str: + return self.receiver.power + + async def get_volume(self) -> float: + return self.receiver.volume + + async def is_muted(self) -> bool: + return self.receiver.muted + + async def get_input(self) -> str: + return self.receiver.input_func + + async def get_sound_mode(self) -> str: + return self.receiver.sound_mode + + + async def get_status(self): return { - "power": self.receiver.power, - "volume": self.receiver.volume, - "input": self.receiver.input_func, - "muted": self.receiver.muted, + "power": self.get_power(), + "volume": self.get_volume(), + "muted": self.is_muted(), + "input": self.get_input(), + "sound_mode": self.get_sound_mode(), } diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index 869fef4..438c115 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -10,12 +10,80 @@ from framework.core.audioAmplifier.denon_controller import DenonAVRController async def main(): - controller = DenonAVRController("10.242.30.236") - await controller.update_state() # Fetch current state - status = controller.get_status() - print("Power:", status["power"]) - print("Volume:", status["volume"]) - print("Input:", status["input"]) - print("Muted:", status["muted"]) - -asyncio.run(main()) + controller = await DenonAVRController.create("10.242.30.236") + + # Power ON test + try: + await controller.power_on() + await controller.update_state() + power = await controller.get_power() + assert power == "ON" + print("PASSED: Power ON") + except: + print("FAILED: Power ON") + + # Volume test + try: + volume = -40 + await controller.set_volume(volume) + await controller.update_state() + updated_volume = await controller.get_volume() + assert updated_volume == volume + print("PASSED: Volume change") + except: + print(f"FAILED: Volume change. Expected: {volume}, actual {updated_volume}") + + # Mute test + try: + await controller.mute(True) + await controller.update_state() + muted = await controller.is_muted() + assert muted is True + print("PASSED: Mute") + except: + print("FAILED: Mute") + + try: + await controller.mute(False) + await controller.update_state() + muted = await controller.is_muted() + assert muted is False + print("PASSED: Unmute") + except: + print("FAILED: Unmute") + + # Input test + try: + print("Available inputs:", await controller.get_available_inputs()) + input = "Game" + await controller.set_input(input) + await controller.update_state() + updated_input = await controller.get_input() + assert updated_input == input + print("PASSED: Input source set correctly.") + except: + print(f"FAILED: Input source not set correctly. Expected: {input}, actual: {updated_input}") + + # Sound Mode test + try: + print("Available sound modes:", await controller.get_available_sound_modes()) + sound_mode = "MUSIC" + await controller.set_sound_mode(sound_mode) + await controller.update_state() + updated_sound_mode = await controller.get_sound_mode() + assert updated_sound_mode == sound_mode + print("PASSED: Sound mode set correctly") + except: + print(f"FAILED: Sound mode not set correctly. Expected: {sound_mode}, actual: {updated_sound_mode}") + + # Power OFF test + try: + await controller.power_off() + await controller.update_state() + power = await controller.get_power() + assert power.upper() == "OFF" + print("PASSED: Power OFF") + except: + print("FAILED: Power OFF") + +asyncio.run(main()) \ No newline at end of file From c6bdbc62204e87a0aa40e33e66eec928d7bdb61c Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Mon, 7 Jul 2025 12:18:32 +0100 Subject: [PATCH 04/10] add core/denon_controller with logging, fix docstring and __init__ inside controller --- framework/core/audioAmplifier/base.py | 10 +- .../core/audioAmplifier/denon_controller.py | 66 +++++----- framework/core/denon_controller.py | 120 ++++++++++++++++++ tests/audioAmp_test.py | 62 +++++---- 4 files changed, 186 insertions(+), 72 deletions(-) create mode 100644 framework/core/denon_controller.py diff --git a/framework/core/audioAmplifier/base.py b/framework/core/audioAmplifier/base.py index 7295531..3ba1e2a 100644 --- a/framework/core/audioAmplifier/base.py +++ b/framework/core/audioAmplifier/base.py @@ -4,18 +4,16 @@ class AudioAmplifier(ABC): """ Abstract base class defining the interface for an audio amplifier controller. - Implementations must provide async methods for controlling power, volume, + Implementations must provide methods for controlling power, volume, input source, mute state, sound mode, and retrieving status information. """ @classmethod @abstractmethod - async def create(cls, host: str): + async def setup(self): """ - Async factory method to create and initialize an instance. - - :param host: IP address or hostname of the audio amplifier. - :return: An initialized instance of AudioAmplifier. + Async setup method to initialize the amplifier connection. + Called once after construction. """ pass diff --git a/framework/core/audioAmplifier/denon_controller.py b/framework/core/audioAmplifier/denon_controller.py index af03677..bc1a95e 100644 --- a/framework/core/audioAmplifier/denon_controller.py +++ b/framework/core/audioAmplifier/denon_controller.py @@ -1,68 +1,66 @@ +import asyncio from denonavr import DenonAVR from .base import AudioAmplifier class DenonAVRController(AudioAmplifier): - def __init__(self, receiver: DenonAVR): - self.receiver = receiver + + def __init__(self, host: str): + self.receiver = DenonAVR(host) - @classmethod - async def create(cls, host: str): - receiver = DenonAVR(host) - await receiver.async_setup() - return cls(receiver) + def setup(self): + asyncio.run(self.receiver.async_setup()) - async def power_on(self): - await self.receiver.async_power_on() + def power_on(self): + asyncio.run(self.receiver.async_power_on()) - async def power_off(self): - await self.receiver.async_power_off() + def power_off(self): + asyncio.run(self.receiver.async_power_off()) - async def set_volume(self, volume: float): - await self.receiver.async_set_volume(volume) + def set_volume(self, volume: float): + asyncio.run(self.receiver.async_set_volume(volume)) - async def mute(self, state: bool): - await self.receiver.async_mute(state) + def mute(self, state: bool): + asyncio.run(self.receiver.async_mute(state)) - async def get_available_inputs(self) -> list[str]: - await self.update_state() + def get_available_inputs(self) -> list[str]: + self.update_state() return self.receiver.input_func_list - async def get_available_sound_modes(self) -> list[str]: - await self.update_state() + def get_available_sound_modes(self) -> list[str]: + self.update_state() return self.receiver.sound_mode_list - async def set_input(self, input_name: str): - available = await self.get_available_inputs() + def set_input(self, input_name: str): + available = self.get_available_inputs() if input_name not in available: raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") - await self.receiver.async_set_input_func(input_name) + asyncio.run(self.receiver.async_set_input_func(input_name)) - async def set_sound_mode(self, mode: str): - available = await self.get_available_sound_modes() + def set_sound_mode(self, mode: str): + available = self.get_available_sound_modes() if mode not in available: raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") - await self.receiver.async_set_sound_mode(mode) + asyncio.run(self.receiver.async_set_sound_mode(mode)) - async def update_state(self): - await self.receiver.async_update() + def update_state(self): + asyncio.run(self.receiver.async_update()) - async def get_power(self) -> str: + def get_power(self) -> str: return self.receiver.power - async def get_volume(self) -> float: + def get_volume(self) -> float: return self.receiver.volume - async def is_muted(self) -> bool: + def is_muted(self) -> bool: return self.receiver.muted - async def get_input(self) -> str: + def get_input(self) -> str: return self.receiver.input_func - async def get_sound_mode(self) -> str: + def get_sound_mode(self) -> str: return self.receiver.sound_mode - - async def get_status(self): + def get_status(self): return { "power": self.get_power(), "volume": self.get_volume(), diff --git a/framework/core/denon_controller.py b/framework/core/denon_controller.py new file mode 100644 index 0000000..bd8f780 --- /dev/null +++ b/framework/core/denon_controller.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +#** ***************************************************************************** +# * +# * If not stated otherwise in this file or this component's LICENSE file the +# * following copyright and licenses apply: +# * +# * Copyright 2023 RDK Management +# * +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * +# http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * +#* ****************************************************************************** +#* +#* ** Project : RAFT +#* ** @addtogroup : core +#* ** @date : 01/07/2025 +#* ** +#* ** @brief : audio amplifier controller +#* ** +#* ****************************************************************************** + +import asyncio +from denonavr import DenonAVR + +from framework.core.logModule import logModule +from framework.core.audioAmplifier.base import AudioAmplifier + +class DenonAVRController(AudioAmplifier): + + def __init__(self, host: str): + self.receiver = DenonAVR(host) + self._log = logModule("DenonAVRController") + + def setup(self): + self._log.info("Setting up receiver") + asyncio.run(self.receiver.async_setup()) + + def power_on(self): + self._log.info("Powering ON receiver") + asyncio.run(self.receiver.async_power_on()) + + def power_off(self): + self._log.info("Powering OFF receiver") + asyncio.run(self.receiver.async_power_off()) + + def set_volume(self, volume: float): + self._log.info("Setting receiver volume") + asyncio.run(self.receiver.async_set_volume(volume)) + + def mute(self, state: bool): + self._log.info("Muting receiver") + asyncio.run(self.receiver.async_mute(state)) + + def get_available_inputs(self) -> list[str]: + self._log.info("Getting receiver available inputs") + self.update_state() + return self.receiver.input_func_list + + def get_available_sound_modes(self) -> list[str]: + self._log.info("Getting receiver available sound modes") + self.update_state() + return self.receiver.sound_mode_list + + def set_input(self, input_name: str): + self._log.info("Setting receiver input") + available = self.get_available_inputs() + if input_name not in available: + raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") + asyncio.run(self.receiver.async_set_input_func(input_name)) + + def set_sound_mode(self, mode: str): + self._log.info("Setting receiver sound mode") + available = self.get_available_sound_modes() + if mode not in available: + raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") + asyncio.run(self.receiver.async_set_sound_mode(mode)) + + def update_state(self): + self._log.info("Updating receiver state") + asyncio.run(self.receiver.async_update()) + + def get_power(self) -> str: + self._log.info("Getting receiver power") + return self.receiver.power + + def get_volume(self) -> float: + self._log.info("Getting receiver volume") + return self.receiver.volume + + def is_muted(self) -> bool: + self._log.info("Getting receiver mute state") + return self.receiver.muted + + def get_input(self) -> str: + self._log.info("Getting receiver input") + return self.receiver.input_func + + def get_sound_mode(self) -> str: + self._log.info("Getting receiver sound mode") + return self.receiver.sound_mode + + def get_status(self): + self._log.info("Getting receiver status") + return { + "power": self.get_power(), + "volume": self.get_volume(), + "muted": self.is_muted(), + "input": self.get_input(), + "sound_mode": self.get_sound_mode(), + } diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index 438c115..fe7048d 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -1,5 +1,4 @@ import asyncio - import os import sys @@ -7,16 +6,17 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path+"/../") -from framework.core.audioAmplifier.denon_controller import DenonAVRController +from framework.core.denon_controller import DenonAVRController -async def main(): - controller = await DenonAVRController.create("10.242.30.236") +if __name__ == "__main__": + controller = DenonAVRController("10.242.30.236") + controller.setup() # Power ON test try: - await controller.power_on() - await controller.update_state() - power = await controller.get_power() + controller.power_on() + controller.update_state() + power = controller.get_power() assert power == "ON" print("PASSED: Power ON") except: @@ -24,10 +24,10 @@ async def main(): # Volume test try: - volume = -40 - await controller.set_volume(volume) - await controller.update_state() - updated_volume = await controller.get_volume() + volume = -45 + controller.set_volume(volume) + controller.update_state() + updated_volume = controller.get_volume() assert updated_volume == volume print("PASSED: Volume change") except: @@ -35,18 +35,18 @@ async def main(): # Mute test try: - await controller.mute(True) - await controller.update_state() - muted = await controller.is_muted() + controller.mute(True) + controller.update_state() + muted = controller.is_muted() assert muted is True print("PASSED: Mute") except: print("FAILED: Mute") try: - await controller.mute(False) - await controller.update_state() - muted = await controller.is_muted() + controller.mute(False) + controller.update_state() + muted = controller.is_muted() assert muted is False print("PASSED: Unmute") except: @@ -54,11 +54,11 @@ async def main(): # Input test try: - print("Available inputs:", await controller.get_available_inputs()) - input = "Game" - await controller.set_input(input) - await controller.update_state() - updated_input = await controller.get_input() + print("Available inputs:", controller.get_available_inputs()) + input = "AUX2" + controller.set_input(input) + controller.update_state() + updated_input = controller.get_input() assert updated_input == input print("PASSED: Input source set correctly.") except: @@ -66,11 +66,11 @@ async def main(): # Sound Mode test try: - print("Available sound modes:", await controller.get_available_sound_modes()) - sound_mode = "MUSIC" - await controller.set_sound_mode(sound_mode) - await controller.update_state() - updated_sound_mode = await controller.get_sound_mode() + print("Available sound modes:", controller.get_available_sound_modes()) + sound_mode = "MOVIE" + controller.set_sound_mode(sound_mode) + controller.update_state() + updated_sound_mode = controller.get_sound_mode() assert updated_sound_mode == sound_mode print("PASSED: Sound mode set correctly") except: @@ -78,12 +78,10 @@ async def main(): # Power OFF test try: - await controller.power_off() - await controller.update_state() - power = await controller.get_power() + controller.power_off() + controller.update_state() + power = controller.get_power() assert power.upper() == "OFF" print("PASSED: Power OFF") except: print("FAILED: Power OFF") - -asyncio.run(main()) \ No newline at end of file From de55e8c681044407dd4ce4d19bd3b67a331743a1 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Mon, 14 Jul 2025 09:29:31 +0100 Subject: [PATCH 05/10] add config to test audio amplifier and clean up test --- ...troller.py => audioAmplifierController.py} | 71 ++++---- tests/audioAmp_test.py | 157 ++++++++++-------- 2 files changed, 123 insertions(+), 105 deletions(-) rename framework/core/{denon_controller.py => audioAmplifierController.py} (56%) diff --git a/framework/core/denon_controller.py b/framework/core/audioAmplifierController.py similarity index 56% rename from framework/core/denon_controller.py rename to framework/core/audioAmplifierController.py index bd8f780..81b7c31 100644 --- a/framework/core/denon_controller.py +++ b/framework/core/audioAmplifierController.py @@ -35,82 +35,85 @@ from framework.core.logModule import logModule from framework.core.audioAmplifier.base import AudioAmplifier -class DenonAVRController(AudioAmplifier): +class audioAmplifierController(AudioAmplifier): - def __init__(self, host: str): - self.receiver = DenonAVR(host) + def __init__(self, config:dict): self._log = logModule("DenonAVRController") + self.controllerType = config.get("type") + self.host = config.get("host") + + self.audioAmplifier = DenonAVR(self.host) def setup(self): - self._log.info("Setting up receiver") - asyncio.run(self.receiver.async_setup()) + self._log.info("Setting up audio amplifier") + asyncio.run(self.audioAmplifier.async_setup()) def power_on(self): - self._log.info("Powering ON receiver") - asyncio.run(self.receiver.async_power_on()) + self._log.info("Powering ON audio amplifier") + asyncio.run(self.audioAmplifier.async_power_on()) def power_off(self): - self._log.info("Powering OFF receiver") - asyncio.run(self.receiver.async_power_off()) + self._log.info("Powering OFF audio amplifier") + asyncio.run(self.audioAmplifier.async_power_off()) def set_volume(self, volume: float): - self._log.info("Setting receiver volume") - asyncio.run(self.receiver.async_set_volume(volume)) + self._log.info("Setting audio amplifier volume") + asyncio.run(self.audioAmplifier.async_set_volume(volume)) def mute(self, state: bool): - self._log.info("Muting receiver") - asyncio.run(self.receiver.async_mute(state)) + self._log.info("Muting audio amplifier") + asyncio.run(self.audioAmplifier.async_mute(state)) def get_available_inputs(self) -> list[str]: - self._log.info("Getting receiver available inputs") + self._log.info("Getting audio amplifier available inputs") self.update_state() - return self.receiver.input_func_list + return self.audioAmplifier.input_func_list def get_available_sound_modes(self) -> list[str]: - self._log.info("Getting receiver available sound modes") + self._log.info("Getting audio amplifier available sound modes") self.update_state() - return self.receiver.sound_mode_list + return self.audioAmplifier.sound_mode_list def set_input(self, input_name: str): - self._log.info("Setting receiver input") + self._log.info("Setting audio amplifier input") available = self.get_available_inputs() if input_name not in available: raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") - asyncio.run(self.receiver.async_set_input_func(input_name)) + asyncio.run(self.audioAmplifier.async_set_input_func(input_name)) def set_sound_mode(self, mode: str): - self._log.info("Setting receiver sound mode") + self._log.info("Setting audio amplifier sound mode") available = self.get_available_sound_modes() if mode not in available: raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") - asyncio.run(self.receiver.async_set_sound_mode(mode)) + asyncio.run(self.audioAmplifier.async_set_sound_mode(mode)) def update_state(self): - self._log.info("Updating receiver state") - asyncio.run(self.receiver.async_update()) + self._log.info("Updating audio amplifier state") + asyncio.run(self.audioAmplifier.async_update()) def get_power(self) -> str: - self._log.info("Getting receiver power") - return self.receiver.power + self._log.info("Getting audio amplifier power") + return self.audioAmplifier.power def get_volume(self) -> float: - self._log.info("Getting receiver volume") - return self.receiver.volume + self._log.info("Getting audio amplifier volume") + return self.audioAmplifier.volume def is_muted(self) -> bool: - self._log.info("Getting receiver mute state") - return self.receiver.muted + self._log.info("Getting audio amplifier mute state") + return self.audioAmplifier.muted def get_input(self) -> str: - self._log.info("Getting receiver input") - return self.receiver.input_func + self._log.info("Getting audio amplifier input") + return self.audioAmplifier.input_func def get_sound_mode(self) -> str: - self._log.info("Getting receiver sound mode") - return self.receiver.sound_mode + self._log.info("Getting audio amplifier sound mode") + return self.audioAmplifier.sound_mode def get_status(self): - self._log.info("Getting receiver status") + self._log.info("Getting audio amplifier status") return { "power": self.get_power(), "volume": self.get_volume(), diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index fe7048d..3b4ef7c 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -1,87 +1,102 @@ -import asyncio + import os import sys +import json # Add the framework path to system dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path+"/../") -from framework.core.denon_controller import DenonAVRController +from framework.core.logModule import logModule +from framework.core.audioAmplifierController import audioAmplifierController if __name__ == "__main__": - controller = DenonAVRController("10.242.30.236") - controller.setup() - # Power ON test - try: - controller.power_on() - controller.update_state() - power = controller.get_power() - assert power == "ON" - print("PASSED: Power ON") - except: - print("FAILED: Power ON") + LOG = logModule("audio amplifier test", logModule.DEBUG) + CONFIGS = [ + { + 'type': 'denon_controller', + 'host': '10.242.30.236' + }] + + for config in CONFIGS: + + LOG.setFilename(os.path.abspath('./logs/'),'audioAmplifier-%sTest.log' % config.get('type')) + LOG.stepStart('Testing with %s' % json.dumps(config)) + + controller = audioAmplifierController(config) + controller.setup() + + # Power ON test + try: + controller.power_on() + controller.update_state() + power = controller.get_power() + assert power == "ON" + print("PASSED: Power ON") + except: + print("FAILED: Power ON") - # Volume test - try: - volume = -45 - controller.set_volume(volume) - controller.update_state() - updated_volume = controller.get_volume() - assert updated_volume == volume - print("PASSED: Volume change") - except: - print(f"FAILED: Volume change. Expected: {volume}, actual {updated_volume}") + # Volume test + try: + volume = -45 + controller.set_volume(volume) + controller.update_state() + updated_volume = controller.get_volume() + assert updated_volume == volume + print("PASSED: Volume change") + except: + print(f"FAILED: Volume change. Expected: {volume}, actual {updated_volume}") - # Mute test - try: - controller.mute(True) - controller.update_state() - muted = controller.is_muted() - assert muted is True - print("PASSED: Mute") - except: - print("FAILED: Mute") + # Mute test + try: + controller.mute(True) + controller.update_state() + muted = controller.is_muted() + assert muted is True + print("PASSED: Mute") + except: + print("FAILED: Mute") - try: - controller.mute(False) - controller.update_state() - muted = controller.is_muted() - assert muted is False - print("PASSED: Unmute") - except: - print("FAILED: Unmute") + try: + controller.mute(False) + controller.update_state() + muted = controller.is_muted() + assert muted is False + print("PASSED: Unmute") + except: + print("FAILED: Unmute") - # Input test - try: - print("Available inputs:", controller.get_available_inputs()) - input = "AUX2" - controller.set_input(input) - controller.update_state() - updated_input = controller.get_input() - assert updated_input == input - print("PASSED: Input source set correctly.") - except: - print(f"FAILED: Input source not set correctly. Expected: {input}, actual: {updated_input}") + # Input test + try: + print("Available inputs:", controller.get_available_inputs()) + input = "AUX2" + controller.set_input(input) + controller.update_state() + updated_input = controller.get_input() + assert updated_input == input + print("PASSED: Input source set correctly.") + except: + print(f"FAILED: Input source not set correctly. Expected: {input}, actual: {updated_input}") - # Sound Mode test - try: - print("Available sound modes:", controller.get_available_sound_modes()) - sound_mode = "MOVIE" - controller.set_sound_mode(sound_mode) - controller.update_state() - updated_sound_mode = controller.get_sound_mode() - assert updated_sound_mode == sound_mode - print("PASSED: Sound mode set correctly") - except: - print(f"FAILED: Sound mode not set correctly. Expected: {sound_mode}, actual: {updated_sound_mode}") + # Sound Mode test + try: + print("Available sound modes:", controller.get_available_sound_modes()) + sound_mode = "MOVIE" + controller.set_sound_mode(sound_mode) + controller.update_state() + updated_sound_mode = controller.get_sound_mode() + assert updated_sound_mode == sound_mode + print("PASSED: Sound mode set correctly") + except: + print(f"FAILED: Sound mode not set correctly. Expected: {sound_mode}, actual: {updated_sound_mode}") - # Power OFF test - try: - controller.power_off() - controller.update_state() - power = controller.get_power() - assert power.upper() == "OFF" - print("PASSED: Power OFF") - except: - print("FAILED: Power OFF") + # Power OFF test + try: + controller.power_off() + controller.update_state() + power = controller.get_power() + assert power.upper() == "OFF" + print("PASSED: Power OFF") + except: + print("FAILED: Power OFF") From d62adb2df7fa8aeb4024ee29662874822a157a76 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Mon, 14 Jul 2025 12:08:20 +0100 Subject: [PATCH 06/10] refactor amplifier controller --- framework/core/audioAmplifierController.py | 56 ++++++++-------------- tests/audioAmp_test.py | 3 +- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/framework/core/audioAmplifierController.py b/framework/core/audioAmplifierController.py index 81b7c31..9834626 100644 --- a/framework/core/audioAmplifierController.py +++ b/framework/core/audioAmplifierController.py @@ -29,11 +29,9 @@ #* ** #* ****************************************************************************** -import asyncio -from denonavr import DenonAVR - from framework.core.logModule import logModule from framework.core.audioAmplifier.base import AudioAmplifier +from framework.core.audioAmplifier.denon_controller import DenonAVRController class audioAmplifierController(AudioAmplifier): @@ -42,82 +40,70 @@ def __init__(self, config:dict): self.controllerType = config.get("type") self.host = config.get("host") - self.audioAmplifier = DenonAVR(self.host) + if self.controllerType == "denon": + self.audioAmplifier = DenonAVRController(self.host) + + self.audioAmplifier.setup() def setup(self): self._log.info("Setting up audio amplifier") - asyncio.run(self.audioAmplifier.async_setup()) + self.audioAmplifier.setup() def power_on(self): self._log.info("Powering ON audio amplifier") - asyncio.run(self.audioAmplifier.async_power_on()) + self.audioAmplifier.power_on() def power_off(self): self._log.info("Powering OFF audio amplifier") - asyncio.run(self.audioAmplifier.async_power_off()) + self.audioAmplifier.power_off() def set_volume(self, volume: float): self._log.info("Setting audio amplifier volume") - asyncio.run(self.audioAmplifier.async_set_volume(volume)) + self.audioAmplifier.set_volume(volume) def mute(self, state: bool): self._log.info("Muting audio amplifier") - asyncio.run(self.audioAmplifier.async_mute(state)) + self.audioAmplifier.mute(state) def get_available_inputs(self) -> list[str]: self._log.info("Getting audio amplifier available inputs") - self.update_state() - return self.audioAmplifier.input_func_list + self.audioAmplifier.get_available_inputs() def get_available_sound_modes(self) -> list[str]: self._log.info("Getting audio amplifier available sound modes") - self.update_state() - return self.audioAmplifier.sound_mode_list + self.audioAmplifier.get_available_sound_modes() def set_input(self, input_name: str): self._log.info("Setting audio amplifier input") - available = self.get_available_inputs() - if input_name not in available: - raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") - asyncio.run(self.audioAmplifier.async_set_input_func(input_name)) + self.audioAmplifier.set_input(input_name) def set_sound_mode(self, mode: str): - self._log.info("Setting audio amplifier sound mode") - available = self.get_available_sound_modes() - if mode not in available: - raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") - asyncio.run(self.audioAmplifier.async_set_sound_mode(mode)) + self.audioAmplifier.set_sound_mode(mode) def update_state(self): self._log.info("Updating audio amplifier state") - asyncio.run(self.audioAmplifier.async_update()) + self.audioAmplifier.update_state() def get_power(self) -> str: self._log.info("Getting audio amplifier power") - return self.audioAmplifier.power + self.audioAmplifier.get_power() def get_volume(self) -> float: self._log.info("Getting audio amplifier volume") - return self.audioAmplifier.volume + self.audioAmplifier.get_volume() def is_muted(self) -> bool: self._log.info("Getting audio amplifier mute state") - return self.audioAmplifier.muted + self.audioAmplifier.is_muted() def get_input(self) -> str: self._log.info("Getting audio amplifier input") - return self.audioAmplifier.input_func + self.audioAmplifier.get_input() def get_sound_mode(self) -> str: self._log.info("Getting audio amplifier sound mode") - return self.audioAmplifier.sound_mode + self.audioAmplifier.get_sound_mode() def get_status(self): self._log.info("Getting audio amplifier status") - return { - "power": self.get_power(), - "volume": self.get_volume(), - "muted": self.is_muted(), - "input": self.get_input(), - "sound_mode": self.get_sound_mode(), - } + self.audioAmplifier.get_status() diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index 3b4ef7c..c27423a 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -15,7 +15,7 @@ LOG = logModule("audio amplifier test", logModule.DEBUG) CONFIGS = [ { - 'type': 'denon_controller', + 'type': 'denon', 'host': '10.242.30.236' }] @@ -25,7 +25,6 @@ LOG.stepStart('Testing with %s' % json.dumps(config)) controller = audioAmplifierController(config) - controller.setup() # Power ON test try: From 6f8cb799b5c3ac41113f1807b45d06187e07ed2c Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Mon, 14 Jul 2025 17:46:08 +0100 Subject: [PATCH 07/10] rename methods and remove denon specific ones from controller --- framework/core/audioAmplifier/base.py | 4 +- .../core/audioAmplifier/denon_controller.py | 15 ++++++-- framework/core/audioAmplifierController.py | 38 +++++++------------ tests/audioAmp_test.py | 13 ++----- 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/framework/core/audioAmplifier/base.py b/framework/core/audioAmplifier/base.py index 3ba1e2a..6fca907 100644 --- a/framework/core/audioAmplifier/base.py +++ b/framework/core/audioAmplifier/base.py @@ -46,14 +46,14 @@ async def mute(self, state: bool): pass @abstractmethod - async def get_available_inputs(self) -> list[str]: + async def list_inputs(self) -> list[str]: """ Get the list of available input sources supported by the amplifier. """ pass @abstractmethod - async def get_available_sound_modes(self) -> list[str]: + async def list_sound_modes(self) -> list[str]: """ Get the list of available sound modes supported by the amplifier. """ diff --git a/framework/core/audioAmplifier/denon_controller.py b/framework/core/audioAmplifier/denon_controller.py index bc1a95e..d30775a 100644 --- a/framework/core/audioAmplifier/denon_controller.py +++ b/framework/core/audioAmplifier/denon_controller.py @@ -12,35 +12,42 @@ def setup(self): def power_on(self): asyncio.run(self.receiver.async_power_on()) + self.update_state() def power_off(self): asyncio.run(self.receiver.async_power_off()) + self.update_state() + def set_volume(self, volume: float): asyncio.run(self.receiver.async_set_volume(volume)) + self.update_state() def mute(self, state: bool): asyncio.run(self.receiver.async_mute(state)) + self.update_state() - def get_available_inputs(self) -> list[str]: + def list_inputs(self) -> list[str]: self.update_state() return self.receiver.input_func_list - def get_available_sound_modes(self) -> list[str]: + def list_sound_modes(self) -> list[str]: self.update_state() return self.receiver.sound_mode_list def set_input(self, input_name: str): - available = self.get_available_inputs() + available = self.list_inputs() if input_name not in available: raise ValueError(f"Invalid input: {input_name}. Available inputs: {available}") asyncio.run(self.receiver.async_set_input_func(input_name)) + self.update_state() def set_sound_mode(self, mode: str): - available = self.get_available_sound_modes() + available = self.list_sound_modes() if mode not in available: raise ValueError(f"Invalid sound mode: {mode}. Available modes: {available}") asyncio.run(self.receiver.async_set_sound_mode(mode)) + self.update_state() def update_state(self): asyncio.run(self.receiver.async_update()) diff --git a/framework/core/audioAmplifierController.py b/framework/core/audioAmplifierController.py index 9834626..d10dd49 100644 --- a/framework/core/audioAmplifierController.py +++ b/framework/core/audioAmplifierController.py @@ -30,10 +30,9 @@ #* ****************************************************************************** from framework.core.logModule import logModule -from framework.core.audioAmplifier.base import AudioAmplifier from framework.core.audioAmplifier.denon_controller import DenonAVRController -class audioAmplifierController(AudioAmplifier): +class audioAmplifierController(): def __init__(self, config:dict): self._log = logModule("DenonAVRController") @@ -42,12 +41,7 @@ def __init__(self, config:dict): if self.controllerType == "denon": self.audioAmplifier = DenonAVRController(self.host) - - self.audioAmplifier.setup() - - def setup(self): - self._log.info("Setting up audio amplifier") - self.audioAmplifier.setup() + self.audioAmplifier.setup() def power_on(self): self._log.info("Powering ON audio amplifier") @@ -65,13 +59,13 @@ def mute(self, state: bool): self._log.info("Muting audio amplifier") self.audioAmplifier.mute(state) - def get_available_inputs(self) -> list[str]: - self._log.info("Getting audio amplifier available inputs") - self.audioAmplifier.get_available_inputs() + def list_inputs(self) -> list[str]: + self._log.info("Listing the audio amplifier available inputs") + return self.audioAmplifier.list_inputs() - def get_available_sound_modes(self) -> list[str]: - self._log.info("Getting audio amplifier available sound modes") - self.audioAmplifier.get_available_sound_modes() + def list_sound_modes(self) -> list[str]: + self._log.info("Listing the audio amplifier available sound modes") + return self.audioAmplifier.list_sound_modes() def set_input(self, input_name: str): self._log.info("Setting audio amplifier input") @@ -80,30 +74,26 @@ def set_input(self, input_name: str): def set_sound_mode(self, mode: str): self.audioAmplifier.set_sound_mode(mode) - def update_state(self): - self._log.info("Updating audio amplifier state") - self.audioAmplifier.update_state() - def get_power(self) -> str: self._log.info("Getting audio amplifier power") - self.audioAmplifier.get_power() + return self.audioAmplifier.get_power() def get_volume(self) -> float: self._log.info("Getting audio amplifier volume") - self.audioAmplifier.get_volume() + return self.audioAmplifier.get_volume() def is_muted(self) -> bool: self._log.info("Getting audio amplifier mute state") - self.audioAmplifier.is_muted() + return self.audioAmplifier.is_muted() def get_input(self) -> str: self._log.info("Getting audio amplifier input") - self.audioAmplifier.get_input() + return self.audioAmplifier.get_input() def get_sound_mode(self) -> str: self._log.info("Getting audio amplifier sound mode") - self.audioAmplifier.get_sound_mode() + return self.audioAmplifier.get_sound_mode() def get_status(self): self._log.info("Getting audio amplifier status") - self.audioAmplifier.get_status() + return self.audioAmplifier.get_status() diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index c27423a..79f0df2 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -29,7 +29,6 @@ # Power ON test try: controller.power_on() - controller.update_state() power = controller.get_power() assert power == "ON" print("PASSED: Power ON") @@ -38,9 +37,8 @@ # Volume test try: - volume = -45 + volume = -51 controller.set_volume(volume) - controller.update_state() updated_volume = controller.get_volume() assert updated_volume == volume print("PASSED: Volume change") @@ -50,7 +48,6 @@ # Mute test try: controller.mute(True) - controller.update_state() muted = controller.is_muted() assert muted is True print("PASSED: Mute") @@ -59,7 +56,6 @@ try: controller.mute(False) - controller.update_state() muted = controller.is_muted() assert muted is False print("PASSED: Unmute") @@ -68,10 +64,9 @@ # Input test try: - print("Available inputs:", controller.get_available_inputs()) + print("Available inputs:", controller.list_inputs()) input = "AUX2" controller.set_input(input) - controller.update_state() updated_input = controller.get_input() assert updated_input == input print("PASSED: Input source set correctly.") @@ -80,10 +75,9 @@ # Sound Mode test try: - print("Available sound modes:", controller.get_available_sound_modes()) + print("Available sound modes:", controller.list_sound_modes()) sound_mode = "MOVIE" controller.set_sound_mode(sound_mode) - controller.update_state() updated_sound_mode = controller.get_sound_mode() assert updated_sound_mode == sound_mode print("PASSED: Sound mode set correctly") @@ -93,7 +87,6 @@ # Power OFF test try: controller.power_off() - controller.update_state() power = controller.get_power() assert power.upper() == "OFF" print("PASSED: Power OFF") From 76ce46c5368e127ae57efeea46bb46f104cb5f10 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Tue, 15 Jul 2025 11:38:56 +0100 Subject: [PATCH 08/10] add log to all controllers --- framework/core/audioAmplifierController.py | 4 ++-- tests/audioAmp_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/audioAmplifierController.py b/framework/core/audioAmplifierController.py index d10dd49..91d1805 100644 --- a/framework/core/audioAmplifierController.py +++ b/framework/core/audioAmplifierController.py @@ -34,8 +34,8 @@ class audioAmplifierController(): - def __init__(self, config:dict): - self._log = logModule("DenonAVRController") + def __init__(self, log:logModule, config:dict): + self._log = log self.controllerType = config.get("type") self.host = config.get("host") diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index 79f0df2..6b232ee 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -24,7 +24,7 @@ LOG.setFilename(os.path.abspath('./logs/'),'audioAmplifier-%sTest.log' % config.get('type')) LOG.stepStart('Testing with %s' % json.dumps(config)) - controller = audioAmplifierController(config) + controller = audioAmplifierController(LOG, config) # Power ON test try: From effd61fb29b5fb66e9d9b4a8037adf4e9b3c9810 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Tue, 15 Jul 2025 13:22:11 +0100 Subject: [PATCH 09/10] move denon setup() in denon controller --- framework/core/audioAmplifier/denon_controller.py | 1 + framework/core/audioAmplifierController.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/audioAmplifier/denon_controller.py b/framework/core/audioAmplifier/denon_controller.py index d30775a..a41690c 100644 --- a/framework/core/audioAmplifier/denon_controller.py +++ b/framework/core/audioAmplifier/denon_controller.py @@ -6,6 +6,7 @@ class DenonAVRController(AudioAmplifier): def __init__(self, host: str): self.receiver = DenonAVR(host) + self.setup() def setup(self): asyncio.run(self.receiver.async_setup()) diff --git a/framework/core/audioAmplifierController.py b/framework/core/audioAmplifierController.py index 91d1805..e05a1dd 100644 --- a/framework/core/audioAmplifierController.py +++ b/framework/core/audioAmplifierController.py @@ -41,7 +41,6 @@ def __init__(self, log:logModule, config:dict): if self.controllerType == "denon": self.audioAmplifier = DenonAVRController(self.host) - self.audioAmplifier.setup() def power_on(self): self._log.info("Powering ON audio amplifier") From 224c65c0093d5ff2dead2e102236682f0b3f9ec4 Mon Sep 17 00:00:00 2001 From: zghp <33546213+zghp@users.noreply.github.com> Date: Tue, 15 Jul 2025 14:30:56 +0100 Subject: [PATCH 10/10] remove async from base.py --- framework/core/audioAmplifier/base.py | 37 ++++++++++----------------- tests/audioAmp_test.py | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/framework/core/audioAmplifier/base.py b/framework/core/audioAmplifier/base.py index 6fca907..2dec4d2 100644 --- a/framework/core/audioAmplifier/base.py +++ b/framework/core/audioAmplifier/base.py @@ -8,27 +8,18 @@ class AudioAmplifier(ABC): input source, mute state, sound mode, and retrieving status information. """ - @classmethod @abstractmethod - async def setup(self): - """ - Async setup method to initialize the amplifier connection. - Called once after construction. - """ - pass - - @abstractmethod - async def power_on(self): + def power_on(self): """Power on the amplifier.""" pass @abstractmethod - async def power_off(self): + def power_off(self): """Power off the amplifier.""" pass @abstractmethod - async def set_volume(self, volume: float): + def set_volume(self, volume: float): """ Set the amplifier volume. @@ -37,7 +28,7 @@ async def set_volume(self, volume: float): pass @abstractmethod - async def mute(self, state: bool): + def mute(self, state: bool): """ Mute or unmute the amplifier. @@ -46,21 +37,21 @@ async def mute(self, state: bool): pass @abstractmethod - async def list_inputs(self) -> list[str]: + def list_inputs(self) -> list[str]: """ Get the list of available input sources supported by the amplifier. """ pass @abstractmethod - async def list_sound_modes(self) -> list[str]: + def list_sound_modes(self) -> list[str]: """ Get the list of available sound modes supported by the amplifier. """ pass @abstractmethod - async def set_input(self, input_name: str): + def set_input(self, input_name: str): """ Set the input source of the amplifier. @@ -69,7 +60,7 @@ async def set_input(self, input_name: str): pass @abstractmethod - async def set_sound_mode(self, input_name: str): + def set_sound_mode(self, input_name: str): """ Set the sound mode of the amplifier. @@ -78,7 +69,7 @@ async def set_sound_mode(self, input_name: str): pass @abstractmethod - async def update_state(self): + def update_state(self): """ Refresh the internal state from the amplifier. @@ -87,27 +78,27 @@ async def update_state(self): pass @abstractmethod - async def get_power(self) -> str: + def get_power(self) -> str: """Get the current power state (e.g., "ON", "OFF").""" pass @abstractmethod - async def get_volume(self) -> float: + def get_volume(self) -> float: """Get the current volume level.""" pass @abstractmethod - async def get_input(self) -> str: + def get_input(self) -> str: """Get the currently selected input source.""" pass @abstractmethod - async def is_muted(self) -> bool: + def is_muted(self) -> bool: """Check whether the amplifier is muted.""" pass @abstractmethod - async def get_status(self) -> dict: + def get_status(self) -> dict: """ Get a dictionary of key status information (power, volume, input, mute). diff --git a/tests/audioAmp_test.py b/tests/audioAmp_test.py index 6b232ee..a0a6813 100644 --- a/tests/audioAmp_test.py +++ b/tests/audioAmp_test.py @@ -16,7 +16,7 @@ CONFIGS = [ { 'type': 'denon', - 'host': '10.242.30.236' + 'host': '' # Needs to be be filled out with IP address }] for config in CONFIGS: