more failure catching and prints

This commit is contained in:
Timon Horlboge 2022-12-04 16:45:29 +01:00
parent 4fdf91ece7
commit 9387dfbea9
2 changed files with 21 additions and 11 deletions

View File

@ -1,6 +1,6 @@
name: "Fritz!Box Temperature Sync Dev"
description: "Sync Fritz!DECT thermostat temperatures with other sensors in Home Assistant"
version: "0.5.0"
version: "0.5.1"
startup: "application"
stage: "stable"
slug: "fritz_temp_sync_dev"

View File

@ -176,7 +176,12 @@ class FritzBox:
name = name[0].string
id = int(button[0].button["value"])
temperature = float(temperature[0].string.split(" ")[0].replace(",", "."))
print("Temperature raw:", temperature)
try:
temperature = float(temperature[0].string.split(" ")[0].replace(",", "."))
except:
print("Error parsing temperature.")
return []
request_data = {
"device": id,
@ -185,7 +190,8 @@ class FritzBox:
}
r = self.session.get(f"{self.url}/{self._endpoints['device_details']}", params=request_data,
verify=self.verify_ssl)
verify=self.verify_ssl)
device_content_raw = BeautifulSoup(r.text, "html.parser")
offset = float(device_content_raw.find("input", {"type": "hidden", "name": "Offset"})["value"])
devices_raw.append({
@ -303,16 +309,20 @@ class FritzBox:
if device is None:
return
offset_changed = False
if self.old_fb:
new_offset = device["offset"] + real_temp - device["temperature"]
logging.info(f"Update offset from {device['offset']} to {new_offset}")
offset_changed = new_offset != device["offset"]
logging.info(f"Update offset from {device['offset']} to {new_offset} (changed: {offset_changed}")
else:
new_offset = device.get_offset() + real_temp - device.get_temperature()
logging.info(f"Update offset from {device.get_offset()} to {new_offset}")
offset_changed = new_offset != device.get_offset()
logging.info(f"Update offset from {device.get_offset()} to {new_offset} (changed: {offset_changed}")
if self.old_fb:
device["offset"] = new_offset
else:
device.set_offset(new_offset)
self.set_offset(device)
self.update_time[device_name] = datetime.now()
if offset_changed:
if self.old_fb:
device["offset"] = new_offset
else:
device.set_offset(new_offset)
self.set_offset(device)
self.update_time[device_name] = datetime.now()