Skip to content

Commit

Permalink
Fix Dynalite to explicitly check valid device class (#36418)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ziv1234 committed Jun 4, 2020
1 parent 99318b7 commit 1edbdcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 0 additions & 2 deletions homeassistant/components/dynalite/const.py
@@ -1,7 +1,6 @@
"""Constants for the Dynalite component."""
import logging

from homeassistant.components.cover import DEVICE_CLASS_SHUTTER
from homeassistant.const import CONF_ROOM

LOGGER = logging.getLogger(__package__)
Expand Down Expand Up @@ -36,7 +35,6 @@
CONF_TIME_COVER = "time_cover"

DEFAULT_CHANNEL_TYPE = "light"
DEFAULT_COVER_CLASS = DEVICE_CLASS_SHUTTER
DEFAULT_NAME = "dynalite"
DEFAULT_PORT = 12345
DEFAULT_TEMPLATES = {
Expand Down
14 changes: 11 additions & 3 deletions homeassistant/components/dynalite/cover.py
@@ -1,12 +1,18 @@
"""Support for the Dynalite channels as covers."""
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.core import HomeAssistant, callback

from .dynalitebase import DynaliteBase, async_setup_entry_base

DEFAULT_COVER_CLASS = DEVICE_CLASS_SHUTTER


async def async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
Expand All @@ -31,8 +37,10 @@ class DynaliteCover(DynaliteBase, CoverEntity):
def device_class(self) -> str:
"""Return the class of the device."""
dev_cls = self._device.device_class
assert dev_cls in DEVICE_CLASSES
return dev_cls
ret_val = DEFAULT_COVER_CLASS
if dev_cls in DEVICE_CLASSES:
ret_val = dev_cls
return ret_val

@property
def current_cover_position(self) -> int:
Expand Down

0 comments on commit 1edbdcb

Please sign in to comment.