From 0985a85fef9c5f866c3fc836ab3312018e9bc563 Mon Sep 17 00:00:00 2001 From: Sebastian Waldvogel Date: Sat, 30 Nov 2024 17:25:07 +0100 Subject: [PATCH] Fix return value of set_weather_regulated_charge(enable=True) + simplification of request creation --- e3dc/_e3dc.py | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/e3dc/_e3dc.py b/e3dc/_e3dc.py index a1af829..f74e525 100644 --- a/e3dc/_e3dc.py +++ b/e3dc/_e3dc.py @@ -2397,39 +2397,20 @@ def set_weather_regulated_charge(self, enable: bool, keepAlive: bool = False): 0 if success -1 if error """ - if enable: - res = self.sendRequest( - ( - RscpTag.EMS_REQ_SET_POWER_SETTINGS, - RscpType.Container, - [ - ( - RscpTag.EMS_WEATHER_REGULATED_CHARGE_ENABLED, - RscpType.UChar8, - 1, - ) - ], - ), - keepAlive=keepAlive, - ) - else: - res = self.sendRequest( - ( - RscpTag.EMS_REQ_SET_POWER_SETTINGS, - RscpType.Container, - [ - ( - RscpTag.EMS_WEATHER_REGULATED_CHARGE_ENABLED, - RscpType.UChar8, - 0, - ) - ], - ), - keepAlive=keepAlive, - ) + res = self.sendRequest( + ( + RscpTag.EMS_REQ_SET_POWER_SETTINGS, + RscpType.Container, + [ + ( + RscpTag.EMS_WEATHER_REGULATED_CHARGE_ENABLED, + RscpType.UChar8, + enable, + ) + ], + ), + keepAlive=keepAlive, + ) - # validate return code for EMS_RES_WEATHER_REGULATED_CHARGE_ENABLED is 0 - if res[2][0][2] == 0: - return 0 - else: - return -1 + # validate return code for EMS_RES_WEATHER_REGULATED_CHARGE_ENABLED being equal to requested new state + return res[2][0][2] == enable