From c6c0e2416c257234ded5674ff242481c2def6aac Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Sat, 20 Feb 2021 20:05:35 +0100 Subject: [PATCH] Validate icon and device_class of ESPHome sensor entities (#46709) --- homeassistant/components/esphome/sensor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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