From ad3e520e09bf22ba0fbe368e036fd5a6750ef4b5 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Fri, 4 Sep 2020 11:44:22 +0200 Subject: [PATCH] Fix sensors without unit attribute in Shelly integration (#39629) --- homeassistant/components/shelly/sensor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index cfeaea98357..d66076d1754 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -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