Handle state unknown if last state is missing in Shelly (#86813)

Shelly - handle state unknown if last state is missing
This commit is contained in:
Shay Levy 2023-01-28 00:34:56 +02:00 committed by GitHub
parent 50c2992f36
commit 803cd8d9a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 170 additions and 38 deletions

View file

@ -93,12 +93,15 @@ class BlockSleepingNumber(ShellySleepingBlockAttributeEntity, NumberEntity):
entity_description: BlockNumberDescription
@property
def native_value(self) -> float:
def native_value(self) -> float | None:
"""Return value of number."""
if self.block is not None:
return cast(float, self.attribute_value)
return cast(float, self.last_state)
if self.last_state is None:
return None
return cast(float, self.last_state.state)
async def async_set_native_value(self, value: float) -> None:
"""Set value."""