Don't inherit SensorEntity/NumberEntity and RestoreEntity in Shelly integration (#93531)
* Use RestoreNumber and Restore Sensor for block entities * Update tests * Use RestoreSensor for RPC entities * Fix test for number platform
This commit is contained in:
parent
7c02e1ca99
commit
fe61672792
7 changed files with 106 additions and 39 deletions
|
@ -14,6 +14,7 @@ from homeassistant.const import STATE_ON, EntityCategory
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.entity_registry import RegistryEntry
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .const import CONF_SLEEP_PERIOD
|
||||
from .entity import (
|
||||
|
@ -290,11 +291,18 @@ class RpcBinarySensor(ShellyRpcAttributeEntity, BinarySensorEntity):
|
|||
return bool(self.attribute_value)
|
||||
|
||||
|
||||
class BlockSleepingBinarySensor(ShellySleepingBlockAttributeEntity, BinarySensorEntity):
|
||||
class BlockSleepingBinarySensor(
|
||||
ShellySleepingBlockAttributeEntity, BinarySensorEntity, RestoreEntity
|
||||
):
|
||||
"""Represent a block sleeping binary sensor."""
|
||||
|
||||
entity_description: BlockBinarySensorDescription
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
self.last_state = await self.async_get_last_state()
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if sensor state is on."""
|
||||
|
@ -307,11 +315,18 @@ class BlockSleepingBinarySensor(ShellySleepingBlockAttributeEntity, BinarySensor
|
|||
return self.last_state.state == STATE_ON
|
||||
|
||||
|
||||
class RpcSleepingBinarySensor(ShellySleepingRpcAttributeEntity, BinarySensorEntity):
|
||||
class RpcSleepingBinarySensor(
|
||||
ShellySleepingRpcAttributeEntity, BinarySensorEntity, RestoreEntity
|
||||
):
|
||||
"""Represent a RPC sleeping binary sensor entity."""
|
||||
|
||||
entity_description: RpcBinarySensorDescription
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
self.last_state = await self.async_get_last_state()
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if RPC sensor state is on."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue