From 9f36412076ecf98708b804f535475cf284f108b4 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 6 Dec 2022 13:30:22 +0100 Subject: [PATCH] Use CoverDeviceClass in Dynalite (#83394) --- homeassistant/components/dynalite/cover.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/dynalite/cover.py b/homeassistant/components/dynalite/cover.py index bbca16d3db6..98005ccee0a 100644 --- a/homeassistant/components/dynalite/cover.py +++ b/homeassistant/components/dynalite/cover.py @@ -1,10 +1,10 @@ """Support for the Dynalite channels as covers.""" +from contextlib import suppress from typing import Any from homeassistant.components.cover import ( ATTR_CURRENT_POSITION, - DEVICE_CLASSES, CoverDeviceClass, CoverEntity, ) @@ -14,8 +14,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .dynalitebase import DynaliteBase, async_setup_entry_base -DEFAULT_COVER_CLASS = CoverDeviceClass.SHUTTER - async def async_setup_entry( hass: HomeAssistant, @@ -39,13 +37,12 @@ class DynaliteCover(DynaliteBase, CoverEntity): """Representation of a Dynalite Channel as a Home Assistant Cover.""" @property - def device_class(self) -> str: + def device_class(self) -> CoverDeviceClass: """Return the class of the device.""" - dev_cls = self._device.device_class - ret_val = DEFAULT_COVER_CLASS - if dev_cls in DEVICE_CLASSES: - ret_val = dev_cls - return ret_val + if device_class := self._device.device_class: + with suppress(ValueError): + return CoverDeviceClass(device_class) + return CoverDeviceClass.SHUTTER @property def current_cover_position(self) -> int: