fritz_temp_sync/sync_ha_fb.py aktualisiert

This commit is contained in:
Micha Horlboge 2024-11-11 23:21:27 +01:00
parent 89fc6ea73c
commit 00b161945f

View File

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