Add Shelly gen2 error sensors (#66825)

pull/66894/head
Shay Levy 2022-02-19 18:51:01 +02:00 committed by GitHub
parent 8f0b6eac41
commit 5359050afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -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,
),
}

View File

@ -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: