More changes i guess

This commit is contained in:
Timon Horlboge 2022-12-04 13:59:02 +01:00
parent 924eb57b34
commit 962e2c84af
2 changed files with 15 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import re
import xml.etree.ElementTree as ET
from asyncio import Task
from datetime import datetime, timedelta
from typing import Optional, Dict, List
from typing import Optional, Dict, List, Union
import requests
from bs4 import BeautifulSoup
@ -243,7 +243,7 @@ class FritzBox:
return device
def set_offset(self, device: Device) -> None:
def set_offset(self, device: Union[Device, Dict]) -> None:
if self.dry_run:
logging.warning("No updates in dry-run-mode")
return
@ -298,7 +298,8 @@ class FritzBox:
logging.info(f"Last update for {device_name} {elapsed} ago")
delta = timedelta(minutes=self.update_timeout)
if device_name not in self.update_time.keys() or elapsed > delta:
device: Optional[Device] = self.get_device_data(name=device_name)
device: Optional[Union[Dict, Device]] = self.get_device_data(name=device_name)
logging.info(f"device: {device}")
if device is None:
return
@ -314,4 +315,4 @@ class FritzBox:
else:
device.set_offset(new_offset)
self.set_offset(device)
self.update_time[device.display_name] = datetime.now()
self.update_time[device_name] = datetime.now()

View File

@ -14,7 +14,7 @@ thermostate_mappings = {}
async def handle_event(idx: int):
logging.debug(f"Wait for events for {idx}")
logging.info(f"Wait for events for {idx}")
while event := await ha.events[idx].get():
try:
@ -28,14 +28,19 @@ async def handle_event(idx: int):
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
sensor_state_temp = sensor_state["attributes"]["temperature"] if "temperatur" in sensor_state[
"attributes"] else sensor_state["state"]
sensor_temp = round(float(sensor_state_temp) * 2) / 2
if therm_temp != sensor_temp:
logging.info(
f"{therm_name}: {therm_temp}\n{sensor}: {sensor_state_temp} ({sensor_temp})")
fb.correct_offset(therm_name, sensor_temp)
elif entity_id in sensor_mappings.keys():
sensor_temp = round(float(new_state["attributes"]["temperature"]) * 2) / 2
new_state_temp = new_state["attributes"]["temperature"] if "temperatur" in new_state[
"attributes"] else new_state["state"]
sensor_temp = round(float(new_state_temp) * 2) / 2
logging.info(sensor_temp)
for thermostate in sensor_mappings[entity_id]:
therm_state = await ha.get_device_state(thermostate)
if therm_state["state"] == "unavailable":
@ -46,8 +51,8 @@ async def handle_event(idx: int):
logging.info(
f"{therm_name}: {therm_temp}\n{entity_id}: {new_state_temp} ({sensor_temp})")
fb.correct_offset(therm_name, sensor_temp)
except KeyError:
pass
except KeyError as e:
logging.error(e)
async def init(ha: HomeAssistantAPI, fb: FritzBox):