Skip to content

Commit

Permalink
web_client TEST will use also new API (and make sure that auto-detect…
Browse files Browse the repository at this point in the history
… is working)
  • Loading branch information
marq24 committed Mar 8, 2024
1 parent 5f067a8 commit 18545d7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions custom_components/senec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import EntityDescription, Entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers import entity_registry, event
from homeassistant.helpers import config_validation as config_val, entity_registry, event
from homeassistant.util import slugify

from custom_components.senec.pysenec_ha import Senec, Inverter, MySenecWebPortal
Expand Down Expand Up @@ -77,7 +77,7 @@
SCAN_INTERVAL = timedelta(seconds=60)

PLATFORMS = ["sensor", "binary_sensor", "select", "switch", "number"]

CONFIG_SCHEMA = config_val.removed(DOMAIN, raise_if_present=False)

async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the senec component."""
Expand Down
23 changes: 8 additions & 15 deletions custom_components/senec/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,20 @@ async def _test_connection_webapi(self, user: str, pwd: str, master_plant: int):
try:
senec_web_client = MySenecWebPortal(user=user, pwd=pwd, web_session=web_session,
master_plant_number=master_plant)
await senec_web_client.web_authenticate(do_update=False, throw401=True)
if senec_web_client._is_authenticated:
await senec_web_client.update_context()
await senec_web_client.app_authenticate(retry=False, do_update=False)
if senec_web_client._app_is_authenticated:
await senec_web_client.app_update_context()
self._device_master_plant_number = senec_web_client.masterPlantNumber

await senec_web_client.app_update_tech_data()
# these values will also read with every restart...
self._device_type = SYSTYPE_NAME_WEBAPI
self._device_model = senec_web_client.product_name + ' | SENEC.Num: ' + senec_web_client.senec_num
self._device_serial = senec_web_client.serial_number
self._device_version = None # senec_web_client.firmwareVersion

if not senec_web_client._app_is_authenticated:
await senec_web_client.app_authenticate(retry=False, do_update=False)

if senec_web_client._app_is_authenticated:
self._app_token = senec_web_client._app_token
self._app_master_plant_id = senec_web_client._app_master_plant_id
self._app_wallbox_num_max = senec_web_client._app_wallbox_num_max

await senec_web_client.app_update_tech_data()
self._device_version = senec_web_client.versions
self._app_token = senec_web_client._app_token
self._app_master_plant_id = senec_web_client._app_master_plant_id
self._app_wallbox_num_max = senec_web_client._app_wallbox_num_max
self._device_version = senec_web_client.versions

_LOGGER.info(f"Successfully connect to mein-senec.de and APP-API with '{user}'")
return True
Expand Down
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.2.1"
"version": "2024.3.0"
}
4 changes: 3 additions & 1 deletion custom_components/senec/pysenec_ha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2509,8 +2509,10 @@ async def app_get_master_plant_id(self, retry: bool = True):
data = None
try:
data = await res.json();
if self._master_plant_number == -1:
self._master_plant_number = 0
idx = int(self._master_plant_number)
if int(len(data)) >= idx:
if len(data) > idx:
if "id" in data[idx]:
self._app_master_plant_id = data[idx]["id"]
_LOGGER.debug(f"APP-API set _app_master_plant_id to {self._app_master_plant_id}")
Expand Down

0 comments on commit 18545d7

Please sign in to comment.