Validate icon and device_class of ESPHome sensor entities (#46709)
parent
9f4874bb81
commit
c6c0e2416c
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue