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