diff --git a/fritz_temp_sync/config.yaml b/fritz_temp_sync/config.yaml index 76c7d75..86adf70 100755 --- a/fritz_temp_sync/config.yaml +++ b/fritz_temp_sync/config.yaml @@ -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" diff --git a/fritz_temp_sync/fritzbox.py b/fritz_temp_sync/fritzbox.py index f43c8ee..61b5e45 100755 --- a/fritz_temp_sync/fritzbox.py +++ b/fritz_temp_sync/fritzbox.py @@ -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()