Skip to content

Commit

Permalink
deal with MISSING batteryInverter data from SENEC WebAPI response
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jun 14, 2024
1 parent 328ab5d commit 34647fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 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.6.0"
"version": "2024.6.1"
}
41 changes: 21 additions & 20 deletions custom_components/senec/pysenec_ha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import asyncio
import traceback

import aiohttp
# required to patch the CookieJar of aiohttp - thanks for nothing!
import contextlib
import logging
from datetime import datetime
from http.cookies import BaseCookie, SimpleCookie, Morsel
from time import time
from typing import Union, cast

import aiohttp
import xmltodict
from time import time
from datetime import datetime
from aiohttp import ClientResponseError, ClientConnectorError
from aiohttp.helpers import is_ip_address
from dateutil.relativedelta import relativedelta

from orjson import JSONDecodeError
from packaging import version

# required to patch the CookieJar of aiohttp - thanks for nothing!
import contextlib
from http.cookies import BaseCookie, SimpleCookie, Morsel
from aiohttp import ClientResponseError, ClientConnectorError
from aiohttp.helpers import is_ip_address
from yarl import URL
from typing import Union, cast, Optional

from custom_components.senec.const import (
QUERY_BMS_KEY,
Expand All @@ -33,8 +29,6 @@
CONF_APP_SYSTEMID,
CONF_APP_WALLBOX_COUNT,
)

from custom_components.senec.pysenec_ha.util import parse
from custom_components.senec.pysenec_ha.constants import (
SYSTEM_STATE_NAME,
WALLBOX_STATE_NAME,
Expand Down Expand Up @@ -68,6 +62,7 @@
LOCAL_WB_MODE_FASTEST,
LOCAL_WB_MODE_UNKNOWN,
)
from custom_components.senec.pysenec_ha.util import parse

# 4: "INITIAL CHARGE",
# 5: "MAINTENANCE CHARGE",
Expand Down Expand Up @@ -3599,11 +3594,17 @@ def system_state(self) -> str:
# 'lastContact': {'time': 1700000000, 'severity': 'INFO'}, 'flags': []},
#######################################################################################################
@property
def battery_inverter_state(self) -> float:
if self._app_raw_tech_data is not None and "batteryInverter" in self._app_raw_tech_data:
bat_inv_obj = self._app_raw_tech_data["batteryInverter"]
if "state" in bat_inv_obj:
return bat_inv_obj["state"]["name"].replace('_', ' ')
def battery_inverter_state(self) -> str:
if self._app_raw_tech_data is not None:
if "batteryInverter" in self._app_raw_tech_data:
bat_inv_obj = self._app_raw_tech_data["batteryInverter"]
if "state" in bat_inv_obj and "name" in bat_inv_obj["state"] and bat_inv_obj["state"]["name"] is not None:
return bat_inv_obj["state"]["name"].replace('_', ' ')
if "mcu" in self._app_raw_tech_data:
mcu_obj = self._app_raw_tech_data["mcu"]
if "mainControllerState" in mcu_obj and "name" in mcu_obj["mainControllerState"] and mcu_obj["mainControllerState"]["name"] is not None:
return mcu_obj["mainControllerState"]["name"].replace('_', ' ')


@property
def battery_temp(self) -> float:
Expand Down

0 comments on commit 34647fe

Please sign in to comment.