Ensure ESPHome device classes are valid (#60594)
This commit is contained in:
parent
5003a1515b
commit
b996f624db
3 changed files with 12 additions and 5 deletions
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
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.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -45,8 +45,10 @@ class EsphomeBinarySensor(
|
|||
return self._state.state
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
def device_class(self) -> str | None:
|
||||
"""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
|
||||
|
||||
@property
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
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.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -32,8 +32,10 @@ class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
|||
"""A button implementation for ESPHome."""
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
def device_class(self) -> str | None:
|
||||
"""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
|
||||
|
||||
@callback
|
||||
|
|
|
@ -8,6 +8,7 @@ from aioesphomeapi import CoverInfo, CoverOperation, CoverState
|
|||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
ATTR_TILT_POSITION,
|
||||
DEVICE_CLASSES,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_CLOSE_TILT,
|
||||
SUPPORT_OPEN,
|
||||
|
@ -57,8 +58,10 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity):
|
|||
return flags
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
def device_class(self) -> str | None:
|
||||
"""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
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Reference in a new issue