mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Ensure ESPHome device classes are valid (#60594)
This commit is contained in:
parent
5003a1515b
commit
b996f624db
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -45,8 +45,10 @@ class EsphomeBinarySensor(
|
|||||||
return self._state.state
|
return self._state.state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str | None:
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
|
if self._static_info.device_class not in DEVICE_CLASSES:
|
||||||
|
return None
|
||||||
return self._static_info.device_class
|
return self._static_info.device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -5,7 +5,7 @@ from typing import Any
|
|||||||
|
|
||||||
from aioesphomeapi import ButtonInfo, EntityState
|
from aioesphomeapi import ButtonInfo, EntityState
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity
|
from homeassistant.components.button import DEVICE_CLASSES, ButtonEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -32,8 +32,10 @@ class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
|||||||
"""A button implementation for ESPHome."""
|
"""A button implementation for ESPHome."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str | None:
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
|
if self._static_info.device_class not in DEVICE_CLASSES:
|
||||||
|
return None
|
||||||
return self._static_info.device_class
|
return self._static_info.device_class
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -8,6 +8,7 @@ from aioesphomeapi import CoverInfo, CoverOperation, CoverState
|
|||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
|
DEVICE_CLASSES,
|
||||||
SUPPORT_CLOSE,
|
SUPPORT_CLOSE,
|
||||||
SUPPORT_CLOSE_TILT,
|
SUPPORT_CLOSE_TILT,
|
||||||
SUPPORT_OPEN,
|
SUPPORT_OPEN,
|
||||||
@ -57,8 +58,10 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity):
|
|||||||
return flags
|
return flags
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str | None:
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
|
if self._static_info.device_class not in DEVICE_CLASSES:
|
||||||
|
return None
|
||||||
return self._static_info.device_class
|
return self._static_info.device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user