From 120bae7d58a7edcbf2e947c72f0b6c68c86d5be1 Mon Sep 17 00:00:00 2001 From: Simon Elsbrock Date: Thu, 11 Jan 2024 23:51:33 +0100 Subject: [PATCH] fix: update sensor wrongly reporting new update An issue reported the update sensor wrongly indicating availability of a newer version. The newer version in fact was older and marked as "testing". Since we do not do a semantic version compare but just a simple string comparison, fix by ignoring "testing" release. Also, make the whole logic a bit more robust. resolves #7 --- custom_components/cowboy/binary_sensor.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/custom_components/cowboy/binary_sensor.py b/custom_components/cowboy/binary_sensor.py index 0368704..3405ffe 100644 --- a/custom_components/cowboy/binary_sensor.py +++ b/custom_components/cowboy/binary_sensor.py @@ -85,9 +85,20 @@ class CowboyUpdateBinarySensor(CowboyBinarySensor): @callback def _handle_coordinator_update(self) -> None: - """Handle updated data from the coordinator.""" + """Handle updated data from the coordinator. + This sensor is on if there is a firmware update available and + the bike firmware is not the latest release. The firmware update + must not have status: testing.""" + data = self.coordinator.data or {} + firmware = data.get("firmware", {}) + firmware_name = firmware.get("name", "") + firmware_status = firmware.get("status", "") + + device_info = self.coordinator.device_info or {} + sw_version = device_info.get("sw_version", "") + self._attr_is_on = ( - self.coordinator.data["firmware"]["name"] - != self.coordinator.device_info["sw_version"] + firmware_name != sw_version and firmware_status != "testing" ) + self.async_write_ha_state()