diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index d7230de0832..5803b8aa839 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -466,21 +466,23 @@ class HomeKitBatterySensor(HomeKitSensor): @property def icon(self) -> str: """Return the sensor icon.""" - if not self.available or self.state is None: + native_value = self.native_value + if not self.available or native_value is None: return "mdi:battery-unknown" # This is similar to the logic in helpers.icon, but we have delegated the # decision about what mdi:battery-alert is to the device. icon = "mdi:battery" - if self.is_charging and self.state > 10: - percentage = int(round(self.state / 20 - 0.01)) * 20 + is_charging = self.is_charging + if is_charging and native_value > 10: + percentage = int(round(native_value / 20 - 0.01)) * 20 icon += f"-charging-{percentage}" - elif self.is_charging: + elif is_charging: icon += "-outline" elif self.is_low_battery: icon += "-alert" - elif self.state < 95: - percentage = max(int(round(self.state / 10 - 0.01)) * 10, 10) + elif native_value < 95: + percentage = max(int(round(native_value / 10 - 0.01)) * 10, 10) icon += f"-{percentage}" return icon