diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 80ac8133415..a6cde0c4670 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -188,6 +188,33 @@ RPC_SENSORS: Final = { }, entity_category=EntityCategory.DIAGNOSTIC, ), + "overtemp": RpcBinarySensorDescription( + key="switch", + sub_key="errors", + name="Overheating", + device_class=BinarySensorDeviceClass.PROBLEM, + value=lambda status, _: False if status is None else "overtemp" in status, + entity_category=EntityCategory.DIAGNOSTIC, + supported=lambda status: status.get("apower") is not None, + ), + "overpower": RpcBinarySensorDescription( + key="switch", + sub_key="errors", + name="Overpowering", + device_class=BinarySensorDeviceClass.PROBLEM, + value=lambda status, _: False if status is None else "overpower" in status, + entity_category=EntityCategory.DIAGNOSTIC, + supported=lambda status: status.get("apower") is not None, + ), + "overvoltage": RpcBinarySensorDescription( + key="switch", + sub_key="errors", + name="Overvoltage", + device_class=BinarySensorDeviceClass.PROBLEM, + value=lambda status, _: False if status is None else "overvoltage" in status, + entity_category=EntityCategory.DIAGNOSTIC, + supported=lambda status: status.get("apower") is not None, + ), } diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index 12f82016a1c..51e0711b035 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -183,7 +183,9 @@ async def async_setup_entry_rpc( for key in key_instances: # Filter non-existing sensors - if description.sub_key not in wrapper.device.status[key]: + if description.sub_key not in wrapper.device.status[ + key + ] and not description.supported(wrapper.device.status[key]): continue # Filter and remove entities that according to settings should not create an entity @@ -266,6 +268,7 @@ class RpcEntityDescription(EntityDescription, RpcEntityRequiredKeysMixin): removal_condition: Callable[[dict, str], bool] | None = None extra_state_attributes: Callable[[dict, dict], dict | None] | None = None use_polling_wrapper: bool = False + supported: Callable = lambda _: False @dataclass @@ -505,7 +508,9 @@ class ShellyRpcAttributeEntity(ShellyRpcEntity, entity.Entity): """Value of sensor.""" if callable(self.entity_description.value): self._last_value = self.entity_description.value( - self.wrapper.device.status[self.key][self.entity_description.sub_key], + self.wrapper.device.status[self.key].get( + self.entity_description.sub_key + ), self._last_value, ) else: