mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Handle missing values in Shelly sensors (#39515)
This commit is contained in:
parent
b541abc551
commit
dde0dab3db
@ -88,6 +88,10 @@ class ShellySensor(ShellyBlockEntity, Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Value of sensor."""
|
"""Value of sensor."""
|
||||||
|
value = getattr(self.block, self.attribute)
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if self.attribute in [
|
if self.attribute in [
|
||||||
"deviceTemp",
|
"deviceTemp",
|
||||||
"extTemp",
|
"extTemp",
|
||||||
@ -95,13 +99,13 @@ class ShellySensor(ShellyBlockEntity, Entity):
|
|||||||
"overpowerValue",
|
"overpowerValue",
|
||||||
"power",
|
"power",
|
||||||
]:
|
]:
|
||||||
return round(getattr(self.block, self.attribute), 1)
|
return round(value, 1)
|
||||||
# Energy unit change from Wmin or Wh to kWh
|
# Energy unit change from Wmin or Wh to kWh
|
||||||
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wmin":
|
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wmin":
|
||||||
return round(getattr(self.block, self.attribute) / 60 / 1000, 2)
|
return round(value / 60 / 1000, 2)
|
||||||
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wh":
|
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wh":
|
||||||
return round(getattr(self.block, self.attribute) / 1000, 2)
|
return round(value / 1000, 2)
|
||||||
return getattr(self.block, self.attribute)
|
return value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user