diff --git a/homeassistant/components/esphome/binary_sensor.py b/homeassistant/components/esphome/binary_sensor.py index 338f3787090..ffe322b6259 100644 --- a/homeassistant/components/esphome/binary_sensor.py +++ b/homeassistant/components/esphome/binary_sensor.py @@ -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 diff --git a/homeassistant/components/esphome/button.py b/homeassistant/components/esphome/button.py index a16eca650ad..914ddb38da1 100644 --- a/homeassistant/components/esphome/button.py +++ b/homeassistant/components/esphome/button.py @@ -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 diff --git a/homeassistant/components/esphome/cover.py b/homeassistant/components/esphome/cover.py index e055ffc5d03..0e23050646f 100644 --- a/homeassistant/components/esphome/cover.py +++ b/homeassistant/components/esphome/cover.py @@ -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