From afeeb6b121bd5f1cceed4f0acd1fc243a43dfb71 Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Wed, 24 Apr 2024 16:29:40 +0000 Subject: [PATCH] moveout transaction load on init. do this after config form --- custom_components/alfen_wallbox/__init__.py | 3 ++- custom_components/alfen_wallbox/alfen.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/custom_components/alfen_wallbox/__init__.py b/custom_components/alfen_wallbox/__init__.py index 7805731..63ee476 100644 --- a/custom_components/alfen_wallbox/__init__.py +++ b/custom_components/alfen_wallbox/__init__.py @@ -51,6 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b if not device: return False + device.initilize = True await device.async_update() device.get_number_of_socket() device.get_licenses() @@ -60,7 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b hass.data[DOMAIN][config_entry.entry_id] = device await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) - + device.initilize = False return True diff --git a/custom_components/alfen_wallbox/alfen.py b/custom_components/alfen_wallbox/alfen.py index cb5b550..3d1b1de 100644 --- a/custom_components/alfen_wallbox/alfen.py +++ b/custom_components/alfen_wallbox/alfen.py @@ -87,6 +87,7 @@ def __init__(self, self.latest_tag = None self.transaction_offset = 0 self.transaction_counter = 0 + self.initilize = False # set next update time as current time self.next_update = datetime.datetime.now() @@ -171,9 +172,11 @@ async def async_update(self): try: self.updating = True await self._get_all_properties_value() - if self.transaction_counter == 0: + + if self.transaction_counter == 0 and not self.initilize: await self._get_transaction() - self.transaction_counter += 1 + if not self.initilize: + self.transaction_counter += 1 finally: self.updating = False