1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Ensure ESPHome device classes are valid (#60594)

This commit is contained in:
Franck Nijhof 2021-11-30 09:44:39 +01:00 committed by GitHub
parent 5003a1515b
commit b996f624db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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