Use CoverDeviceClass in ESPHome (#83395)

This commit is contained in:
Franck Nijhof 2022-12-06 13:29:58 +01:00 committed by GitHub
parent 985c1b31e1
commit 04793978d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
"""Support for ESPHome covers."""
from __future__ import annotations
from contextlib import suppress
from typing import Any
from aioesphomeapi import CoverInfo, CoverOperation, CoverState
@ -8,7 +9,7 @@ from aioesphomeapi import CoverInfo, CoverOperation, CoverState
from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DEVICE_CLASSES,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
)
@ -54,11 +55,11 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity):
return flags
@property
def device_class(self) -> str | None:
def device_class(self) -> CoverDeviceClass | 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
with suppress(ValueError):
return CoverDeviceClass(self._static_info.device_class)
return None
@property
def assumed_state(self) -> bool: