Use CoverDeviceClass in Dynalite (#83394)

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

View File

@ -1,10 +1,10 @@
"""Support for the Dynalite channels as covers.""" """Support for the Dynalite channels as covers."""
from contextlib import suppress
from typing import Any from typing import Any
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_CURRENT_POSITION, ATTR_CURRENT_POSITION,
DEVICE_CLASSES,
CoverDeviceClass, CoverDeviceClass,
CoverEntity, CoverEntity,
) )
@ -14,8 +14,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .dynalitebase import DynaliteBase, async_setup_entry_base from .dynalitebase import DynaliteBase, async_setup_entry_base
DEFAULT_COVER_CLASS = CoverDeviceClass.SHUTTER
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
@ -39,13 +37,12 @@ class DynaliteCover(DynaliteBase, CoverEntity):
"""Representation of a Dynalite Channel as a Home Assistant Cover.""" """Representation of a Dynalite Channel as a Home Assistant Cover."""
@property @property
def device_class(self) -> str: def device_class(self) -> CoverDeviceClass:
"""Return the class of the device.""" """Return the class of the device."""
dev_cls = self._device.device_class if device_class := self._device.device_class:
ret_val = DEFAULT_COVER_CLASS with suppress(ValueError):
if dev_cls in DEVICE_CLASSES: return CoverDeviceClass(device_class)
ret_val = dev_cls return CoverDeviceClass.SHUTTER
return ret_val
@property @property
def current_cover_position(self) -> int: def current_cover_position(self) -> int: