Fix sensors without unit attribute in Shelly integration (#39629)

pull/39644/head
Maciej Bieniek 2020-09-04 11:44:22 +02:00 committed by GitHub
parent 8fd9f56d21
commit ad3e520e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -72,8 +72,6 @@ class ShellySensor(ShellyBlockEntity, Entity):
unit = TEMP_CELSIUS
else:
unit = TEMP_FAHRENHEIT
elif self.info[aioshelly.BLOCK_VALUE_TYPE] == aioshelly.BLOCK_VALUE_TYPE_ENERGY:
unit = ENERGY_KILO_WATT_HOUR
self._unit = unit
self._device_class = device_class
@ -104,9 +102,9 @@ class ShellySensor(ShellyBlockEntity, Entity):
]:
return round(value, 1)
# Energy unit change from Wmin or Wh to kWh
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wmin":
if self.info.get(aioshelly.BLOCK_VALUE_UNIT) == "Wmin":
return round(value / 60 / 1000, 2)
if self.info[aioshelly.BLOCK_VALUE_UNIT] == "Wh":
if self.info.get(aioshelly.BLOCK_VALUE_UNIT) == "Wh":
return round(value / 1000, 2)
return value