Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f95b35b
Added InvertedRflinkCover class to support COCO/KAKU ASUN-650 devices
fmartens Apr 18, 2019
3537d7a
Rename TYPE_NORMAL to TYPE_STANDARD
fmartens Apr 21, 2019
8e6cfc6
Cleaning up code and removed unused imports
fmartens Apr 21, 2019
b1e0f05
Added unit tests for InvertedRflinkCover
fmartens Apr 21, 2019
3fddfd3
less if/else statements
javicalle Apr 21, 2019
db12205
Autoresolve type for newkaku
javicalle Apr 21, 2019
801fbd9
Merge pull request #1 from javicalle/InvertedRflinkCover
fmartens Apr 28, 2019
edf8414
Updated tests for InvertedRflinkCover
fmartens Aug 11, 2019
75f33ff
Added unit test for standard cover without specifying type
fmartens Aug 11, 2019
dd1fab2
Updated comments in unit tests
fmartens Aug 11, 2019
2e564be
Updated unit test configuration and comments to be more explanatory
fmartens Aug 11, 2019
08136d4
Restore variable names in first part of the unit test that have been …
fmartens Aug 11, 2019
c9676ba
Reformated the code according to 4de97ab
fmartens Aug 18, 2019
232f8c2
Merge branch 'dev' into InvertedRflinkCover
fmartens Aug 18, 2019
88419e6
remove blank lines at end of rflink test_cover.py
fmartens Aug 18, 2019
9d5cb1a
Replace single with double quote in test_cover.py
fmartens Aug 18, 2019
30df21b
Replaced single quotes with double qoutes and fixed formatting
fmartens Aug 18, 2019
39aa119
Black improvements
fmartens Aug 18, 2019
7ca40ac
Reformated the code of the unit test.
fmartens Aug 18, 2019
28be75b
entity_type_for_device_id should return 'TYPE_STANDARD' instead of 'N…
fmartens Sep 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions homeassistant/components/rflink/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import voluptuous as vol

from homeassistant.components.cover import PLATFORM_SCHEMA, CoverDevice
from homeassistant.const import CONF_NAME, STATE_OPEN
from homeassistant.const import CONF_NAME, CONF_TYPE, STATE_OPEN
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity

Expand All @@ -23,6 +23,8 @@

_LOGGER = logging.getLogger(__name__)

TYPE_STANDARD = "standard"
TYPE_INVERTED = "inverted"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand All @@ -33,6 +35,7 @@
{
cv.string: {
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_TYPE): vol.Any(TYPE_STANDARD, TYPE_INVERTED),
vol.Optional(CONF_ALIASES, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
Expand All @@ -52,12 +55,51 @@
)


def entity_type_for_device_id(device_id):
"""Return entity class for protocol of a given device_id.

Async friendly.
"""
entity_type_mapping = {
# KlikAanKlikUit cover have the controls inverted
"newkaku": TYPE_INVERTED
}
protocol = device_id.split("_")[0]
return entity_type_mapping.get(protocol, TYPE_STANDARD)


def entity_class_for_type(entity_type):
"""Translate entity type to entity class.

Async friendly.
"""
entity_device_mapping = {
# default cover implementation
TYPE_STANDARD: RflinkCover,
# cover with open/close commands inverted
# like KAKU/COCO ASUN-650
TYPE_INVERTED: InvertedRflinkCover,
}

return entity_device_mapping.get(entity_type, RflinkCover)


def devices_from_config(domain_config):
"""Parse configuration and add Rflink cover devices."""
devices = []
for device_id, config in domain_config[CONF_DEVICES].items():
# Determine what kind of entity to create, RflinkCover
# or InvertedRflinkCover
if CONF_TYPE in config:
# Remove type from config to not pass it as and argument
# to entity instantiation
entity_type = config.pop(CONF_TYPE)
else:
entity_type = entity_type_for_device_id(device_id)

entity_class = entity_class_for_type(entity_type)
device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config)
device = RflinkCover(device_id, **device_config)
device = entity_class(device_id, **device_config)
devices.append(device)

return devices
Expand Down Expand Up @@ -115,3 +157,13 @@ def async_open_cover(self, **kwargs):
def async_stop_cover(self, **kwargs):
"""Turn the device stop."""
return self._async_handle_command("stop_cover")


class InvertedRflinkCover(RflinkCover):
"""Rflink cover that has inverted open/close commands."""

async def _async_send_command(self, cmd, repetitions):
"""Will invert only the UP/DOWN commands."""
_LOGGER.debug("Getting command: %s for Rflink device: %s", cmd, self._device_id)
cmd_inv = {"UP": "DOWN", "DOWN": "UP"}
await super()._async_send_command(cmd_inv.get(cmd, cmd), repetitions)
Loading