diff --git a/homeassistant/components/esphome/sensor.py b/homeassistant/components/esphome/sensor.py index ad23afd4744..fe9922cf0ed 100644 --- a/homeassistant/components/esphome/sensor.py +++ b/homeassistant/components/esphome/sensor.py @@ -3,8 +3,11 @@ import math from typing import Optional from aioesphomeapi import SensorInfo, SensorState, TextSensorInfo, TextSensorState +import voluptuous as vol +from homeassistant.components.sensor import DEVICE_CLASSES from homeassistant.config_entries import ConfigEntry +import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import HomeAssistantType from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry @@ -54,7 +57,7 @@ class EsphomeSensor(EsphomeEntity): """Return the icon.""" if not self._static_info.icon or self._static_info.device_class: return None - return self._static_info.icon + return vol.Schema(cv.icon)(self._static_info.icon) @property def force_update(self) -> bool: @@ -80,7 +83,7 @@ class EsphomeSensor(EsphomeEntity): @property def device_class(self) -> str: """Return the class of this device, from component DEVICE_CLASSES.""" - if not self._static_info.device_class: + if self._static_info.device_class not in DEVICE_CLASSES: return None return self._static_info.device_class