Fix Dynalite to explicitly check valid device class (#36418)

* changed back to check for class in DEVICE_CLASSES

* created a flow that would go through everything as it was blocking the commit
and the cv rules prevent an input that would get to that flow

* moved DEFAULT_COVER_CLASS from const to cover
This commit is contained in:
Ziv 2020-06-04 16:34:28 +03:00 committed by GitHub
parent 99318b7b11
commit 1edbdcb67b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,6 @@
"""Constants for the Dynalite component.""" """Constants for the Dynalite component."""
import logging import logging
from homeassistant.components.cover import DEVICE_CLASS_SHUTTER
from homeassistant.const import CONF_ROOM from homeassistant.const import CONF_ROOM
LOGGER = logging.getLogger(__package__) LOGGER = logging.getLogger(__package__)
@ -36,7 +35,6 @@ CONF_TILT_TIME = "tilt"
CONF_TIME_COVER = "time_cover" CONF_TIME_COVER = "time_cover"
DEFAULT_CHANNEL_TYPE = "light" DEFAULT_CHANNEL_TYPE = "light"
DEFAULT_COVER_CLASS = DEVICE_CLASS_SHUTTER
DEFAULT_NAME = "dynalite" DEFAULT_NAME = "dynalite"
DEFAULT_PORT = 12345 DEFAULT_PORT = 12345
DEFAULT_TEMPLATES = { DEFAULT_TEMPLATES = {

View File

@ -1,12 +1,18 @@
"""Support for the Dynalite channels as covers.""" """Support for the Dynalite channels as covers."""
from typing import Callable from typing import Callable
from homeassistant.components.cover import DEVICE_CLASSES, CoverEntity from homeassistant.components.cover import (
DEVICE_CLASS_SHUTTER,
DEVICE_CLASSES,
CoverEntity,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from .dynalitebase import DynaliteBase, async_setup_entry_base from .dynalitebase import DynaliteBase, async_setup_entry_base
DEFAULT_COVER_CLASS = DEVICE_CLASS_SHUTTER
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
@ -31,8 +37,10 @@ class DynaliteCover(DynaliteBase, CoverEntity):
def device_class(self) -> str: def device_class(self) -> str:
"""Return the class of the device.""" """Return the class of the device."""
dev_cls = self._device.device_class dev_cls = self._device.device_class
assert dev_cls in DEVICE_CLASSES ret_val = DEFAULT_COVER_CLASS
return dev_cls if dev_cls in DEVICE_CLASSES:
ret_val = dev_cls
return ret_val
@property @property
def current_cover_position(self) -> int: def current_cover_position(self) -> int: