From f1f61f8916c3b2b4e899c0184e1c0d83a6ee24af Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Thu, 12 Dec 2024 22:34:48 -0300 Subject: [PATCH 01/18] list beer fridges devices --- cli.py | 5 ++++- whirlpool/appliancesmanager.py | 10 +++++++++- whirlpool/backendselector.py | 6 ++++++ whirlpool/types.py | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index 0a8ff6a..642a579 100644 --- a/cli.py +++ b/cli.py @@ -22,7 +22,7 @@ parser.add_argument("-e", "--email", help="Email address") parser.add_argument("-p", "--password", help="Password") parser.add_argument( - "-b", "--brand", help="Brand (whirlpool/maytag/kitchenaid)", default="whirlpool" + "-b", "--brand", help="Brand (whirlpool/maytag/kitchenaid/consul)", default="whirlpool" ) parser.add_argument("-r", "--region", help="Region (EU/US)", default="EU") parser.add_argument("-l", "--list", help="List appliances", action="store_true") @@ -40,6 +40,8 @@ def attr_upd(): selected_brand = Brand.Maytag elif args.brand == "kitchenaid": selected_brand = Brand.KitchenAid + elif args.brand == "consul": + selected_brand = Brand.Consul else: logger.error("Invalid brand argument") return @@ -66,6 +68,7 @@ def attr_upd(): print(appliance_manager.aircons) print(appliance_manager.washer_dryers) print(appliance_manager.ovens) + print(appliance_manager.beer_fridges) return if not args.said: diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index 08151d8..f3016ab 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -20,6 +20,7 @@ def __init__( self._auth = auth self._aircons: list[dict[str, Any]] = [] self._washer_dryers: list[dict[str, Any]] = [] + self._beer_fridges: list[dict[str, Any]] = [] self._ovens: list[dict[str, Any]] = [] self._session: aiohttp.ClientSession = session @@ -64,7 +65,10 @@ def _add_appliance(self, appliance: dict[str, Any]) -> None: if any(model in data_model for model in oven_models): self._ovens.append(appliance_data) return - + if "ddm_ted_refrigerator_v12" in data_model: + self._beer_fridges.append(appliance_data) + return + LOGGER.warning("Unsupported appliance data model %s", data_model) async def _get_owned_appliances(self, account_id: str) -> bool: @@ -118,6 +122,10 @@ def aircons(self): @property def washer_dryers(self): return self._washer_dryers + + @property + def beer_fridges(self): + return self._beer_fridges @property def ovens(self): diff --git a/whirlpool/backendselector.py b/whirlpool/backendselector.py index 381e646..7680545 100644 --- a/whirlpool/backendselector.py +++ b/whirlpool/backendselector.py @@ -27,6 +27,12 @@ "client_secret": "kkdPquOHfNH-iIinccTdhAkJmaIdWBhLehhLrfoXRWbKjEpqpdu92PISF_yJEWQs72D2yeC0PdoEKeWgHR9JRA", } ], + Brand.Consul: [ + { + "client_id": "consul_lar_android_v1", + "client_secret": "xfPIj2fqhHXlK4bz2oPToDX5E0zHZ409ZLY6ZHiU3p_jh4wv_Ycg8haUhnB6yXuA", + } + ], } URLS: dict[Region, str] = { diff --git a/whirlpool/types.py b/whirlpool/types.py index 3a89891..b46ff8a 100644 --- a/whirlpool/types.py +++ b/whirlpool/types.py @@ -5,6 +5,7 @@ class Brand(Enum): Whirlpool = 0 Maytag = 1 KitchenAid = 2 + Consul = 3 class Region(Enum): From 1016f7a6e42c4dcbc338365d886c63e8ec5d503f Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Fri, 13 Dec 2024 15:20:02 -0300 Subject: [PATCH 02/18] including beer fridge integration --- cli.py | 16 ++++++--- cli_beer_fridge_menu.py | 72 ++++++++++++++++++++++++++++++++++++++++ whirlpool/beer_fridge.py | 52 +++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 cli_beer_fridge_menu.py create mode 100644 whirlpool/beer_fridge.py diff --git a/cli.py b/cli.py index 642a579..8c01b63 100644 --- a/cli.py +++ b/cli.py @@ -7,6 +7,7 @@ from cli_ac_menu import show_aircon_menu from cli_oven_menu import show_oven_menu from cli_washerdryer_menu import show_washerdryer_menu +from cli_beer_fridge_menu import show_beer_fridge_menu from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth from whirlpool.backendselector import BackendSelector, Brand, Region @@ -69,11 +70,7 @@ def attr_upd(): print(appliance_manager.washer_dryers) print(appliance_manager.ovens) print(appliance_manager.beer_fridges) - return - - if not args.said: - logger.error("No appliance specified") - return + # return for ac_data in appliance_manager.aircons: if ac_data["SAID"] == args.said: @@ -89,6 +86,15 @@ def attr_upd(): if mo_data["SAID"] == args.said: await show_oven_menu(backend_selector, auth, args.said, session) return + + for bf_data in appliance_manager.beer_fridges: + if bf_data["SAID"]: + await show_beer_fridge_menu(backend_selector, auth, bf_data["SAID"], session) + return + + if not args.said: + logger.error("No appliance specified") + return asyncio.run(start()) diff --git a/cli_beer_fridge_menu.py b/cli_beer_fridge_menu.py new file mode 100644 index 0000000..d375726 --- /dev/null +++ b/cli_beer_fridge_menu.py @@ -0,0 +1,72 @@ +import aioconsole + +from whirlpool.beer_fridge import BeerFridge + + +async def show_beer_fridge_menu(bbckend_selector, auth, said, session): + def print_menu(): + print("\n") + print(30 * "-", "MENU", 30 * "-") + print("+. Temp up") + print("-. Temp down") + print("-4. Set -4°C") + print("-2. Set -2°C") + print("0. Set 0°C") + print("3. Set 3°C") + print("5. Set 5°C") + print("t. Turbo toggle") + print("l. Display lock toggle") + print("u. Update status from server") + print("p. Print status") + print("r. Print raw status") + print("c. Custom command") + print("q. Exit") + print(67 * "-") + + def print_status(bc: BeerFridge): + print("current_temp: " + str(bc.get_current_temp(True))+"°C") + print("turbo_mode: " + str(bc.get_turbo_mode())) + print("display_locked: " + str(bc.get_display_lock())) + + def attr_upd(): + print("Attributes updated") + + bc = BeerFridge(bbckend_selector, auth, said, session) + bc.register_attr_callback(attr_upd) + await bc.connect() + + loop = True + while loop: + print_menu() + choice = await aioconsole.ainput("Enter your choice: ") + + if choice == "+": + temp = bc.get_current_temp() - 1 + await bc.set_temp(temp) + elif choice == "-": + temp = bc.get_current_temp() + 1 + await bc.set_temp(temp) + elif choice in ["-4", "-2", "0", "3", "5"]: + temp = int(choice) + await bc.set_especific_temp(temp) + elif choice == "t": + await bc.set_turbo_mode(not bc.get_turbo_mode()) + elif choice == "l": + await bc.set_display_lock(not bc.get_display_lock()) + elif choice == "p": + print_status(bc) + elif choice == "u": + await bc.fetch_data() + print_status(bc) + elif choice == "r": + print(bc._data_dict) + elif choice == "c": + cmd = await aioconsole.ainput("Command: ") + val = await aioconsole.ainput("Value: ") + await bc.send_attributes({cmd: val}) + elif choice == "q": + await bc.disconnect() + print("Bye") + loop = False + else: + print("Wrong option selection. Enter any key to try again..") diff --git a/whirlpool/beer_fridge.py b/whirlpool/beer_fridge.py new file mode 100644 index 0000000..d9a9114 --- /dev/null +++ b/whirlpool/beer_fridge.py @@ -0,0 +1,52 @@ +import logging + +import aiohttp + +from .appliance import Appliance + +LOGGER = logging.getLogger(__name__) + +SETTING_TEMP = "Refrigerator_OpSetTempPreset" +SETTING_DISPLAY_LOCK = "Sys_OpSetControlLock" +SETTING_TURBO_MODE = "Sys_OpSetMaxCool" + +TEMP_MAP = { + -4: 12, + -2: 11, + 0: 10, + 3: 9, + 5: 8, + } + + +class BeerFridge(Appliance): + def __init__(self, backend_selector, auth, said, session: aiohttp.ClientSession): + Appliance.__init__(self, backend_selector, auth, said, session) + + def get_current_temp(self, real_temp: bool=None): + if real_temp: + reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} + return str(reversed_temp_map[int(self.get_attribute(SETTING_TEMP))]) + return int(self.get_attribute(SETTING_TEMP)) + + async def set_temp(self, temp: int): + if (8 <= temp <= 12): + await self.send_attributes({SETTING_TEMP: str(temp)}) + + async def set_especific_temp(self, temp: int): + allowed_temps = [-4, -2, 0, 3, 5] + if temp not in allowed_temps: + raise ValueError(f"Invalid temperature: {temp}. Allowed values are {allowed_temps}.") + await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) + + def get_turbo_mode(self): + return self.attr_value_to_bool(self.get_attribute(SETTING_TURBO_MODE)) + + async def set_turbo_mode(self, turbo: bool): + await self.send_attributes({SETTING_TURBO_MODE: self.bool_to_attr_value(turbo)}) + + def get_display_lock(self): + return self.attr_value_to_bool(self.get_attribute(SETTING_DISPLAY_LOCK)) + + async def set_display_lock(self, display: bool): + await self.send_attributes({SETTING_DISPLAY_LOCK: self.bool_to_attr_value(display)}) From 414a87b020caea2ff78011c2bf6e36a51f252365 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Fri, 13 Dec 2024 15:37:11 -0300 Subject: [PATCH 03/18] fix isort --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 8c01b63..94c6725 100644 --- a/cli.py +++ b/cli.py @@ -5,9 +5,9 @@ import aiohttp from cli_ac_menu import show_aircon_menu +from cli_beer_fridge_menu import show_beer_fridge_menu from cli_oven_menu import show_oven_menu from cli_washerdryer_menu import show_washerdryer_menu -from cli_beer_fridge_menu import show_beer_fridge_menu from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth from whirlpool.backendselector import BackendSelector, Brand, Region From 19d4cd277d929f18d0080f7259a66a8c52991e4e Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Fri, 13 Dec 2024 15:40:40 -0300 Subject: [PATCH 04/18] fixing lint --- whirlpool/appliancesmanager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index f3016ab..24868f3 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -118,15 +118,15 @@ async def fetch_appliances(self): @property def aircons(self): return self._aircons - - @property - def washer_dryers(self): - return self._washer_dryers @property def beer_fridges(self): return self._beer_fridges + @property + def washer_dryers(self): + return self._washer_dryers + @property def ovens(self): return self._ovens From 2b41226a8ad9ea924e0bcbaf7a07c934181b2eb2 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Fri, 13 Dec 2024 16:08:01 -0300 Subject: [PATCH 05/18] fixing black lint --- cli.py | 9 +++++++-- cli_beer_fridge_menu.py | 2 +- whirlpool/appliancesmanager.py | 4 +++- whirlpool/beer_fridge.py | 24 ++++++++++++++---------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cli.py b/cli.py index 94c6725..b4d86e0 100644 --- a/cli.py +++ b/cli.py @@ -23,7 +23,10 @@ parser.add_argument("-e", "--email", help="Email address") parser.add_argument("-p", "--password", help="Password") parser.add_argument( - "-b", "--brand", help="Brand (whirlpool/maytag/kitchenaid/consul)", default="whirlpool" + "-b", + "--brand", + help="Brand (whirlpool/maytag/kitchenaid/consul)", + default="whirlpool" ) parser.add_argument("-r", "--region", help="Region (EU/US)", default="EU") parser.add_argument("-l", "--list", help="List appliances", action="store_true") @@ -89,7 +92,9 @@ def attr_upd(): for bf_data in appliance_manager.beer_fridges: if bf_data["SAID"]: - await show_beer_fridge_menu(backend_selector, auth, bf_data["SAID"], session) + await show_beer_fridge_menu( + backend_selector, auth, bf_data["SAID"], session + ) return if not args.said: diff --git a/cli_beer_fridge_menu.py b/cli_beer_fridge_menu.py index d375726..8ec21f8 100644 --- a/cli_beer_fridge_menu.py +++ b/cli_beer_fridge_menu.py @@ -24,7 +24,7 @@ def print_menu(): print(67 * "-") def print_status(bc: BeerFridge): - print("current_temp: " + str(bc.get_current_temp(True))+"°C") + print("current_temp: " + str(bc.get_current_temp(True)) + "°C") print("turbo_mode: " + str(bc.get_turbo_mode())) print("display_locked: " + str(bc.get_display_lock())) diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index 24868f3..0d3be31 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -62,9 +62,11 @@ def _add_appliance(self, appliance: dict[str, Any]) -> None: "cooking_u2", "ddm_cooking_bio_self_clean_tourmaline_v2", ] + if any(model in data_model for model in oven_models): self._ovens.append(appliance_data) return + if "ddm_ted_refrigerator_v12" in data_model: self._beer_fridges.append(appliance_data) return @@ -118,7 +120,7 @@ async def fetch_appliances(self): @property def aircons(self): return self._aircons - + @property def beer_fridges(self): return self._beer_fridges diff --git a/whirlpool/beer_fridge.py b/whirlpool/beer_fridge.py index d9a9114..54ba9f9 100644 --- a/whirlpool/beer_fridge.py +++ b/whirlpool/beer_fridge.py @@ -11,11 +11,11 @@ SETTING_TURBO_MODE = "Sys_OpSetMaxCool" TEMP_MAP = { - -4: 12, - -2: 11, - 0: 10, - 3: 9, - 5: 8, + -4: 12, + -2: 11, + 0: 10, + 3: 9, + 5: 8, } @@ -23,20 +23,22 @@ class BeerFridge(Appliance): def __init__(self, backend_selector, auth, said, session: aiohttp.ClientSession): Appliance.__init__(self, backend_selector, auth, said, session) - def get_current_temp(self, real_temp: bool=None): + def get_current_temp(self, real_temp: bool = None): if real_temp: - reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} + reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} return str(reversed_temp_map[int(self.get_attribute(SETTING_TEMP))]) return int(self.get_attribute(SETTING_TEMP)) async def set_temp(self, temp: int): - if (8 <= temp <= 12): + if 8 <= temp <= 12: await self.send_attributes({SETTING_TEMP: str(temp)}) async def set_especific_temp(self, temp: int): allowed_temps = [-4, -2, 0, 3, 5] if temp not in allowed_temps: - raise ValueError(f"Invalid temperature: {temp}. Allowed values are {allowed_temps}.") + raise ValueError( + f"Invalid temperature: {temp}. Allowed values are {allowed_temps}." + ) await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) def get_turbo_mode(self): @@ -49,4 +51,6 @@ def get_display_lock(self): return self.attr_value_to_bool(self.get_attribute(SETTING_DISPLAY_LOCK)) async def set_display_lock(self, display: bool): - await self.send_attributes({SETTING_DISPLAY_LOCK: self.bool_to_attr_value(display)}) + await self.send_attributes( + {SETTING_DISPLAY_LOCK: self.bool_to_attr_value(display)} + ) From d5d1f73c669522dd85126c8b6c343ce9050d9bf2 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Fri, 13 Dec 2024 16:14:00 -0300 Subject: [PATCH 06/18] formating --- cli.py | 8 ++++---- whirlpool/appliancesmanager.py | 6 +++--- whirlpool/beer_fridge.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli.py b/cli.py index b4d86e0..a7dc9bd 100644 --- a/cli.py +++ b/cli.py @@ -26,7 +26,7 @@ "-b", "--brand", help="Brand (whirlpool/maytag/kitchenaid/consul)", - default="whirlpool" + default="whirlpool", ) parser.add_argument("-r", "--region", help="Region (EU/US)", default="EU") parser.add_argument("-l", "--list", help="List appliances", action="store_true") @@ -89,14 +89,14 @@ def attr_upd(): if mo_data["SAID"] == args.said: await show_oven_menu(backend_selector, auth, args.said, session) return - + for bf_data in appliance_manager.beer_fridges: if bf_data["SAID"]: await show_beer_fridge_menu( backend_selector, auth, bf_data["SAID"], session - ) + ) return - + if not args.said: logger.error("No appliance specified") return diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index 0d3be31..b326499 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -62,15 +62,15 @@ def _add_appliance(self, appliance: dict[str, Any]) -> None: "cooking_u2", "ddm_cooking_bio_self_clean_tourmaline_v2", ] - + if any(model in data_model for model in oven_models): self._ovens.append(appliance_data) return - + if "ddm_ted_refrigerator_v12" in data_model: self._beer_fridges.append(appliance_data) return - + LOGGER.warning("Unsupported appliance data model %s", data_model) async def _get_owned_appliances(self, account_id: str) -> bool: diff --git a/whirlpool/beer_fridge.py b/whirlpool/beer_fridge.py index 54ba9f9..6f980bc 100644 --- a/whirlpool/beer_fridge.py +++ b/whirlpool/beer_fridge.py @@ -16,7 +16,7 @@ 0: 10, 3: 9, 5: 8, - } +} class BeerFridge(Appliance): @@ -32,7 +32,7 @@ def get_current_temp(self, real_temp: bool = None): async def set_temp(self, temp: int): if 8 <= temp <= 12: await self.send_attributes({SETTING_TEMP: str(temp)}) - + async def set_especific_temp(self, temp: int): allowed_temps = [-4, -2, 0, 3, 5] if temp not in allowed_temps: @@ -49,7 +49,7 @@ async def set_turbo_mode(self, turbo: bool): def get_display_lock(self): return self.attr_value_to_bool(self.get_attribute(SETTING_DISPLAY_LOCK)) - + async def set_display_lock(self, display: bool): await self.send_attributes( {SETTING_DISPLAY_LOCK: self.bool_to_attr_value(display)} From 9b6ee78517d6d52c0471d13693b437dff4d6edf4 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 18:57:12 -0300 Subject: [PATCH 07/18] Suggested changes --- cli.py | 14 +++--- ...fridge_menu.py => cli_refrigerator_menu.py | 44 +++++++++---------- whirlpool/appliancesmanager.py | 8 ++-- whirlpool/{beer_fridge.py => refrigerator.py} | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) rename cli_beer_fridge_menu.py => cli_refrigerator_menu.py (57%) rename whirlpool/{beer_fridge.py => refrigerator.py} (98%) diff --git a/cli.py b/cli.py index a7dc9bd..2f8371f 100644 --- a/cli.py +++ b/cli.py @@ -5,7 +5,7 @@ import aiohttp from cli_ac_menu import show_aircon_menu -from cli_beer_fridge_menu import show_beer_fridge_menu +from cli_refrigerator_menu import show_refrigerator_menu from cli_oven_menu import show_oven_menu from cli_washerdryer_menu import show_washerdryer_menu from whirlpool.appliancesmanager import AppliancesManager @@ -72,8 +72,8 @@ def attr_upd(): print(appliance_manager.aircons) print(appliance_manager.washer_dryers) print(appliance_manager.ovens) - print(appliance_manager.beer_fridges) - # return + print(appliance_manager.refrigerator) + return for ac_data in appliance_manager.aircons: if ac_data["SAID"] == args.said: @@ -90,10 +90,10 @@ def attr_upd(): await show_oven_menu(backend_selector, auth, args.said, session) return - for bf_data in appliance_manager.beer_fridges: - if bf_data["SAID"]: - await show_beer_fridge_menu( - backend_selector, auth, bf_data["SAID"], session + for rf_data in appliance_manager.refrigerator: + if rf_data["SAID"] == args.said: + await show_refrigerator_menu( + backend_selector, auth, args.said, session ) return diff --git a/cli_beer_fridge_menu.py b/cli_refrigerator_menu.py similarity index 57% rename from cli_beer_fridge_menu.py rename to cli_refrigerator_menu.py index 8ec21f8..c9127e8 100644 --- a/cli_beer_fridge_menu.py +++ b/cli_refrigerator_menu.py @@ -1,9 +1,9 @@ import aioconsole -from whirlpool.beer_fridge import BeerFridge +from whirlpool.refrigerator import Refrigerator -async def show_beer_fridge_menu(bbckend_selector, auth, said, session): +async def show_refrigerator_menu(bbckend_selector, auth, said, session): def print_menu(): print("\n") print(30 * "-", "MENU", 30 * "-") @@ -23,17 +23,17 @@ def print_menu(): print("q. Exit") print(67 * "-") - def print_status(bc: BeerFridge): - print("current_temp: " + str(bc.get_current_temp(True)) + "°C") - print("turbo_mode: " + str(bc.get_turbo_mode())) - print("display_locked: " + str(bc.get_display_lock())) + def print_status(bc: Refrigerator): + print("current_temp: " + str(rf.get_current_temp(True)) + "°C") + print("turbo_mode: " + str(rf.get_turbo_mode())) + print("display_locked: " + str(rf.get_display_lock())) def attr_upd(): print("Attributes updated") - bc = BeerFridge(bbckend_selector, auth, said, session) - bc.register_attr_callback(attr_upd) - await bc.connect() + rf = Refrigerator(bbckend_selector, auth, said, session) + rf.register_attr_callback(attr_upd) + await rf.connect() loop = True while loop: @@ -41,31 +41,31 @@ def attr_upd(): choice = await aioconsole.ainput("Enter your choice: ") if choice == "+": - temp = bc.get_current_temp() - 1 - await bc.set_temp(temp) + temp = rf.get_current_temp() - 1 + await rf.set_temp(temp) elif choice == "-": - temp = bc.get_current_temp() + 1 - await bc.set_temp(temp) + temp = rf.get_current_temp() + 1 + await rf.set_temp(temp) elif choice in ["-4", "-2", "0", "3", "5"]: temp = int(choice) - await bc.set_especific_temp(temp) + await rf.set_especific_temp(temp) elif choice == "t": - await bc.set_turbo_mode(not bc.get_turbo_mode()) + await rf.set_turbo_mode(not rf.get_turbo_mode()) elif choice == "l": - await bc.set_display_lock(not bc.get_display_lock()) + await rf.set_display_lock(not rf.get_display_lock()) elif choice == "p": - print_status(bc) + print_status(rf) elif choice == "u": - await bc.fetch_data() - print_status(bc) + await rf.fetch_data() + print_status(rf) elif choice == "r": - print(bc._data_dict) + print(rf._data_dict) elif choice == "c": cmd = await aioconsole.ainput("Command: ") val = await aioconsole.ainput("Value: ") - await bc.send_attributes({cmd: val}) + await rf.send_attributes({cmd: val}) elif choice == "q": - await bc.disconnect() + await rf.disconnect() print("Bye") loop = False else: diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index b326499..3c869ac 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -20,7 +20,7 @@ def __init__( self._auth = auth self._aircons: list[dict[str, Any]] = [] self._washer_dryers: list[dict[str, Any]] = [] - self._beer_fridges: list[dict[str, Any]] = [] + self._refrigerator: list[dict[str, Any]] = [] self._ovens: list[dict[str, Any]] = [] self._session: aiohttp.ClientSession = session @@ -68,7 +68,7 @@ def _add_appliance(self, appliance: dict[str, Any]) -> None: return if "ddm_ted_refrigerator_v12" in data_model: - self._beer_fridges.append(appliance_data) + self._refrigerator.append(appliance_data) return LOGGER.warning("Unsupported appliance data model %s", data_model) @@ -122,8 +122,8 @@ def aircons(self): return self._aircons @property - def beer_fridges(self): - return self._beer_fridges + def refrigerator(self): + return self._refrigerator @property def washer_dryers(self): diff --git a/whirlpool/beer_fridge.py b/whirlpool/refrigerator.py similarity index 98% rename from whirlpool/beer_fridge.py rename to whirlpool/refrigerator.py index 6f980bc..f52ad55 100644 --- a/whirlpool/beer_fridge.py +++ b/whirlpool/refrigerator.py @@ -19,7 +19,7 @@ } -class BeerFridge(Appliance): +class Refrigerator(Appliance): def __init__(self, backend_selector, auth, said, session: aiohttp.ClientSession): Appliance.__init__(self, backend_selector, auth, said, session) From b9ca087592d7e1b5b040e8d807425f2010640963 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 19:01:00 -0300 Subject: [PATCH 08/18] fixing isort and lint --- cli.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cli.py b/cli.py index 2f8371f..81a8630 100644 --- a/cli.py +++ b/cli.py @@ -5,8 +5,8 @@ import aiohttp from cli_ac_menu import show_aircon_menu -from cli_refrigerator_menu import show_refrigerator_menu from cli_oven_menu import show_oven_menu +from cli_refrigerator_menu import show_refrigerator_menu from cli_washerdryer_menu import show_washerdryer_menu from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth @@ -92,9 +92,7 @@ def attr_upd(): for rf_data in appliance_manager.refrigerator: if rf_data["SAID"] == args.said: - await show_refrigerator_menu( - backend_selector, auth, args.said, session - ) + await show_refrigerator_menu(backend_selector, auth, args.said, session) return if not args.said: From 8f9912c66162315acfcf35b14aebd53678d3c28f Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 19:52:10 -0300 Subject: [PATCH 09/18] merged temperatures methods --- cli_refrigerator_menu.py | 2 +- whirlpool/refrigerator.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cli_refrigerator_menu.py b/cli_refrigerator_menu.py index c9127e8..2baae41 100644 --- a/cli_refrigerator_menu.py +++ b/cli_refrigerator_menu.py @@ -48,7 +48,7 @@ def attr_upd(): await rf.set_temp(temp) elif choice in ["-4", "-2", "0", "3", "5"]: temp = int(choice) - await rf.set_especific_temp(temp) + await rf.set_temp(temp) elif choice == "t": await rf.set_turbo_mode(not rf.get_turbo_mode()) elif choice == "l": diff --git a/whirlpool/refrigerator.py b/whirlpool/refrigerator.py index f52ad55..b318a50 100644 --- a/whirlpool/refrigerator.py +++ b/whirlpool/refrigerator.py @@ -30,16 +30,14 @@ def get_current_temp(self, real_temp: bool = None): return int(self.get_attribute(SETTING_TEMP)) async def set_temp(self, temp: int): - if 8 <= temp <= 12: + if temp in TEMP_MAP.keys(): + await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) + elif temp in TEMP_MAP.values(): await self.send_attributes({SETTING_TEMP: str(temp)}) - - async def set_especific_temp(self, temp: int): - allowed_temps = [-4, -2, 0, 3, 5] - if temp not in allowed_temps: + else: raise ValueError( - f"Invalid temperature: {temp}. Allowed values are {allowed_temps}." + f"Invalid temperature: {temp}. Allowed values are {TEMP_MAP.keys()}." ) - await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) def get_turbo_mode(self): return self.attr_value_to_bool(self.get_attribute(SETTING_TURBO_MODE)) From 37f9cb9951fd21cb7bdd3da682b8522e95a68fd5 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 20:48:51 -0300 Subject: [PATCH 10/18] including refrigerator tests --- tests/conftest.py | 9 + tests/data/refrigerator_data.json | 466 ++++++++++++++++++++++++++++++ tests/test_refrigerator.py | 112 +++++++ 3 files changed, 587 insertions(+) create mode 100644 tests/data/refrigerator_data.json create mode 100644 tests/test_refrigerator.py diff --git a/tests/conftest.py b/tests/conftest.py index 524586b..5d39fb4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,7 @@ from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth from whirlpool.oven import Oven +from whirlpool.refrigerator import Refrigerator from whirlpool.washerdryer import WasherDryer SAID = "WPR1XYZABC123" @@ -66,6 +67,14 @@ def aircon_fixture(backend_selector_mock, auth_fixture, client_session_fixture): ) yield aircon +@pytest.fixture(name="refrigerator") +def refrigerator_fixture(backend_selector_mock, auth_fixture, client_session_fixture): + with patch("whirlpool.appliance.Appliance._create_headers", return_value={}): + refrigerator = Refrigerator( + backend_selector_mock, auth_fixture, SAID, client_session_fixture + ) + yield refrigerator + @pytest.fixture(name="appliances_manager") def appliances_manager_fixture( diff --git a/tests/data/refrigerator_data.json b/tests/data/refrigerator_data.json new file mode 100644 index 0000000..9e053c0 --- /dev/null +++ b/tests/data/refrigerator_data.json @@ -0,0 +1,466 @@ +{ + "DATA1": { + "_id": "WPR43R8FNDJ4C", + "applianceId": "WPR43R8FNDJ4C", + "lastFullSyncTime": 1663677597931, + "lastModified": 1736031905504, + "attributes": { + "XCat_ApplianceInfoSetSerialNumber": { + "value": "TED2018", + "updateTime": 1735714437212 + }, + "Sys_OpSetCalibrationOn": { + "value": "0", + "updateTime": 1735714437212 + }, + "Sys_AlertStatusCustomerFaultCode": { + "value": "0", + "updateTime": 1562028497470 + }, + "lkCans": { + "value": "14", + "updateTime": 1736007173422 + }, + "XCat_WifiSetDeprovisionWifiCommModule": { + "value": "0", + "updateTime": 1735714437212 + }, + "Pantry_OpStatusDoorOpen": { + "value": "0", + "updateTime": 1735714437212 + }, + "ModelNumber": { + "value": "CZE12", + "updateTime": 1735714435000 + }, + "ISP_PART_NUMBER": { + "value": "W00000000", + "updateTime": 1735714435000 + }, + "Freezer_OpStatusContentsWeight": { + "value": "3", + "updateTime": 1736031905314 + }, + "XCat_OdometerStatusRunningHours": { + "value": "553", + "updateTime": 1736030707778 + }, + "ApplianceVersionNumber": { + "value": "0", + "updateTime": 1735714435000 + }, + "ProjectReleaseNumber": { + "value": "W11224365", + "updateTime": 1570702737991 + }, + "ccuri": { + "value": "API144_FRIG_V12", + "updateTime": 1735714435000 + }, + "version": { + "value": "1", + "updateTime": 1735714436056 + }, + "lkLongneck": { + "value": "59", + "updateTime": 1736007173422 + }, + "XCat_PersistentInfoVersion": { + "value": "12", + "updateTime": 1735714437212 + }, + "lkVolume": { + "value": "27.045", + "updateTime": 1736007173422 + }, + "lkBottles": { + "value": "2", + "updateTime": 1736007173422 + }, + "SerialNumber": { + "value": "ED2018", + "updateTime": 1735714435000 + }, + "Refrigerator_OpStatusDoorOpen": { + "value": "0", + "updateTime": 1736007170085 + }, + "Sys_DisplaySetCavityBrightness": { + "value": "0", + "updateTime": 1736007170085 + }, + "lkWeight": { + "value": "39785.0", + "updateTime": 1736007173422 + }, + "Refrigerator_OpSetTempPreset": { + "value": "10", + "updateTime": 1736030932627 + }, + "XCat_WifiStatusRssiAntennaDiversity": { + "value": "-31", + "updateTime": 1735714437212 + }, + "Sys_AlertStatusDoorOpenAlarm": { + "value": "0", + "updateTime": 1735714437212 + }, + "XCat_PowerStatusPowerOutage": { + "value": "1", + "updateTime": 1734307490309 + }, + "Sys_OpStatusState": { + "value": "1", + "updateTime": 1736030847546 + }, + "XCat_OdometerStatusTotalHours": { + "value": "553", + "updateTime": 1736030707778 + }, + "applianceId": { + "value": "72698", + "updateTime": 1736007173422 + }, + "Sys_OpSetMaxCool": { + "value": "0", + "updateTime": 1735714437212 + }, + "TimezoneId": { + "value": "America/New_York", + "updateTime": 1580769838547 + }, + "XCat_PersistentInfoSaid": { + "value": "WPR43R8FNDJ4C", + "updateTime": 1735714437212 + }, + "XCat_WifiSetPublishApplianceState": { + "value": "0", + "updateTime": 1735714437212 + }, + "orgId": { + "value": "NAR", + "updateTime": 1592607815213 + }, + "SAID": { + "value": "WPR43R8FNDJ4C", + "updateTime": 1735714435000 + }, + "Sys_OpSetControlLock": { + "value": "0", + "updateTime": 1735714437212 + }, + "UtcOffset": { + "value": "-18000", + "updateTime": 1580769838547 + }, + "DstOffset": { + "value": "0", + "updateTime": 1580769838547 + }, + "XCat_WifiStatusIspCheck": { + "value": "1", + "updateTime": 1735714437212 + }, + "CC_URI": { + "value": "API144_FRIG_V12", + "updateTime": 1593115050140 + }, + "lkDelta": { + "value": "-551.0", + "updateTime": 1736007173422 + }, + "DateTimeMode": { + "value": "2", + "updateTime": 1580769838547 + }, + "XCat_ApplianceInfoSetModelNumber": { + "value": "CZE12", + "updateTime": 1735714437212 + }, + "Refrigerator_OpStatusContentsWeight": { + "value": "39785", + "updateTime": 1736007173422 + }, + "XCat_WifiSetRebootWifiCommModule": { + "value": "0", + "updateTime": 1735714437212 + }, + "XCat_ConfigSetApplianceCapability": { + "value": "0", + "updateTime": 1562028497470 + }, + "ISP_WIFI_VERSION": { + "value": "9.0.0", + "updateTime": 1735714435000 + }, + "SubscribeClaimstate": { + "value": "1", + "updateTime": 1592607815750 + }, + "XCat_PersistentInfoMacAddress": { + "value": "88:E7:12:0F:E3:9A", + "updateTime": 1735714437212 + }, + "Sys_OpSetVacationMode": { + "value": "0", + "updateTime": 1648382747876 + }, + "XCat_DateTimeSetDateTimeSet": { + "value": "2024-12-30T02:44:23-03:00", + "updateTime": 1735537463798 + }, + "createdDate": { + "value": "1736007174451", + "updateTime": 1736007173422 + }, + "TimeZoneId": { + "value": "America/Sao_Paulo", + "updateTime": 1735714436058 + }, + "ISP_WIFI_PART_NUMBER": { + "value": "W11224365", + "updateTime": 1735714435000 + }, + "Online": { + "value": "0", + "updateTime": 1735714435238 + }, + "MAC_Address": { + "value": "88:e7:12:0f:e3:9a", + "updateTime": 1735714435000 + } + } + }, + "DATA2": { + "_id": "WPR43R8FNDJ4C", + "applianceId": "WPR43R8FNDJ4C", + "lastFullSyncTime": 1663677597931, + "lastModified": 1736031905504, + "attributes": { + "XCat_ApplianceInfoSetSerialNumber": { + "value": "TED2018", + "updateTime": 1735714437212 + }, + "Sys_OpSetCalibrationOn": { + "value": "0", + "updateTime": 1735714437212 + }, + "Sys_AlertStatusCustomerFaultCode": { + "value": "0", + "updateTime": 1562028497470 + }, + "lkCans": { + "value": "14", + "updateTime": 1736007173422 + }, + "XCat_WifiSetDeprovisionWifiCommModule": { + "value": "0", + "updateTime": 1735714437212 + }, + "Pantry_OpStatusDoorOpen": { + "value": "0", + "updateTime": 1735714437212 + }, + "ModelNumber": { + "value": "CZE12", + "updateTime": 1735714435000 + }, + "ISP_PART_NUMBER": { + "value": "W00000000", + "updateTime": 1735714435000 + }, + "Freezer_OpStatusContentsWeight": { + "value": "3", + "updateTime": 1736031905314 + }, + "XCat_OdometerStatusRunningHours": { + "value": "553", + "updateTime": 1736030707778 + }, + "ApplianceVersionNumber": { + "value": "0", + "updateTime": 1735714435000 + }, + "ProjectReleaseNumber": { + "value": "W11224365", + "updateTime": 1570702737991 + }, + "ccuri": { + "value": "API144_FRIG_V12", + "updateTime": 1735714435000 + }, + "version": { + "value": "1", + "updateTime": 1735714436056 + }, + "lkLongneck": { + "value": "59", + "updateTime": 1736007173422 + }, + "XCat_PersistentInfoVersion": { + "value": "12", + "updateTime": 1735714437212 + }, + "lkVolume": { + "value": "27.045", + "updateTime": 1736007173422 + }, + "lkBottles": { + "value": "2", + "updateTime": 1736007173422 + }, + "SerialNumber": { + "value": "ED2018", + "updateTime": 1735714435000 + }, + "Refrigerator_OpStatusDoorOpen": { + "value": "0", + "updateTime": 1736007170085 + }, + "Sys_DisplaySetCavityBrightness": { + "value": "0", + "updateTime": 1736007170085 + }, + "lkWeight": { + "value": "39785.0", + "updateTime": 1736007173422 + }, + "Refrigerator_OpSetTempPreset": { + "value": "8", + "updateTime": 1736030932627 + }, + "XCat_WifiStatusRssiAntennaDiversity": { + "value": "-31", + "updateTime": 1735714437212 + }, + "Sys_AlertStatusDoorOpenAlarm": { + "value": "0", + "updateTime": 1735714437212 + }, + "XCat_PowerStatusPowerOutage": { + "value": "1", + "updateTime": 1734307490309 + }, + "Sys_OpStatusState": { + "value": "1", + "updateTime": 1736030847546 + }, + "XCat_OdometerStatusTotalHours": { + "value": "553", + "updateTime": 1736030707778 + }, + "applianceId": { + "value": "72698", + "updateTime": 1736007173422 + }, + "Sys_OpSetMaxCool": { + "value": "1", + "updateTime": 1735714437212 + }, + "TimezoneId": { + "value": "America/New_York", + "updateTime": 1580769838547 + }, + "XCat_PersistentInfoSaid": { + "value": "WPR43R8FNDJ4C", + "updateTime": 1735714437212 + }, + "XCat_WifiSetPublishApplianceState": { + "value": "0", + "updateTime": 1735714437212 + }, + "orgId": { + "value": "NAR", + "updateTime": 1592607815213 + }, + "SAID": { + "value": "WPR43R8FNDJ4C", + "updateTime": 1735714435000 + }, + "Sys_OpSetControlLock": { + "value": "1", + "updateTime": 1735714437212 + }, + "UtcOffset": { + "value": "-18000", + "updateTime": 1580769838547 + }, + "DstOffset": { + "value": "0", + "updateTime": 1580769838547 + }, + "XCat_WifiStatusIspCheck": { + "value": "1", + "updateTime": 1735714437212 + }, + "CC_URI": { + "value": "API144_FRIG_V12", + "updateTime": 1593115050140 + }, + "lkDelta": { + "value": "-551.0", + "updateTime": 1736007173422 + }, + "DateTimeMode": { + "value": "2", + "updateTime": 1580769838547 + }, + "XCat_ApplianceInfoSetModelNumber": { + "value": "CZE12", + "updateTime": 1735714437212 + }, + "Refrigerator_OpStatusContentsWeight": { + "value": "39785", + "updateTime": 1736007173422 + }, + "XCat_WifiSetRebootWifiCommModule": { + "value": "0", + "updateTime": 1735714437212 + }, + "XCat_ConfigSetApplianceCapability": { + "value": "0", + "updateTime": 1562028497470 + }, + "ISP_WIFI_VERSION": { + "value": "9.0.0", + "updateTime": 1735714435000 + }, + "SubscribeClaimstate": { + "value": "1", + "updateTime": 1592607815750 + }, + "XCat_PersistentInfoMacAddress": { + "value": "88:E7:12:0F:E3:9A", + "updateTime": 1735714437212 + }, + "Sys_OpSetVacationMode": { + "value": "0", + "updateTime": 1648382747876 + }, + "XCat_DateTimeSetDateTimeSet": { + "value": "2024-12-30T02:44:23-03:00", + "updateTime": 1735537463798 + }, + "createdDate": { + "value": "1736007174451", + "updateTime": 1736007173422 + }, + "TimeZoneId": { + "value": "America/Sao_Paulo", + "updateTime": 1735714436058 + }, + "ISP_WIFI_PART_NUMBER": { + "value": "W11224365", + "updateTime": 1735714435000 + }, + "Online": { + "value": "1", + "updateTime": 1735714435238 + }, + "MAC_Address": { + "value": "88:e7:12:0f:e3:9a", + "updateTime": 1735714435000 + } + } + } +} diff --git a/tests/test_refrigerator.py b/tests/test_refrigerator.py new file mode 100644 index 0000000..27f3d65 --- /dev/null +++ b/tests/test_refrigerator.py @@ -0,0 +1,112 @@ +import json +from collections.abc import Callable +from pathlib import Path +from typing import Any + +import pytest +from yarl import URL + +from whirlpool.backendselector import BackendSelector +from whirlpool.refrigerator import Refrigerator + +ACCOUNT_ID = 111222333 + + +CURR_DIR = Path(__file__).parent +DATA_DIR = CURR_DIR / "data" + +REFRIGERATOR_DATA = json.loads((DATA_DIR / "refrigerator_data.json").read_text()) + +DATA1 = REFRIGERATOR_DATA["DATA1"] +DATA2 = REFRIGERATOR_DATA["DATA2"] + + +async def test_attributes( + refrigerator: Refrigerator, backend_selector_mock: BackendSelector, aioresponses_mock +): + aioresponses_mock.get( + backend_selector_mock.websocket_url, + payload={"url": "wss://something"}, + repeat=True, + ) + aioresponses_mock.get( + backend_selector_mock.get_appliance_data_url(refrigerator.said), payload=DATA1 + ) + + await refrigerator.connect() + assert refrigerator.get_online() is False + assert refrigerator.get_current_temp(True) == '0' + assert refrigerator.get_turbo_mode() is False + assert refrigerator.get_display_lock() is False + await refrigerator.disconnect() + + aioresponses_mock.get( + backend_selector_mock.get_appliance_data_url(refrigerator.said), payload=DATA2 + ) + + await refrigerator.connect() + assert refrigerator.get_online() is True + assert refrigerator.get_turbo_mode() is True + assert refrigerator.get_display_lock() is True + assert refrigerator.get_current_temp(True) == '5' + await refrigerator.disconnect() + + +@pytest.mark.parametrize( + ["method", "argument", "expected_json"], + [ + (Refrigerator.set_temp, -4, {'Refrigerator_OpSetTempPreset': '12'}), + (Refrigerator.set_temp, -2, {'Refrigerator_OpSetTempPreset': '11'}), + (Refrigerator.set_temp, 0, {'Refrigerator_OpSetTempPreset': '10'}), + (Refrigerator.set_temp, 3, {'Refrigerator_OpSetTempPreset': '9'}), + (Refrigerator.set_temp, 5, {'Refrigerator_OpSetTempPreset': '8'}), + (Refrigerator.set_turbo_mode, True, {'Sys_OpSetMaxCool': '1'}), + (Refrigerator.set_turbo_mode, False, {'Sys_OpSetMaxCool': '0'}), + (Refrigerator.set_display_lock, True, {"Sys_OpSetControlLock": "1"}), + (Refrigerator.set_display_lock, False, {"Sys_OpSetControlLock": "0"}), + ], +) +async def test_setters( + refrigerator: Refrigerator, + backend_selector_mock: BackendSelector, + aioresponses_mock, + method: Callable, + argument: Any, + expected_json: dict, +): + expected_payload = { + "json": { + "body": expected_json, + "header": {"said": refrigerator.said, "command": "setAttributes"}, + } + } + + post_request_call_kwargs = { + "url": backend_selector_mock.appliance_command_url, + "method": "POST", + "data": None, + "json": expected_payload["json"], + "allow_redirects": True, + "headers": {}, + } + + url = backend_selector_mock.appliance_command_url + + aioresponses_mock.get( + backend_selector_mock.websocket_url, payload={"url": "wss://something"} + ) + aioresponses_mock.get( + backend_selector_mock.get_appliance_data_url(refrigerator.said), payload=DATA1 + ) + + await refrigerator.connect() + + # add call, call method + aioresponses_mock.post(url, payload=expected_payload) + await method(refrigerator, argument) + + # assert args and length + aioresponses_mock.assert_called_with(**post_request_call_kwargs) + assert len(aioresponses_mock.requests[("POST", URL(url))]) == 1 + + await refrigerator.disconnect() From ebcf1359e0e2614df38752aef08523b8488d419c Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 20:53:13 -0300 Subject: [PATCH 11/18] fixing test lint --- tests/test_refrigerator.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_refrigerator.py b/tests/test_refrigerator.py index 27f3d65..297e6d8 100644 --- a/tests/test_refrigerator.py +++ b/tests/test_refrigerator.py @@ -35,7 +35,7 @@ async def test_attributes( await refrigerator.connect() assert refrigerator.get_online() is False - assert refrigerator.get_current_temp(True) == '0' + assert refrigerator.get_current_temp(True) == "0" assert refrigerator.get_turbo_mode() is False assert refrigerator.get_display_lock() is False await refrigerator.disconnect() @@ -48,20 +48,20 @@ async def test_attributes( assert refrigerator.get_online() is True assert refrigerator.get_turbo_mode() is True assert refrigerator.get_display_lock() is True - assert refrigerator.get_current_temp(True) == '5' + assert refrigerator.get_current_temp(True) == "5" await refrigerator.disconnect() @pytest.mark.parametrize( ["method", "argument", "expected_json"], [ - (Refrigerator.set_temp, -4, {'Refrigerator_OpSetTempPreset': '12'}), - (Refrigerator.set_temp, -2, {'Refrigerator_OpSetTempPreset': '11'}), - (Refrigerator.set_temp, 0, {'Refrigerator_OpSetTempPreset': '10'}), - (Refrigerator.set_temp, 3, {'Refrigerator_OpSetTempPreset': '9'}), - (Refrigerator.set_temp, 5, {'Refrigerator_OpSetTempPreset': '8'}), - (Refrigerator.set_turbo_mode, True, {'Sys_OpSetMaxCool': '1'}), - (Refrigerator.set_turbo_mode, False, {'Sys_OpSetMaxCool': '0'}), + (Refrigerator.set_temp, -4, {"Refrigerator_OpSetTempPreset": "12"}), + (Refrigerator.set_temp, -2, {"Refrigerator_OpSetTempPreset": "11"}), + (Refrigerator.set_temp, 0, {"Refrigerator_OpSetTempPreset": "10"}), + (Refrigerator.set_temp, 3, {"Refrigerator_OpSetTempPreset": "9"}), + (Refrigerator.set_temp, 5, {"Refrigerator_OpSetTempPreset": "8"}), + (Refrigerator.set_turbo_mode, True, {"Sys_OpSetMaxCool": "1"}), + (Refrigerator.set_turbo_mode, False, {"Sys_OpSetMaxCool": "0"}), (Refrigerator.set_display_lock, True, {"Sys_OpSetControlLock": "1"}), (Refrigerator.set_display_lock, False, {"Sys_OpSetControlLock": "0"}), ], From cba2e730d1cd5363877928e88f5e6a198a0f8e44 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 20:55:45 -0300 Subject: [PATCH 12/18] fixing lint --- tests/conftest.py | 1 + tests/test_refrigerator.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5d39fb4..858150d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,7 @@ def aircon_fixture(backend_selector_mock, auth_fixture, client_session_fixture): ) yield aircon + @pytest.fixture(name="refrigerator") def refrigerator_fixture(backend_selector_mock, auth_fixture, client_session_fixture): with patch("whirlpool.appliance.Appliance._create_headers", return_value={}): diff --git a/tests/test_refrigerator.py b/tests/test_refrigerator.py index 297e6d8..b6ba47e 100644 --- a/tests/test_refrigerator.py +++ b/tests/test_refrigerator.py @@ -22,7 +22,9 @@ async def test_attributes( - refrigerator: Refrigerator, backend_selector_mock: BackendSelector, aioresponses_mock + refrigerator: Refrigerator, + backend_selector_mock: BackendSelector, + aioresponses_mock ): aioresponses_mock.get( backend_selector_mock.websocket_url, From 81b4ac74777ffe09cea18cf05e755ea199139b3d Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Sat, 4 Jan 2025 20:57:17 -0300 Subject: [PATCH 13/18] lint fix --- tests/test_refrigerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_refrigerator.py b/tests/test_refrigerator.py index b6ba47e..7fb1cf3 100644 --- a/tests/test_refrigerator.py +++ b/tests/test_refrigerator.py @@ -24,7 +24,7 @@ async def test_attributes( refrigerator: Refrigerator, backend_selector_mock: BackendSelector, - aioresponses_mock + aioresponses_mock, ): aioresponses_mock.get( backend_selector_mock.websocket_url, From abd2ffed0c1804516a7bd01fd054752035768b30 Mon Sep 17 00:00:00 2001 From: leandrocaldas <95449790+leandrocaldas@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:17:22 -0300 Subject: [PATCH 14/18] Update cli_refrigerator_menu.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Abílio Costa --- cli_refrigerator_menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli_refrigerator_menu.py b/cli_refrigerator_menu.py index 2baae41..54040fb 100644 --- a/cli_refrigerator_menu.py +++ b/cli_refrigerator_menu.py @@ -3,7 +3,7 @@ from whirlpool.refrigerator import Refrigerator -async def show_refrigerator_menu(bbckend_selector, auth, said, session): +async def show_refrigerator_menu(backend_selector, auth, said, session): def print_menu(): print("\n") print(30 * "-", "MENU", 30 * "-") From 5dda84c8b0abb303a415b8cd3ed5870681c6ab69 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Mon, 6 Jan 2025 13:38:32 -0300 Subject: [PATCH 15/18] suggestions updated --- cli.py | 8 ++++++-- cli_refrigerator_menu.py | 12 ++++++------ tests/test_refrigerator.py | 16 +++++++++------- whirlpool/appliancesmanager.py | 8 ++++---- whirlpool/refrigerator.py | 25 ++++++++++++++++--------- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/cli.py b/cli.py index 81a8630..a2e00d9 100644 --- a/cli.py +++ b/cli.py @@ -72,7 +72,11 @@ def attr_upd(): print(appliance_manager.aircons) print(appliance_manager.washer_dryers) print(appliance_manager.ovens) - print(appliance_manager.refrigerator) + print(appliance_manager.refrigerators) + return + + if not args.said: + logger.error("No appliance specified") return for ac_data in appliance_manager.aircons: @@ -90,7 +94,7 @@ def attr_upd(): await show_oven_menu(backend_selector, auth, args.said, session) return - for rf_data in appliance_manager.refrigerator: + for rf_data in appliance_manager.refrigerators: if rf_data["SAID"] == args.said: await show_refrigerator_menu(backend_selector, auth, args.said, session) return diff --git a/cli_refrigerator_menu.py b/cli_refrigerator_menu.py index 2baae41..c508da2 100644 --- a/cli_refrigerator_menu.py +++ b/cli_refrigerator_menu.py @@ -3,7 +3,7 @@ from whirlpool.refrigerator import Refrigerator -async def show_refrigerator_menu(bbckend_selector, auth, said, session): +async def show_refrigerator_menu(backend_selector, auth, said, session): def print_menu(): print("\n") print(30 * "-", "MENU", 30 * "-") @@ -24,14 +24,14 @@ def print_menu(): print(67 * "-") def print_status(bc: Refrigerator): - print("current_temp: " + str(rf.get_current_temp(True)) + "°C") + print("current_temp: " + str(rf.get_offset_temp(True)) + "°C") print("turbo_mode: " + str(rf.get_turbo_mode())) print("display_locked: " + str(rf.get_display_lock())) def attr_upd(): print("Attributes updated") - rf = Refrigerator(bbckend_selector, auth, said, session) + rf = Refrigerator(backend_selector, auth, said, session) rf.register_attr_callback(attr_upd) await rf.connect() @@ -41,14 +41,14 @@ def attr_upd(): choice = await aioconsole.ainput("Enter your choice: ") if choice == "+": - temp = rf.get_current_temp() - 1 + temp = rf.get_temp() - 1 await rf.set_temp(temp) elif choice == "-": - temp = rf.get_current_temp() + 1 + temp = rf.get_temp() + 1 await rf.set_temp(temp) elif choice in ["-4", "-2", "0", "3", "5"]: temp = int(choice) - await rf.set_temp(temp) + await rf.set_offset_temp(temp) elif choice == "t": await rf.set_turbo_mode(not rf.get_turbo_mode()) elif choice == "l": diff --git a/tests/test_refrigerator.py b/tests/test_refrigerator.py index 7fb1cf3..cfcb729 100644 --- a/tests/test_refrigerator.py +++ b/tests/test_refrigerator.py @@ -37,7 +37,7 @@ async def test_attributes( await refrigerator.connect() assert refrigerator.get_online() is False - assert refrigerator.get_current_temp(True) == "0" + assert refrigerator.get_offset_temp() == "0" assert refrigerator.get_turbo_mode() is False assert refrigerator.get_display_lock() is False await refrigerator.disconnect() @@ -50,18 +50,20 @@ async def test_attributes( assert refrigerator.get_online() is True assert refrigerator.get_turbo_mode() is True assert refrigerator.get_display_lock() is True - assert refrigerator.get_current_temp(True) == "5" + assert refrigerator.get_offset_temp() == "5" await refrigerator.disconnect() @pytest.mark.parametrize( ["method", "argument", "expected_json"], [ - (Refrigerator.set_temp, -4, {"Refrigerator_OpSetTempPreset": "12"}), - (Refrigerator.set_temp, -2, {"Refrigerator_OpSetTempPreset": "11"}), - (Refrigerator.set_temp, 0, {"Refrigerator_OpSetTempPreset": "10"}), - (Refrigerator.set_temp, 3, {"Refrigerator_OpSetTempPreset": "9"}), - (Refrigerator.set_temp, 5, {"Refrigerator_OpSetTempPreset": "8"}), + (Refrigerator.set_offset_temp, -4, {"Refrigerator_OpSetTempPreset": "12"}), + (Refrigerator.set_offset_temp, -2, {"Refrigerator_OpSetTempPreset": "11"}), + (Refrigerator.set_offset_temp, 0, {"Refrigerator_OpSetTempPreset": "10"}), + (Refrigerator.set_offset_temp, 3, {"Refrigerator_OpSetTempPreset": "9"}), + (Refrigerator.set_offset_temp, 5, {"Refrigerator_OpSetTempPreset": "8"}), + (Refrigerator.set_temp, 8, {"Refrigerator_OpSetTempPreset": "8"}), + (Refrigerator.set_temp, 12, {"Refrigerator_OpSetTempPreset": "12"}), (Refrigerator.set_turbo_mode, True, {"Sys_OpSetMaxCool": "1"}), (Refrigerator.set_turbo_mode, False, {"Sys_OpSetMaxCool": "0"}), (Refrigerator.set_display_lock, True, {"Sys_OpSetControlLock": "1"}), diff --git a/whirlpool/appliancesmanager.py b/whirlpool/appliancesmanager.py index 3c869ac..39b40d8 100644 --- a/whirlpool/appliancesmanager.py +++ b/whirlpool/appliancesmanager.py @@ -20,7 +20,7 @@ def __init__( self._auth = auth self._aircons: list[dict[str, Any]] = [] self._washer_dryers: list[dict[str, Any]] = [] - self._refrigerator: list[dict[str, Any]] = [] + self._refrigerators: list[dict[str, Any]] = [] self._ovens: list[dict[str, Any]] = [] self._session: aiohttp.ClientSession = session @@ -68,7 +68,7 @@ def _add_appliance(self, appliance: dict[str, Any]) -> None: return if "ddm_ted_refrigerator_v12" in data_model: - self._refrigerator.append(appliance_data) + self._refrigerators.append(appliance_data) return LOGGER.warning("Unsupported appliance data model %s", data_model) @@ -122,8 +122,8 @@ def aircons(self): return self._aircons @property - def refrigerator(self): - return self._refrigerator + def refrigerators(self): + return self._refrigerators @property def washer_dryers(self): diff --git a/whirlpool/refrigerator.py b/whirlpool/refrigerator.py index b318a50..449af74 100644 --- a/whirlpool/refrigerator.py +++ b/whirlpool/refrigerator.py @@ -23,20 +23,27 @@ class Refrigerator(Appliance): def __init__(self, backend_selector, auth, said, session: aiohttp.ClientSession): Appliance.__init__(self, backend_selector, auth, said, session) - def get_current_temp(self, real_temp: bool = None): - if real_temp: - reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} - return str(reversed_temp_map[int(self.get_attribute(SETTING_TEMP))]) + def get_offset_temp(self): + reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} + return str(reversed_temp_map[int(self.get_attribute(SETTING_TEMP))]) + + async def set_offset_temp(self, temp): + if temp in TEMP_MAP.keys(): + await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) + else: + LOGGER.error( + f"Invalid temperature: {temp}. Allowed values are {TEMP_MAP.keys()}." + ) + + def get_temp(self): return int(self.get_attribute(SETTING_TEMP)) async def set_temp(self, temp: int): - if temp in TEMP_MAP.keys(): - await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) - elif temp in TEMP_MAP.values(): + if temp in TEMP_MAP.values(): await self.send_attributes({SETTING_TEMP: str(temp)}) else: - raise ValueError( - f"Invalid temperature: {temp}. Allowed values are {TEMP_MAP.keys()}." + LOGGER.error( + f"Invalid temperature: {temp}. Allowed values are {TEMP_MAP.values()}." ) def get_turbo_mode(self): From 1384d210eab2c037bd6f241193d8fa3744821540 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Mon, 6 Jan 2025 13:43:19 -0300 Subject: [PATCH 16/18] updated --- cli_refrigerator_menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli_refrigerator_menu.py b/cli_refrigerator_menu.py index c508da2..95e5684 100644 --- a/cli_refrigerator_menu.py +++ b/cli_refrigerator_menu.py @@ -24,7 +24,7 @@ def print_menu(): print(67 * "-") def print_status(bc: Refrigerator): - print("current_temp: " + str(rf.get_offset_temp(True)) + "°C") + print("current_temp: " + str(rf.get_offset_temp()) + "°C") print("turbo_mode: " + str(rf.get_turbo_mode())) print("display_locked: " + str(rf.get_display_lock())) From c2e83b94cac84f0601c0ae641aae54867654d319 Mon Sep 17 00:00:00 2001 From: leandrocaldas Date: Mon, 6 Jan 2025 13:45:27 -0300 Subject: [PATCH 17/18] lint fixed --- whirlpool/refrigerator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/whirlpool/refrigerator.py b/whirlpool/refrigerator.py index 449af74..8d21cc8 100644 --- a/whirlpool/refrigerator.py +++ b/whirlpool/refrigerator.py @@ -26,14 +26,14 @@ def __init__(self, backend_selector, auth, said, session: aiohttp.ClientSession) def get_offset_temp(self): reversed_temp_map = {v: k for k, v in TEMP_MAP.items()} return str(reversed_temp_map[int(self.get_attribute(SETTING_TEMP))]) - + async def set_offset_temp(self, temp): if temp in TEMP_MAP.keys(): await self.send_attributes({SETTING_TEMP: str(TEMP_MAP[temp])}) else: LOGGER.error( f"Invalid temperature: {temp}. Allowed values are {TEMP_MAP.keys()}." - ) + ) def get_temp(self): return int(self.get_attribute(SETTING_TEMP)) From 49e1f9ac7b2bb8650dba3aa8ee821e6a7de3548f Mon Sep 17 00:00:00 2001 From: leandrocaldas <95449790+leandrocaldas@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:10:07 -0300 Subject: [PATCH 18/18] Update cli.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Abílio Costa --- cli.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli.py b/cli.py index a2e00d9..8e7d5bf 100644 --- a/cli.py +++ b/cli.py @@ -99,9 +99,5 @@ def attr_upd(): await show_refrigerator_menu(backend_selector, auth, args.said, session) return - if not args.said: - logger.error("No appliance specified") - return - asyncio.run(start())