fritz_temp_sync/sync_ha_fb.py aktualisiert

This commit is contained in:
Micha Horlboge 2024-11-11 23:04:39 +01:00
parent f6f46fba8f
commit 89fc6ea73c

View File

@ -22,13 +22,14 @@ async def handle_event(idx: int):
if entity_id in sensor_mappings.keys() or entity_id in thermostate_mappings.keys():
state = await ha.get_device_state(entity_id)
new_state = event["data"]["new_state"]
logging.debug(f"received changed state from {entity_id}")
logging.info(f"received changed state from {entity_id} {entity_id in thermostate_mappings.keys()} {state['state']}")
if entity_id in thermostate_mappings.keys() and state["state"] != "unavailable":
therm_temp = new_state["attributes"]["current_temperature"]
therm_name = new_state["attributes"]["friendly_name"]
sensor = thermostate_mappings[entity_id]
sensor_state = await ha.get_device_state(sensor)
sensor_temp = round(float(sensor_state["attributes"]["temperature"]) * 2) / 2
logger.info(f"temps: {therm_temp} {sensor_temp}")
if therm_temp != sensor_temp:
logging.info(f"{therm_name}: {therm_temp}\n{sensor}: {sensor_state['attributes']['temperature']} ({sensor_temp})")
fb.correct_offset(therm_name, sensor_temp)