Skip to content

Commit

Permalink
fallback, if _bms_modules_configured is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Aug 24, 2024
1 parent dcf6083 commit f2f29b4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion custom_components/senec/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-senec-v3/issues",
"requirements": ["xmltodict>=0.12.0", "packaging>=21.0", "python-dateutil>=2.8.0"],
"version": "2024.8.3"
"version": "2024.8.4"
}
84 changes: 55 additions & 29 deletions custom_components/senec/pysenec_ha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,122 +968,146 @@ def _bms_modules_configured(self) -> int:

@property
def bms_soc_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["SOC"]) > 0):
return self._raw["BMS"]["SOC"][0]

@property
def bms_soc_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["SOC"]) > 1):
return self._raw["BMS"]["SOC"][1]

@property
def bms_soc_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["SOC"]) > 2):
return self._raw["BMS"]["SOC"][2]

@property
def bms_soc_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOC" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["SOC"]) > 3):
return self._raw["BMS"]["SOC"][3]

@property
def bms_soh_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["SOH"]) > 0):
return self._raw["BMS"]["SOH"][0]

@property
def bms_soh_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["SOH"]) > 1):
return self._raw["BMS"]["SOH"][1]

@property
def bms_soh_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["SOH"]) > 2):
return self._raw["BMS"]["SOH"][2]

@property
def bms_soh_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "SOH" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["SOH"]) > 3):
return self._raw["BMS"]["SOH"][3]

@property
def bms_voltage_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["VOLTAGE"]) > 0):
return self._raw["BMS"]["VOLTAGE"][0]

@property
def bms_voltage_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["VOLTAGE"]) > 1):
return self._raw["BMS"]["VOLTAGE"][1]

@property
def bms_voltage_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["VOLTAGE"]) > 2):
return self._raw["BMS"]["VOLTAGE"][2]

@property
def bms_voltage_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "VOLTAGE" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["VOLTAGE"]) > 3):
return self._raw["BMS"]["VOLTAGE"][3]

@property
def bms_current_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["CURRENT"]) > 0):
return self._raw["BMS"]["CURRENT"][0]

@property
def bms_current_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["CURRENT"]) > 1):
return self._raw["BMS"]["CURRENT"][1]

@property
def bms_current_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["CURRENT"]) > 2):
return self._raw["BMS"]["CURRENT"][2]

@property
def bms_current_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "CURRENT" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["CURRENT"]) > 3):
return self._raw["BMS"]["CURRENT"][3]

@property
def bms_cycles_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["CYCLES"]) > 0):
return self._raw["BMS"]["CYCLES"][0]

@property
def bms_cycles_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["CYCLES"]) > 1):
return self._raw["BMS"]["CYCLES"][1]

@property
def bms_cycles_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["CYCLES"]) > 2):
return self._raw["BMS"]["CYCLES"][2]

@property
def bms_cycles_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "CYCLES" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["CYCLES"]) > 3):
return self._raw["BMS"]["CYCLES"][3]

@property
def bms_fw_a(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and self._bms_modules_configured > 0:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and (
self._bms_modules_configured > 0 or len(self._raw["BMS"]["FW"]) > 0):
return self._raw["BMS"]["FW"][0]

@property
def bms_fw_b(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and self._bms_modules_configured > 1:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and (
self._bms_modules_configured > 1 or len(self._raw["BMS"]["FW"]) > 1):
return self._raw["BMS"]["FW"][1]

@property
def bms_fw_c(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and self._bms_modules_configured > 2:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and (
self._bms_modules_configured > 2 or len(self._raw["BMS"]["FW"]) > 2):
return self._raw["BMS"]["FW"][2]

@property
def bms_fw_d(self) -> float:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and self._bms_modules_configured > 3:
if hasattr(self, '_raw') and "BMS" in self._raw and "FW" in self._raw["BMS"] and (
self._bms_modules_configured > 3 or len(self._raw["BMS"]["FW"]) > 3):
return self._raw["BMS"]["FW"][3]

@property
Expand Down Expand Up @@ -3763,13 +3787,15 @@ def battery_module_temperature_max(self) -> [float]:
def clear_jar(self):
self.web_session._cookie_jar.clear()


need_patch: bool = None
@staticmethod
def _require_lib_patch() -> bool:
need_patch = version.parse(aiohttp.__version__) < version.parse("3.9.0")
if need_patch:
_LOGGER.info(
f"aiohttp version is below 3.9.0 (current version is: {aiohttp.__version__}) - CookieJar.filter_cookies(...) need to be patched")
global need_patch
if need_patch is None:
need_patch = version.parse(aiohttp.__version__) < version.parse("3.9.0")
if need_patch:
_LOGGER.info(
f"aiohttp version is below 3.9.0 (current version is: {aiohttp.__version__}) - CookieJar.filter_cookies(...) need to be patched")
return need_patch


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
homeassistant>=2023.6.0
homeassistant>=2024.8.2
xmltodict>=0.12.0
packaging>=21.0
6 changes: 1 addition & 5 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
colorlog==6.8.0
pip>=23.2.1
ruff==0.1.7
# https://github.com/home-assistant/core/issues/95192
urllib3>=1.26.5,<2
pytest-homeassistant-custom-component>=0.13.154

0 comments on commit f2f29b4

Please sign in to comment.