mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Validate icon and device_class of ESPHome sensor entities (#46709)
This commit is contained in:
parent
9f4874bb81
commit
c6c0e2416c
@ -3,8 +3,11 @@ import math
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from aioesphomeapi import SensorInfo, SensorState, TextSensorInfo, TextSensorState
|
from aioesphomeapi import SensorInfo, SensorState, TextSensorInfo, TextSensorState
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import DEVICE_CLASSES
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
|
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
|
||||||
@ -54,7 +57,7 @@ class EsphomeSensor(EsphomeEntity):
|
|||||||
"""Return the icon."""
|
"""Return the icon."""
|
||||||
if not self._static_info.icon or self._static_info.device_class:
|
if not self._static_info.icon or self._static_info.device_class:
|
||||||
return None
|
return None
|
||||||
return self._static_info.icon
|
return vol.Schema(cv.icon)(self._static_info.icon)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def force_update(self) -> bool:
|
def force_update(self) -> bool:
|
||||||
@ -80,7 +83,7 @@ class EsphomeSensor(EsphomeEntity):
|
|||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
"""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 None
|
||||||
return self._static_info.device_class
|
return self._static_info.device_class
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user