From cc82976d1572aba21f92549b815313dabbf262b1 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Sun, 7 Nov 2021 12:53:28 -0500 Subject: [PATCH] Add Battery sensor regardless if the battery_percent_remaining attribute is supported or not (#59264) --- homeassistant/components/zha/sensor.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index d7c3e0797b8..2281d5295bc 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -226,6 +226,22 @@ class Battery(Sensor): _unit = PERCENTAGE _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + @classmethod + def create_entity( + cls, + unique_id: str, + zha_device: ZhaDeviceType, + channels: list[ChannelType], + **kwargs, + ) -> ZhaEntity | None: + """Entity Factory. + + Unlike any other entity, PowerConfiguration cluster may not support + battery_percent_remaining attribute, but zha-device-handlers takes care of it + so create the entity regardless + """ + return cls(unique_id, zha_device, channels, **kwargs) + @staticmethod def formatter(value: int) -> int: """Return the state of the entity."""