Skip to content

Commit bf7b14f

Browse files
author
marq24
committed
added a "force-refresh-all-data" Button
1 parent 81f00ff commit bf7b14f

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

custom_components/goecharger_api2/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,16 @@ async def _async_update_data(self) -> dict:
338338
# ret = await self.bridge.async_write_values(kv_pairs)
339339
# return ret
340340

341-
def _request_update_in_sec(self, seconds: int):
341+
def request_update_in_sec(self, seconds: float):
342342
if self._debounced_update_task is not None and not self._debounced_update_task.done():
343343
self._debounced_update_task.cancel()
344344
self._debounced_update_task = asyncio.create_task(self._debounce_coordinator_update(seconds))
345345

346-
async def _debounce_coordinator_update(self, seconds: int):
346+
async def _debounce_coordinator_update(self, seconds: float):
347347
await asyncio.sleep(seconds)
348-
if self.bridge is not None:
349-
self.bridge.reset_stored_update_ts()
350348
await self.async_refresh()
351349

352-
def handle_write_resut(self, a_type, value, key, result, entity):
350+
def handle_write_result(self, a_type, value, key, result, entity):
353351
_LOGGER.debug(f"write {a_type} result: {result}")
354352
if key in result:
355353
self.data[key] = result[key]
@@ -364,19 +362,23 @@ def handle_write_resut(self, a_type, value, key, result, entity):
364362
self.async_update_listeners()
365363
do_refresh = False
366364

365+
elif key == Tag.INTERNAL_FORCE_REFRESH_ALL.key:
366+
self.request_update_in_sec(2.5)
367+
do_refresh = False
368+
367369
if do_refresh:
368370
if entity is not None:
369371
entity.async_schedule_update_ha_state(force_refresh=True)
370-
self._request_update_in_sec(10)
372+
#self.request_update_in_sec(10)
371373

372374
async def async_write_key(self, key: str, value, entity: Entity = None) -> dict:
373375
result = await self.bridge.write_value_to_key(key, value)
374-
self.handle_write_resut("single", value, key, result, entity)
376+
self.handle_write_result("single", value, key, result, entity)
375377
return result
376378

377379
async def async_write_multiple_keys(self, attr:dict, key: str, value, entity: Entity = None) -> dict:
378380
result = await self.bridge._write_values_int(attr, key, value)
379-
self.handle_write_resut("multiple", value, key, result, entity)
381+
self.handle_write_result("multiple", value, key, result, entity)
380382
return result
381383

382384
async def read_versions(self):

custom_components/goecharger_api2/const.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ class ExtSwitchEntityDescription(SwitchEntityDescription):
229229
icon="mdi:reload",
230230
entity_registry_enabled_default=True
231231
),
232+
ExtButtonEntityDescription(
233+
key=Tag.INTERNAL_FORCE_REFRESH_ALL.key,
234+
payload=IS_TRIGGER,
235+
entity_category=EntityCategory.CONFIG,
236+
device_class=None,
237+
icon="mdi:reload",
238+
entity_registry_enabled_default=True
239+
),
232240
]
233241
NUMBER_SENSORS = [
234242
# ama

custom_components/goecharger_api2/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"iot_class": "local_polling",
1212
"issue_tracker": "https://github.com/marq24/ha-goecharger-api2/issues",
1313
"requirements": ["packaging>=21.0"],
14-
"version": "2026.2.4"
14+
"version": "2026.2.5"
1515
}

custom_components/goecharger_api2/pygoecharger_ha/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ async def write_value_to_key(self, key, value) -> dict:
293293
match key:
294294
case Tag.INTERNAL_FORCE_CONFIG_READ.key:
295295
await self.force_config_update()
296+
case Tag.INTERNAL_FORCE_REFRESH_ALL.key:
297+
self.reset_stored_update_ts()
298+
# we do the actual request for the new data in the
299+
# DataUpdateCoordinator... (with a short delwy of some
300+
# seconds...)
301+
# await self.read_all()
296302

297303
return {key: value}
298304
else:

custom_components/goecharger_api2/pygoecharger_ha/keys.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,10 @@ def __str__(self):
349349
# see also https://github.com/goecharger/go-eCharger-API-v2/discussions/110
350350
IDS = ApiKey(key="ids", cat=CAT.STATUS, writeable=True, writeonly=True)
351351

352-
# none exsiting ApiKeys
352+
# none existing ApiKeys
353353
CAR_CONNECTED = ApiKey(key="car", cat=CAT.STATUS)
354354
INTERNAL_FORCE_CONFIG_READ = ApiKey(key="zfocore", cat=CAT.CONFIG)
355+
INTERNAL_FORCE_REFRESH_ALL = ApiKey(key="zforeal", cat=CAT.CONFIG)
355356

356357
# NOT-DOCUMENTED
357358
# -> goe-Controller-Scan immer aktiviert

custom_components/goecharger_api2/translations/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
},
9393
"button": {
9494
"rst": {"name": "go-e Neustarten"},
95-
"zfocore": {"name": "Konfiguration erneut einlesen"}
95+
"zfocore": {"name": "Konfiguration erneut einlesen"},
96+
"zforeal": {"name": "Daten Sync erzwingen"}
9697
},
9798
"number": {
9899
"ama": {"name": "Max. Stromlimit"},

custom_components/goecharger_api2/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
},
9393
"button": {
9494
"rst": {"name": "Restart go-e device"},
95-
"zfocore": {"name": "Read Configuration"}
95+
"zfocore": {"name": "Read Configuration"},
96+
"zforeal": {"name": "Force data sync"}
9697
},
9798
"number": {
9899
"ama": {"name": "Maximum current limit"},

0 commit comments

Comments
 (0)