Validate icon and device_class of ESPHome sensor entities (#46709)

pull/46830/head
marecabo 2021-02-20 20:05:35 +01:00 committed by GitHub
parent 9f4874bb81
commit c6c0e2416c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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