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" name: "Fritz!Box Temperature Sync Dev"
description: "Sync Fritz!DECT thermostat temperatures with other sensors in Home Assistant" description: "Sync Fritz!DECT thermostat temperatures with other sensors in Home Assistant"
version: "0.5.0" version: "0.5.1"
startup: "application" startup: "application"
stage: "stable" stage: "stable"
slug: "fritz_temp_sync_dev" slug: "fritz_temp_sync_dev"

View File

@ -176,7 +176,12 @@ class FritzBox:
name = name[0].string name = name[0].string
id = int(button[0].button["value"]) 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 = { request_data = {
"device": id, "device": id,
@ -185,7 +190,8 @@ class FritzBox:
} }
r = self.session.get(f"{self.url}/{self._endpoints['device_details']}", params=request_data, 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") device_content_raw = BeautifulSoup(r.text, "html.parser")
offset = float(device_content_raw.find("input", {"type": "hidden", "name": "Offset"})["value"]) offset = float(device_content_raw.find("input", {"type": "hidden", "name": "Offset"})["value"])
devices_raw.append({ devices_raw.append({
@ -303,16 +309,20 @@ class FritzBox:
if device is None: if device is None:
return return
offset_changed = False
if self.old_fb: if self.old_fb:
new_offset = device["offset"] + real_temp - device["temperature"] 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: else:
new_offset = device.get_offset() + real_temp - device.get_temperature() 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: if offset_changed:
device["offset"] = new_offset if self.old_fb:
else: device["offset"] = new_offset
device.set_offset(new_offset) else:
self.set_offset(device) device.set_offset(new_offset)
self.update_time[device_name] = datetime.now() self.set_offset(device)
self.update_time[device_name] = datetime.now()