From f95b35b0be8ba7061413d5ad2c278bc960ce9c08 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Thu, 18 Apr 2019 23:31:26 +0200 Subject: [PATCH 01/18] Added InvertedRflinkCover class to support COCO/KAKU ASUN-650 devices --- homeassistant/components/rflink/cover.py | 53 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index d78fe8312e72c..fb5d0d15c0aa2 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -3,8 +3,9 @@ import voluptuous as vol +from homeassistant.components.cover import SUPPORT_OPEN, SUPPORT_CLOSE 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 @@ -15,6 +16,8 @@ _LOGGER = logging.getLogger(__name__) +TYPE_NORMAL = 'normal' +TYPE_INVERTED = 'inverted' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})): @@ -22,6 +25,8 @@ vol.Optional(CONF_DEVICES, default={}): vol.Schema({ cv.string: { vol.Optional(CONF_NAME): cv.string, + vol.Optional(CONF_TYPE): + vol.Any(TYPE_NORMAL, TYPE_INVERTED), vol.Optional(CONF_ALIASES, default=[]): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_GROUP_ALIASES, default=[]): @@ -36,12 +41,38 @@ }) +def entity_class_for_type(entity_type): + """Translate entity type to entity class. + + Async friendly. + """ + entity_device_mapping = { + # default cover implementation + TYPE_NORMAL: 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 = TYPE_NORMAL + + 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 @@ -100,3 +131,21 @@ 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) + if cmd == 'DOWN': + cmmnd = 'UP' + elif cmd == 'UP': + cmmnd = 'DOWN' + else: + cmmnd = cmd + + await super()._async_send_command(cmmnd, repetitions) + From 3537d7a69e0d0e70aecde02f233af60ba000c512 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 21 Apr 2019 11:27:41 +0200 Subject: [PATCH 02/18] Rename TYPE_NORMAL to TYPE_STANDARD --- homeassistant/components/rflink/cover.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index fb5d0d15c0aa2..da63960cf4dbb 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) -TYPE_NORMAL = 'normal' +TYPE_STANDARD = 'standard' TYPE_INVERTED = 'inverted' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ @@ -26,7 +26,7 @@ cv.string: { vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_TYPE): - vol.Any(TYPE_NORMAL, TYPE_INVERTED), + vol.Any(TYPE_STANDARD, TYPE_INVERTED), vol.Optional(CONF_ALIASES, default=[]): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_GROUP_ALIASES, default=[]): @@ -48,7 +48,7 @@ def entity_class_for_type(entity_type): """ entity_device_mapping = { # default cover implementation - TYPE_NORMAL: RflinkCover, + TYPE_STANDARD: RflinkCover, # cover with open/close commands inverted # like KAKU/COCO ASUN-650 TYPE_INVERTED: InvertedRflinkCover, @@ -68,7 +68,7 @@ def devices_from_config(domain_config): # to entity instantiation entity_type = config.pop(CONF_TYPE) else: - entity_type = TYPE_NORMAL + entity_type = TYPE_STANDARD entity_class = entity_class_for_type(entity_type) device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config) From 8e6cfc6ae402f661df90d43786dda68d85d2ecd7 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 21 Apr 2019 20:05:22 +0200 Subject: [PATCH 03/18] Cleaning up code and removed unused imports --- homeassistant/components/rflink/cover.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index da63960cf4dbb..a85d9c20a4f4e 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -3,7 +3,6 @@ import voluptuous as vol -from homeassistant.components.cover import SUPPORT_OPEN, SUPPORT_CLOSE from homeassistant.components.cover import PLATFORM_SCHEMA, CoverDevice from homeassistant.const import CONF_NAME, CONF_TYPE, STATE_OPEN import homeassistant.helpers.config_validation as cv @@ -62,7 +61,7 @@ def devices_from_config(domain_config): devices = [] for device_id, config in domain_config[CONF_DEVICES].items(): # Determine what kind of entity to create, RflinkCover - # or InvertedRflinkCover + # or InvertedRflinkCover if CONF_TYPE in config: # Remove type from config to not pass it as and argument # to entity instantiation @@ -148,4 +147,3 @@ async def _async_send_command(self, cmd, repetitions): cmmnd = cmd await super()._async_send_command(cmmnd, repetitions) - From b1e0f052a04963733ed95eb72b6c0979cc708fa3 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 21 Apr 2019 20:06:49 +0200 Subject: [PATCH 04/18] Added unit tests for InvertedRflinkCover --- tests/components/rflink/test_cover.py | 146 ++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index d531574d34f06..0b248a62df547 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -468,3 +468,149 @@ async def test_restore_state(hass, monkeypatch): assert state assert state.state == STATE_CLOSED assert state.attributes['assumed_state'] + + +async def test_inverted_cover(hass, monkeypatch): + """Ensure states are restored on startup.""" + config = { + 'rflink': { + 'port': '/dev/ttyABC0', + }, + DOMAIN: { + 'platform': 'rflink', + 'devices': { + 'test_inverted_1': { + 'name': 'standard', + 'type': 'standard' + }, + 'test_inverted_2': { + 'name': 'inverted', + 'type': 'inverted' + }, + }, + }, + } + + # setup mocking rflink module + event_callback, _, protocol, _ = await mock_rflink( + hass, config, DOMAIN, monkeypatch) + + # test default state of cover loaded from config + standard_cover = hass.states.get(DOMAIN + '.standard') + assert standard_cover.state == STATE_CLOSED + assert standard_cover.attributes['assumed_state'] + + # mock incoming up command event for all devices + event_callback({ + 'id': 'test_inverted_1', + 'command': 'up' + }) + await hass.async_block_till_done() + + standard_cover = hass.states.get(DOMAIN + '.standard') + assert standard_cover.state == STATE_OPEN + assert standard_cover.attributes.get('assumed_state') + + # mock incoming up command event for all devices + event_callback({ + 'id': 'test_inverted_2', + 'command': 'up' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted') + assert inverted_cover.state == STATE_OPEN + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming up command event for all devices + event_callback({ + 'id': 'test_inverted_1', + 'command': 'down' + }) + + await hass.async_block_till_done() + + standard_cover = hass.states.get(DOMAIN + '.standard') + assert standard_cover.state == STATE_CLOSED + assert standard_cover.attributes.get('assumed_state') + + event_callback({ + 'id': 'test_inverted_2', + 'command': 'down' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted') + assert inverted_cover.state == STATE_CLOSED + assert inverted_cover.attributes.get('assumed_state') + + # We are only testing the inverted device, the 'standard' device + # is already covered by other test cases. + + # should respond to group command + event_callback({ + 'id': 'test_inverted_2', + 'command': 'alloff', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted') + assert inverted_cover.state == STATE_CLOSED + + # should respond to group command + event_callback({ + 'id': 'test_inverted_2', + 'command': 'allon', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted') + assert inverted_cover.state == STATE_OPEN + + # Sending the close command from HA should result + # in an 'UP' command sent to the inverted device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[0][0][0] == 'test_inverted_2' + assert protocol.send_command_ack.call_args_list[0][0][1] == 'UP' + + # Sending the open command from HA should result + # in an 'DOWN' command sent to the inverted device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[1][0][0] == 'test_inverted_2' + assert protocol.send_command_ack.call_args_list[1][0][1] == 'DOWN' + + # Sending the close command from HA should result + # in an 'UP' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.standard').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[2][0][0] == 'test_inverted_1' + assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' + + # Sending the open command from HA should result + # in an 'DOWN' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.standard').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[3][0][0] == 'test_inverted_1' + assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' From 3fddfd3365fb9db0859477560234c956024215b1 Mon Sep 17 00:00:00 2001 From: javicalle Date: Mon, 22 Apr 2019 01:34:48 +0200 Subject: [PATCH 05/18] less if/else statements --- homeassistant/components/rflink/cover.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index a85d9c20a4f4e..6386e4f411f67 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -139,11 +139,8 @@ 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) - if cmd == 'DOWN': - cmmnd = 'UP' - elif cmd == 'UP': - cmmnd = 'DOWN' - else: - cmmnd = cmd - - await super()._async_send_command(cmmnd, repetitions) + cmd_inv = { + 'UP': 'DOWN', + 'DOWN': 'UP', + } + await super()._async_send_command(cmd_inv.get(cmd, cmd), repetitions) From db12205417ac233e7a18abd933b870a5e23c9e77 Mon Sep 17 00:00:00 2001 From: javicalle Date: Mon, 22 Apr 2019 01:44:33 +0200 Subject: [PATCH 06/18] Autoresolve type for newkaku --- homeassistant/components/rflink/cover.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index 6386e4f411f67..c85109181e16f 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -40,6 +40,19 @@ }) +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, None) + + def entity_class_for_type(entity_type): """Translate entity type to entity class. @@ -67,7 +80,7 @@ def devices_from_config(domain_config): # to entity instantiation entity_type = config.pop(CONF_TYPE) else: - entity_type = TYPE_STANDARD + 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) From edf8414690a86803a232999749c5a9618562924c Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 11 Aug 2019 15:28:51 +0200 Subject: [PATCH 07/18] Updated tests for InvertedRflinkCover --- tests/components/rflink/test_cover.py | 294 ++++++++++++++++++++++---- 1 file changed, 257 insertions(+), 37 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 0b248a62df547..df2d8047d8c80 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -470,6 +470,9 @@ async def test_restore_state(hass, monkeypatch): assert state.attributes['assumed_state'] +# The code checks the ID, it will use the +# 'inverted' class when the name starts with +# 'newkaku' async def test_inverted_cover(hass, monkeypatch): """Ensure states are restored on startup.""" config = { @@ -479,12 +482,23 @@ async def test_inverted_cover(hass, monkeypatch): DOMAIN: { 'platform': 'rflink', 'devices': { - 'test_inverted_1': { - 'name': 'standard', + 'device_test_1': { + 'name': 'cover_is_standard', 'type': 'standard' }, - 'test_inverted_2': { - 'name': 'inverted', + 'device_test_2': { + 'name': 'cover_is_inverted', + 'type': 'inverted' + }, + 'newkaku_test_3': { + 'name': 'inverted_cover_is_standard', + 'type': 'standard' + }, + 'newkaku_test_4': { + 'name': 'inverted_cover_is_none' + }, + 'newkaku_test_5': { + 'name': 'inverted_cover_is_inverted', 'type': 'inverted' }, }, @@ -496,53 +510,126 @@ async def test_inverted_cover(hass, monkeypatch): hass, config, DOMAIN, monkeypatch) # test default state of cover loaded from config - standard_cover = hass.states.get(DOMAIN + '.standard') + standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') assert standard_cover.state == STATE_CLOSED assert standard_cover.attributes['assumed_state'] - # mock incoming up command event for all devices + # mock incoming up command event for device_test_1 event_callback({ - 'id': 'test_inverted_1', + 'id': 'device_test_1', 'command': 'up' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.standard') + standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') assert standard_cover.state == STATE_OPEN assert standard_cover.attributes.get('assumed_state') - # mock incoming up command event for all devices + # mock incoming up command event for device_test_2 event_callback({ - 'id': 'test_inverted_2', + 'id': 'device_test_2', 'command': 'up' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted') + inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for all devices + # mock incoming up command event for device_test_3 event_callback({ - 'id': 'test_inverted_1', + 'id': 'newkaku_test_3', + 'command': 'up' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + assert inverted_cover.state == STATE_OPEN + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming up command event for device_test_4 + event_callback({ + 'id': 'newkaku_test_4', + 'command': 'up' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + assert inverted_cover.state == STATE_OPEN + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming up command event for device_test_5 + event_callback({ + 'id': 'newkaku_test_5', + 'command': 'up' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + assert inverted_cover.state == STATE_OPEN + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming down command event for device_test_1 + event_callback({ + 'id': 'device_test_1', 'command': 'down' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.standard') + standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') assert standard_cover.state == STATE_CLOSED assert standard_cover.attributes.get('assumed_state') + # mock incoming down command event for device_test_2 + event_callback({ + 'id': 'device_test_2', + 'command': 'down' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + assert inverted_cover.state == STATE_CLOSED + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming down command event for device_test_3 event_callback({ - 'id': 'test_inverted_2', + 'id': 'newkaku_test_3', 'command': 'down' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted') + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + assert inverted_cover.state == STATE_CLOSED + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming down command event for device_test_4 + event_callback({ + 'id': 'newkaku_test_4', + 'command': 'down' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + assert inverted_cover.state == STATE_CLOSED + assert inverted_cover.attributes.get('assumed_state') + + # mock incoming down command event for device_test_5 + event_callback({ + 'id': 'newkaku_test_5', + 'command': 'down' + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') @@ -551,66 +638,199 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'test_inverted_2', + 'id': 'device_test_2', + 'command': 'alloff', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + assert inverted_cover.state == STATE_CLOSED + + # should respond to group command + event_callback({ + 'id': 'device_test_2', + 'command': 'allon', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + assert inverted_cover.state == STATE_OPEN + + # should respond to group command + event_callback({ + 'id': 'newkaku_test_3', + 'command': 'alloff', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + assert inverted_cover.state == STATE_CLOSED + + # should respond to group command + event_callback({ + 'id': 'newkaku_test_3', + 'command': 'allon', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + assert inverted_cover.state == STATE_OPEN + + # should respond to group command + event_callback({ + 'id': 'newkaku_test_4', 'command': 'alloff', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted') + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') assert inverted_cover.state == STATE_CLOSED # should respond to group command event_callback({ - 'id': 'test_inverted_2', + 'id': 'newkaku_test_4', 'command': 'allon', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted') + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + assert inverted_cover.state == STATE_OPEN + + # should respond to group command + event_callback({ + 'id': 'newkaku_test_5', + 'command': 'alloff', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + assert inverted_cover.state == STATE_CLOSED + + # should respond to group command + event_callback({ + 'id': 'newkaku_test_5', + 'command': 'allon', + }) + + await hass.async_block_till_done() + + inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') assert inverted_cover.state == STATE_OPEN + # Sending the close command from HA should result + # in an 'DOWN' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.cover_is_standard').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[0][0][0] == 'device_test_1' + assert protocol.send_command_ack.call_args_list[0][0][1] == 'DOWN' + + # Sending the open command from HA should result + # in an 'UP' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.cover_is_standard').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[1][0][0] == 'device_test_1' + assert protocol.send_command_ack.call_args_list[1][0][1] == 'UP' + # Sending the close command from HA should result # in an 'UP' command sent to the inverted device. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[0][0][0] == 'test_inverted_2' - assert protocol.send_command_ack.call_args_list[0][0][1] == 'UP' + assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[2][0][0] == 'device_test_2' + assert protocol.send_command_ack.call_args_list[2][0][1] == 'UP' # Sending the open command from HA should result # in an 'DOWN' command sent to the inverted device. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[1][0][0] == 'test_inverted_2' - assert protocol.send_command_ack.call_args_list[1][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[3][0][0] == 'device_test_2' + assert protocol.send_command_ack.call_args_list[3][0][1] == 'DOWN' # Sending the close command from HA should result + # in an 'DOWN' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[4][0][0] == 'newkaku_test_3' + assert protocol.send_command_ack.call_args_list[4][0][1] == 'DOWN' + + # Sending the open command from HA should result # in an 'UP' command sent to the standard device. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.standard'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[5][0][0] == 'newkaku_test_3' + assert protocol.send_command_ack.call_args_list[5][0][1] == 'UP' + + # Sending the close command from HA should result + # in an 'UP' command sent to the inverted device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[2][0][0] == 'test_inverted_1' - assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_test_4' + assert protocol.send_command_ack.call_args_list[6][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the standard device. + # in an 'DOWN' command sent to the inverted device. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.standard'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[3][0][0] == 'test_inverted_1' - assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' + assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_test_4' + assert protocol.send_command_ack.call_args_list[7][0][1] == 'DOWN' + + # Sending the close command from HA should result + # in an 'UP' command sent to the inverted device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_test_5' + assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' + + # Sending the open command from HA should result + # in an 'DOWN' command sent to the inverted device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_test_5' + assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' + From 75f33ff77d74df3a6f9cb282ed5e441259f68b6c Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 11 Aug 2019 16:39:47 +0200 Subject: [PATCH 08/18] Added unit test for standard cover without specifying type --- tests/components/rflink/test_cover.py | 126 ++++++++++++++++++-------- 1 file changed, 87 insertions(+), 39 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index df2d8047d8c80..d5035d962b3d5 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -487,17 +487,20 @@ async def test_inverted_cover(hass, monkeypatch): 'type': 'standard' }, 'device_test_2': { + 'name': 'cover_is_none' + }, + 'device_test_3': { 'name': 'cover_is_inverted', 'type': 'inverted' }, - 'newkaku_test_3': { + 'newkaku_test_4': { 'name': 'inverted_cover_is_standard', 'type': 'standard' }, - 'newkaku_test_4': { + 'newkaku_test_5': { 'name': 'inverted_cover_is_none' }, - 'newkaku_test_5': { + 'newkaku_test_6': { 'name': 'inverted_cover_is_inverted', 'type': 'inverted' }, @@ -530,6 +533,17 @@ async def test_inverted_cover(hass, monkeypatch): 'id': 'device_test_2', 'command': 'up' }) + await hass.async_block_till_done() + + standard_cover = hass.states.get(DOMAIN + '.cover_is_none') + assert standard_cover.state == STATE_OPEN + assert standard_cover.attributes.get('assumed_state') + + # mock incoming up command event for device_test_3 + event_callback({ + 'id': 'device_test_3', + 'command': 'up' + }) await hass.async_block_till_done() @@ -537,9 +551,9 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for device_test_3 + # mock incoming up command event for newkaku_test_4 event_callback({ - 'id': 'newkaku_test_3', + 'id': 'newkaku_test_4', 'command': 'up' }) @@ -549,9 +563,9 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for device_test_4 + # mock incoming up command event for newkaku_test_5 event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_test_5', 'command': 'up' }) @@ -561,9 +575,9 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for device_test_5 + # mock incoming up command event for newkaku_test_6 event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_test_6', 'command': 'up' }) @@ -593,13 +607,25 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() + standard_cover = hass.states.get(DOMAIN + '.cover_is_none') + assert standard_cover.state == STATE_CLOSED + assert standard_cover.attributes.get('assumed_state') + + # mock incoming down command event for device_test_3 + event_callback({ + 'id': 'device_test_3', + 'command': 'down' + }) + + await hass.async_block_till_done() + inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_3 + # mock incoming down command event for newkaku_test_4 event_callback({ - 'id': 'newkaku_test_3', + 'id': 'newkaku_test_4', 'command': 'down' }) @@ -609,9 +635,9 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_4 + # mock incoming down command event for newkaku_test_5 event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_test_5', 'command': 'down' }) @@ -621,9 +647,9 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_5 + # mock incoming down command event for newkaku_test_6 event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_test_6', 'command': 'down' }) @@ -638,7 +664,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'device_test_2', + 'id': 'device_test_3', 'command': 'alloff', }) @@ -649,7 +675,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'device_test_2', + 'id': 'device_test_3', 'command': 'allon', }) @@ -660,7 +686,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_3', + 'id': 'newkaku_test_4', 'command': 'alloff', }) @@ -671,7 +697,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_3', + 'id': 'newkaku_test_4', 'command': 'allon', }) @@ -682,7 +708,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_test_5', 'command': 'alloff', }) @@ -693,7 +719,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_test_5', 'command': 'allon', }) @@ -704,7 +730,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_test_6', 'command': 'alloff', }) @@ -715,7 +741,7 @@ async def test_inverted_cover(hass, monkeypatch): # should respond to group command event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_test_6', 'command': 'allon', }) @@ -746,6 +772,28 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[1][0][0] == 'device_test_1' assert protocol.send_command_ack.call_args_list[1][0][1] == 'UP' + # Sending the close command from HA should result + # in an 'DOWN' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.cover_is_none').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[2][0][0] == 'device_test_2' + assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' + + # Sending the open command from HA should result + # in an 'UP' command sent to the standard device. + hass.async_create_task(hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) + + await hass.async_block_till_done() + + assert hass.states.get(DOMAIN + '.cover_is_none').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[3][0][0] == 'device_test_2' + assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' + # Sending the close command from HA should result # in an 'UP' command sent to the inverted device. hass.async_create_task(hass.services.async_call( @@ -754,8 +802,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[2][0][0] == 'device_test_2' - assert protocol.send_command_ack.call_args_list[2][0][1] == 'UP' + assert protocol.send_command_ack.call_args_list[4][0][0] == 'device_test_3' + assert protocol.send_command_ack.call_args_list[4][0][1] == 'UP' # Sending the open command from HA should result # in an 'DOWN' command sent to the inverted device. @@ -765,8 +813,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[3][0][0] == 'device_test_2' - assert protocol.send_command_ack.call_args_list[3][0][1] == 'DOWN' + assert protocol.send_command_ack.call_args_list[5][0][0] == 'device_test_3' + assert protocol.send_command_ack.call_args_list[5][0][1] == 'DOWN' # Sending the close command from HA should result # in an 'DOWN' command sent to the standard device. @@ -776,8 +824,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[4][0][0] == 'newkaku_test_3' - assert protocol.send_command_ack.call_args_list[4][0][1] == 'DOWN' + assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_test_4' + assert protocol.send_command_ack.call_args_list[6][0][1] == 'DOWN' # Sending the open command from HA should result # in an 'UP' command sent to the standard device. @@ -787,8 +835,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[5][0][0] == 'newkaku_test_3' - assert protocol.send_command_ack.call_args_list[5][0][1] == 'UP' + assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_test_4' + assert protocol.send_command_ack.call_args_list[7][0][1] == 'UP' # Sending the close command from HA should result # in an 'UP' command sent to the inverted device. @@ -798,8 +846,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_test_4' - assert protocol.send_command_ack.call_args_list[6][0][1] == 'UP' + assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_test_5' + assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' # Sending the open command from HA should result # in an 'DOWN' command sent to the inverted device. @@ -809,8 +857,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_test_4' - assert protocol.send_command_ack.call_args_list[7][0][1] == 'DOWN' + assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_test_5' + assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' # Sending the close command from HA should result # in an 'UP' command sent to the inverted device. @@ -820,8 +868,8 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_test_5' - assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' + assert protocol.send_command_ack.call_args_list[10][0][0] == 'newkaku_test_6' + assert protocol.send_command_ack.call_args_list[10][0][1] == 'UP' # Sending the open command from HA should result # in an 'DOWN' command sent to the inverted device. @@ -831,6 +879,6 @@ async def test_inverted_cover(hass, monkeypatch): await hass.async_block_till_done() assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_test_5' - assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' + assert protocol.send_command_ack.call_args_list[11][0][0] == 'newkaku_test_6' + assert protocol.send_command_ack.call_args_list[11][0][1] == 'DOWN' From dd1fab2918c04b3a3cdb5db754a8a2598e85ddc7 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 11 Aug 2019 16:55:45 +0200 Subject: [PATCH 09/18] Updated comments in unit tests --- tests/components/rflink/test_cover.py | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index d5035d962b3d5..75c688c7c270d 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -751,7 +751,8 @@ async def test_inverted_cover(hass, monkeypatch): assert inverted_cover.state == STATE_OPEN # Sending the close command from HA should result - # in an 'DOWN' command sent to the standard device. + # in an 'DOWN' command sent to the 'RflinkCover' + # device that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) @@ -762,7 +763,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[0][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the standard device. + # in an 'UP' command sent to the 'RflinkCover' + # device that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) @@ -773,7 +775,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[1][0][1] == 'UP' # Sending the close command from HA should result - # in an 'DOWN' command sent to the standard device. + # in an 'DOWN' command sent to the 'RflinkCover' + # device that has its type not specified. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) @@ -784,7 +787,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the standard device. + # in an 'UP' command sent to the 'RflinkCover' + # device that has its type not specified. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) @@ -795,7 +799,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' # Sending the close command from HA should result - # in an 'UP' command sent to the inverted device. + # in an 'UP' command sent to the 'RflinkCover' + # device that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) @@ -806,7 +811,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[4][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the inverted device. + # in an 'DOWN' command sent to the 'RflinkCover' + # device that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) @@ -817,7 +823,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[5][0][1] == 'DOWN' # Sending the close command from HA should result - # in an 'DOWN' command sent to the standard device. + # in an 'DOWN' command sent to the 'InvertedRflinkCover' + # device that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) @@ -828,7 +835,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[6][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the standard device. + # in an 'UP' command sent to the 'InvertedRflinkCover' + # device that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) @@ -839,7 +847,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[7][0][1] == 'UP' # Sending the close command from HA should result - # in an 'UP' command sent to the inverted device. + # in an 'UP' command sent to the 'InvertedRflinkCover' + # device that has its type not specified. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) @@ -850,7 +859,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the inverted device. + # in an 'DOWN' command sent to the 'InvertedRflinkCover' + # device that has its type not specified. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) @@ -861,7 +871,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' # Sending the close command from HA should result - # in an 'UP' command sent to the inverted device. + # in an 'UP' command sent to the 'InvertedRflinkCover' + # device that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) @@ -872,7 +883,8 @@ async def test_inverted_cover(hass, monkeypatch): assert protocol.send_command_ack.call_args_list[10][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the inverted device. + # in an 'DOWN' command sent to the 'InvertedRflinkCover' + # device that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) From 2e564be5d28a045b8695690164f3c6c60900b881 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 11 Aug 2019 20:47:49 +0200 Subject: [PATCH 10/18] Updated unit test configuration and comments to be more explanatory --- tests/components/rflink/test_cover.py | 276 +++++++++++++------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 75c688c7c270d..4ad4b17741487 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -30,11 +30,11 @@ 'name': 'test', 'aliases': ['test_alias_0_0'], }, - 'cover_0_0': { + 'nonkaku_0_0': { 'name': 'dim_test', }, - 'cover_0_1': { - 'name': 'cover_test', + 'nonkaku_0_1': { + 'name': 'nonkaku_test', } }, }, @@ -53,9 +53,9 @@ async def test_default_setup(hass, monkeypatch): assert create.call_args_list[0][1]['ignore'] # test default state of cover loaded from config - cover_initial = hass.states.get(DOMAIN + '.test') - assert cover_initial.state == STATE_CLOSED - assert cover_initial.attributes['assumed_state'] + nonkaku_initial = hass.states.get(DOMAIN + '.test') + assert nonkaku_initial.state == STATE_CLOSED + assert nonkaku_initial.attributes['assumed_state'] # cover should follow state of the hardware device by interpreting # incoming events for its name and aliases @@ -67,10 +67,10 @@ async def test_default_setup(hass, monkeypatch): }) await hass.async_block_till_done() - cover_after_first_command = hass.states.get(DOMAIN + '.test') - assert cover_after_first_command.state == STATE_OPEN + nonkaku_after_first_command = hass.states.get(DOMAIN + '.test') + assert nonkaku_after_first_command.state == STATE_OPEN # not sure why, but cover have always assumed_state=true - assert cover_after_first_command.attributes.get('assumed_state') + assert nonkaku_after_first_command.attributes.get('assumed_state') # mock incoming command event for this device event_callback({ @@ -88,8 +88,8 @@ async def test_default_setup(hass, monkeypatch): }) await hass.async_block_till_done() - cover_after_first_command = hass.states.get(DOMAIN + '.test') - assert cover_after_first_command.state == STATE_OPEN + nonkaku_after_first_command = hass.states.get(DOMAIN + '.test') + assert nonkaku_after_first_command.state == STATE_OPEN # should respond to group command event_callback({ @@ -482,26 +482,26 @@ async def test_inverted_cover(hass, monkeypatch): DOMAIN: { 'platform': 'rflink', 'devices': { - 'device_test_1': { - 'name': 'cover_is_standard', + 'nonkaku_device_1': { + 'name': 'nonkaku_type_standard', 'type': 'standard' }, - 'device_test_2': { - 'name': 'cover_is_none' + 'nonkaku_device_2': { + 'name': 'nonkaku_type_none' }, - 'device_test_3': { - 'name': 'cover_is_inverted', + 'nonkaku_device_3': { + 'name': 'nonkaku_type_inverted', 'type': 'inverted' }, - 'newkaku_test_4': { - 'name': 'inverted_cover_is_standard', + 'newkaku_device_4': { + 'name': 'newkaku_type_standard', 'type': 'standard' }, - 'newkaku_test_5': { - 'name': 'inverted_cover_is_none' + 'newkaku_device_5': { + 'name': 'newkaku_type_none' }, - 'newkaku_test_6': { - 'name': 'inverted_cover_is_inverted', + 'newkaku_device_6': { + 'name': 'newkaku_type_inverted', 'type': 'inverted' }, }, @@ -513,384 +513,384 @@ async def test_inverted_cover(hass, monkeypatch): hass, config, DOMAIN, monkeypatch) # test default state of cover loaded from config - standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') + standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') assert standard_cover.state == STATE_CLOSED assert standard_cover.attributes['assumed_state'] - # mock incoming up command event for device_test_1 + # mock incoming up command event for nonkaku_device_1 event_callback({ - 'id': 'device_test_1', + 'id': 'nonkaku_device_1', 'command': 'up' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') + standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') assert standard_cover.state == STATE_OPEN assert standard_cover.attributes.get('assumed_state') - # mock incoming up command event for device_test_2 + # mock incoming up command event for nonkaku_device_2 event_callback({ - 'id': 'device_test_2', + 'id': 'nonkaku_device_2', 'command': 'up' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.cover_is_none') + standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_none') assert standard_cover.state == STATE_OPEN assert standard_cover.attributes.get('assumed_state') - # mock incoming up command event for device_test_3 + # mock incoming up command event for nonkaku_device_3 event_callback({ - 'id': 'device_test_3', + 'id': 'nonkaku_device_3', 'command': 'up' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for newkaku_test_4 + # mock incoming up command event for newkaku_device_4 event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_device_4', 'command': 'up' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for newkaku_test_5 + # mock incoming up command event for newkaku_device_5 event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_device_5', 'command': 'up' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming up command event for newkaku_test_6 + # mock incoming up command event for newkaku_device_6 event_callback({ - 'id': 'newkaku_test_6', + 'id': 'newkaku_device_6', 'command': 'up' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') assert inverted_cover.state == STATE_OPEN assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_1 + # mock incoming down command event for nonkaku_device_1 event_callback({ - 'id': 'device_test_1', + 'id': 'nonkaku_device_1', 'command': 'down' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.cover_is_standard') + standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') assert standard_cover.state == STATE_CLOSED assert standard_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_2 + # mock incoming down command event for nonkaku_device_2 event_callback({ - 'id': 'device_test_2', + 'id': 'nonkaku_device_2', 'command': 'down' }) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.cover_is_none') + standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_none') assert standard_cover.state == STATE_CLOSED assert standard_cover.attributes.get('assumed_state') - # mock incoming down command event for device_test_3 + # mock incoming down command event for nonkaku_device_3 event_callback({ - 'id': 'device_test_3', + 'id': 'nonkaku_device_3', 'command': 'down' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for newkaku_test_4 + # mock incoming down command event for newkaku_device_4 event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_device_4', 'command': 'down' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for newkaku_test_5 + # mock incoming down command event for newkaku_device_5 event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_device_5', 'command': 'down' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # mock incoming down command event for newkaku_test_6 + # mock incoming down command event for newkaku_device_6 event_callback({ - 'id': 'newkaku_test_6', + 'id': 'newkaku_device_6', 'command': 'down' }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') assert inverted_cover.state == STATE_CLOSED assert inverted_cover.attributes.get('assumed_state') - # We are only testing the inverted device, the 'standard' device - # is already covered by other test cases. + # We are only testing the 'inverted' devices, the 'standard' devices + # are already covered by other test cases. # should respond to group command event_callback({ - 'id': 'device_test_3', + 'id': 'nonkaku_device_3', 'command': 'alloff', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') assert inverted_cover.state == STATE_CLOSED # should respond to group command event_callback({ - 'id': 'device_test_3', + 'id': 'nonkaku_device_3', 'command': 'allon', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') assert inverted_cover.state == STATE_OPEN # should respond to group command event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_device_4', 'command': 'alloff', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') assert inverted_cover.state == STATE_CLOSED # should respond to group command event_callback({ - 'id': 'newkaku_test_4', + 'id': 'newkaku_device_4', 'command': 'allon', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_standard') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') assert inverted_cover.state == STATE_OPEN # should respond to group command event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_device_5', 'command': 'alloff', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') assert inverted_cover.state == STATE_CLOSED # should respond to group command event_callback({ - 'id': 'newkaku_test_5', + 'id': 'newkaku_device_5', 'command': 'allon', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_none') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') assert inverted_cover.state == STATE_OPEN # should respond to group command event_callback({ - 'id': 'newkaku_test_6', + 'id': 'newkaku_device_6', 'command': 'alloff', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') assert inverted_cover.state == STATE_CLOSED # should respond to group command event_callback({ - 'id': 'newkaku_test_6', + 'id': 'newkaku_device_6', 'command': 'allon', }) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.inverted_cover_is_inverted') + inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') assert inverted_cover.state == STATE_OPEN # Sending the close command from HA should result - # in an 'DOWN' command sent to the 'RflinkCover' - # device that has its type set to 'standard'. + # in an 'DOWN' command sent to a non-newkaku device + # that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_standard'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[0][0][0] == 'device_test_1' + assert hass.states.get(DOMAIN + '.nonkaku_type_standard').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[0][0][0] == 'nonkaku_device_1' assert protocol.send_command_ack.call_args_list[0][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the 'RflinkCover' - # device that has its type set to 'standard'. + # in an 'UP' command sent to a non-newkaku device + # that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_standard'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_standard'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[1][0][0] == 'device_test_1' + assert hass.states.get(DOMAIN + '.nonkaku_type_standard').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[1][0][0] == 'nonkaku_device_1' assert protocol.send_command_ack.call_args_list[1][0][1] == 'UP' # Sending the close command from HA should result - # in an 'DOWN' command sent to the 'RflinkCover' - # device that has its type not specified. + # in an 'DOWN' command sent to a non-newkaku device + # that has its type not specified. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_none').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[2][0][0] == 'device_test_2' + assert hass.states.get(DOMAIN + '.nonkaku_type_none').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[2][0][0] == 'nonkaku_device_2' assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the 'RflinkCover' - # device that has its type not specified. + # in an 'UP' command sent to a non-newkaku device + # that has its type not specified. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_none'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_none').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[3][0][0] == 'device_test_2' + assert hass.states.get(DOMAIN + '.nonkaku_type_none').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[3][0][0] == 'nonkaku_device_2' assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' # Sending the close command from HA should result - # in an 'UP' command sent to the 'RflinkCover' - # device that has its type set to 'inverted'. + # in an 'UP' command sent to a non-newkaku device + # that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[4][0][0] == 'device_test_3' + assert hass.states.get(DOMAIN + '.nonkaku_type_inverted').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[4][0][0] == 'nonkaku_device_3' assert protocol.send_command_ack.call_args_list[4][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the 'RflinkCover' - # device that has its type set to 'inverted'. + # in an 'DOWN' command sent to a non-newkaku device + # that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.cover_is_inverted'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.cover_is_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[5][0][0] == 'device_test_3' + assert hass.states.get(DOMAIN + '.nonkaku_type_inverted').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[5][0][0] == 'nonkaku_device_3' assert protocol.send_command_ack.call_args_list[5][0][1] == 'DOWN' # Sending the close command from HA should result - # in an 'DOWN' command sent to the 'InvertedRflinkCover' - # device that has its type set to 'standard'. + # in an 'DOWN' command sent to a newkaku device + # that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_standard'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_test_4' + assert hass.states.get(DOMAIN + '.newkaku_type_standard').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_device_4' assert protocol.send_command_ack.call_args_list[6][0][1] == 'DOWN' # Sending the open command from HA should result - # in an 'UP' command sent to the 'InvertedRflinkCover' - # device that has its type set to 'standard'. + # in an 'UP' command sent to a newkaku device + # that has its type set to 'standard'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_standard'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_standard'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_test_4' + assert hass.states.get(DOMAIN + '.newkaku_type_standard').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_device_4' assert protocol.send_command_ack.call_args_list[7][0][1] == 'UP' # Sending the close command from HA should result - # in an 'UP' command sent to the 'InvertedRflinkCover' - # device that has its type not specified. + # in an 'UP' command sent to a newkaku device + # that has its type not specified. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_test_5' + assert hass.states.get(DOMAIN + '.newkaku_type_none').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_device_5' assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the 'InvertedRflinkCover' - # device that has its type not specified. + # in an 'DOWN' command sent to a newkaku device + # that has its type not specified. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_none'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_none'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_none').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_test_5' + assert hass.states.get(DOMAIN + '.newkaku_type_none').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_device_5' assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' # Sending the close command from HA should result - # in an 'UP' command sent to the 'InvertedRflinkCover' - # device that has its type set to 'inverted'. + # in an 'UP' command sent to a newkaku device + # that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[10][0][0] == 'newkaku_test_6' + assert hass.states.get(DOMAIN + '.newkaku_type_inverted').state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[10][0][0] == 'newkaku_device_6' assert protocol.send_command_ack.call_args_list[10][0][1] == 'UP' # Sending the open command from HA should result - # in an 'DOWN' command sent to the 'InvertedRflinkCover' - # device that has its type set to 'inverted'. + # in an 'DOWN' command sent to a newkaku device + # that has its type set to 'inverted'. hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.inverted_cover_is_inverted'})) + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_inverted'})) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.inverted_cover_is_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[11][0][0] == 'newkaku_test_6' + assert hass.states.get(DOMAIN + '.newkaku_type_inverted').state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[11][0][0] == 'newkaku_device_6' assert protocol.send_command_ack.call_args_list[11][0][1] == 'DOWN' From 08136d472e0729776458dfe1c35851bc5c6db405 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 11 Aug 2019 21:01:45 +0200 Subject: [PATCH 11/18] Restore variable names in first part of the unit test that have been changed during a search and replace --- tests/components/rflink/test_cover.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 4ad4b17741487..b323f22c32e04 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -30,11 +30,11 @@ 'name': 'test', 'aliases': ['test_alias_0_0'], }, - 'nonkaku_0_0': { + 'cover_0_0': { 'name': 'dim_test', }, - 'nonkaku_0_1': { - 'name': 'nonkaku_test', + 'cover_0_1': { + 'name': 'cover_test', } }, }, @@ -53,9 +53,9 @@ async def test_default_setup(hass, monkeypatch): assert create.call_args_list[0][1]['ignore'] # test default state of cover loaded from config - nonkaku_initial = hass.states.get(DOMAIN + '.test') - assert nonkaku_initial.state == STATE_CLOSED - assert nonkaku_initial.attributes['assumed_state'] + cover_initial = hass.states.get(DOMAIN + '.test') + assert cover_initial.state == STATE_CLOSED + assert cover_initial.attributes['assumed_state'] # cover should follow state of the hardware device by interpreting # incoming events for its name and aliases @@ -67,10 +67,10 @@ async def test_default_setup(hass, monkeypatch): }) await hass.async_block_till_done() - nonkaku_after_first_command = hass.states.get(DOMAIN + '.test') - assert nonkaku_after_first_command.state == STATE_OPEN + cover_after_first_command = hass.states.get(DOMAIN + '.test') + assert cover_after_first_command.state == STATE_OPEN # not sure why, but cover have always assumed_state=true - assert nonkaku_after_first_command.attributes.get('assumed_state') + assert cover_after_first_command.attributes.get('assumed_state') # mock incoming command event for this device event_callback({ @@ -88,8 +88,8 @@ async def test_default_setup(hass, monkeypatch): }) await hass.async_block_till_done() - nonkaku_after_first_command = hass.states.get(DOMAIN + '.test') - assert nonkaku_after_first_command.state == STATE_OPEN + cover_after_first_command = hass.states.get(DOMAIN + '.test') + assert cover_after_first_command.state == STATE_OPEN # should respond to group command event_callback({ From c9676bae41931026b4cf04ae738faf7e530e09ad Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Sun, 18 Aug 2019 15:03:44 +0200 Subject: [PATCH 12/18] Reformated the code according to 4de97ab --- homeassistant/components/rflink/cover.py | 69 +++++++++++++++--------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index c85109181e16f..aace561c6b75d 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -9,35 +9,52 @@ from homeassistant.helpers.restore_state import RestoreEntity from . import ( - CONF_ALIASES, CONF_DEVICE_DEFAULTS, CONF_DEVICES, CONF_FIRE_EVENT, - CONF_GROUP, CONF_GROUP_ALIASES, CONF_NOGROUP_ALIASES, - CONF_SIGNAL_REPETITIONS, DEVICE_DEFAULTS_SCHEMA, RflinkCommand) + CONF_ALIASES, + CONF_DEVICE_DEFAULTS, + CONF_DEVICES, + CONF_FIRE_EVENT, + CONF_GROUP, + CONF_GROUP_ALIASES, + CONF_NOGROUP_ALIASES, + CONF_SIGNAL_REPETITIONS, + DEVICE_DEFAULTS_SCHEMA, + RflinkCommand +) _LOGGER = logging.getLogger(__name__) TYPE_STANDARD = 'standard' TYPE_INVERTED = 'inverted' -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})): - DEVICE_DEFAULTS_SCHEMA, - vol.Optional(CONF_DEVICES, default={}): vol.Schema({ - 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]), - vol.Optional(CONF_GROUP_ALIASES, default=[]): - vol.All(cv.ensure_list, [cv.string]), - vol.Optional(CONF_NOGROUP_ALIASES, default=[]): - vol.All(cv.ensure_list, [cv.string]), - vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean, - vol.Optional(CONF_SIGNAL_REPETITIONS): vol.Coerce(int), - vol.Optional(CONF_GROUP, default=True): cv.boolean, - }, - }), -}) +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( + { + vol.Optional( + CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({}) + ): DEVICE_DEFAULTS_SCHEMA, + vol.Optional(CONF_DEVICES, default={}): vol.Schema( + { + 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] + ), + vol.Optional(CONF_GROUP_ALIASES, default=[]): vol.All( + cv.ensure_list, [cv.string] + ), + vol.Optional(CONF_NOGROUP_ALIASES, default=[]): vol.All( + cv.ensure_list, [cv.string] + ), + vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean, + vol.Optional(CONF_SIGNAL_REPETITIONS): vol.Coerce(int), + vol.Optional(CONF_GROUP, default=True): cv.boolean, + }, + } + ), + } +) def entity_type_for_device_id(device_id): @@ -111,10 +128,10 @@ def _handle_event(self, event): """Adjust state if Rflink picks up a remote command for this device.""" self.cancel_queued_send_commands() - command = event['command'] - if command in ['on', 'allon', 'up']: + command = event["command"] + if command in ["on", "allon", "up"]: self._state = True - elif command in ['off', 'alloff', 'down']: + elif command in ["off", "alloff", "down"]: self._state = False @property From 88419e6838e22457da27cb4450d3fa9c58bce69b Mon Sep 17 00:00:00 2001 From: fmartens <17504441+fmartens@users.noreply.github.com> Date: Sun, 18 Aug 2019 21:59:00 +0200 Subject: [PATCH 13/18] remove blank lines at end of rflink test_cover.py --- tests/components/rflink/test_cover.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 44ce9f825d1b1..b48afb1c9f9dd 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -815,4 +815,3 @@ async def test_inverted_cover(hass, monkeypatch): assert hass.states.get(DOMAIN + '.newkaku_type_inverted').state == STATE_OPEN assert protocol.send_command_ack.call_args_list[11][0][0] == 'newkaku_device_6' assert protocol.send_command_ack.call_args_list[11][0][1] == 'DOWN' - From 9d5cb1a80b1d374cc5e8d67bacbe83d8238fdd3b Mon Sep 17 00:00:00 2001 From: fmartens <17504441+fmartens@users.noreply.github.com> Date: Sun, 18 Aug 2019 22:01:02 +0200 Subject: [PATCH 14/18] Replace single with double quote in test_cover.py --- tests/components/rflink/test_cover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index b48afb1c9f9dd..5ce9ed8d5ee42 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -389,7 +389,7 @@ async def test_restore_state(hass, monkeypatch): state = hass.states.get(DOMAIN + ".c4") assert state assert state.state == STATE_CLOSED - assert state.attributes['assumed_state'] + assert state.attributes["assumed_state"] # The code checks the ID, it will use the From 30df21b49e4d93f646a11b5e77eb0086eb9a7057 Mon Sep 17 00:00:00 2001 From: fmartens <17504441+fmartens@users.noreply.github.com> Date: Sun, 18 Aug 2019 23:49:31 +0200 Subject: [PATCH 15/18] Replaced single quotes with double qoutes and fixed formatting --- homeassistant/components/rflink/cover.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index db086efcf8a47..ccce7a1f19c99 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -23,8 +23,8 @@ _LOGGER = logging.getLogger(__name__) -TYPE_STANDARD = 'standard' -TYPE_INVERTED = 'inverted' +TYPE_STANDARD = "standard" +TYPE_INVERTED = "inverted" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { @@ -35,9 +35,7 @@ { cv.string: { vol.Optional(CONF_NAME): cv.string, - vol.Optional(CONF_TYPE): vol.Any( - TYPE_STANDARD, TYPE_INVERTED - ), + vol.Optional(CONF_TYPE): vol.Any(TYPE_STANDARD, TYPE_INVERTED), vol.Optional(CONF_ALIASES, default=[]): vol.All( cv.ensure_list, [cv.string] ), @@ -64,7 +62,7 @@ def entity_type_for_device_id(device_id): """ entity_type_mapping = { # KlikAanKlikUit cover have the controls inverted - 'newkaku': TYPE_INVERTED, + "newkaku": TYPE_INVERTED, } protocol = device_id.split('_')[0] return entity_type_mapping.get(protocol, None) @@ -166,10 +164,6 @@ class InvertedRflinkCover(RflinkCover): 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', - } + _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) From 39aa1198932275cf5d903fa30005d4c501d963a5 Mon Sep 17 00:00:00 2001 From: fmartens <17504441+fmartens@users.noreply.github.com> Date: Sun, 18 Aug 2019 23:58:59 +0200 Subject: [PATCH 16/18] Black improvements --- homeassistant/components/rflink/cover.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index ccce7a1f19c99..33a082be62745 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -62,9 +62,9 @@ def entity_type_for_device_id(device_id): """ entity_type_mapping = { # KlikAanKlikUit cover have the controls inverted - "newkaku": TYPE_INVERTED, + "newkaku": TYPE_INVERTED } - protocol = device_id.split('_')[0] + protocol = device_id.split("_")[0] return entity_type_mapping.get(protocol, None) From 7ca40acf5790b220f4fa2e4bda786884834f26d1 Mon Sep 17 00:00:00 2001 From: Freddy Martens <17504441+fmartens@users.noreply.github.com> Date: Mon, 19 Aug 2019 00:19:09 +0200 Subject: [PATCH 17/18] Reformated the code of the unit test. --- tests/components/rflink/test_cover.py | 383 +++++++++++++------------- 1 file changed, 185 insertions(+), 198 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 5ce9ed8d5ee42..858258e7efd0c 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -398,33 +398,27 @@ async def test_restore_state(hass, monkeypatch): async def test_inverted_cover(hass, monkeypatch): """Ensure states are restored on startup.""" config = { - 'rflink': { - 'port': '/dev/ttyABC0', - }, + "rflink": {"port": "/dev/ttyABC0"}, DOMAIN: { - 'platform': 'rflink', - 'devices': { - 'nonkaku_device_1': { - 'name': 'nonkaku_type_standard', - 'type': 'standard' - }, - 'nonkaku_device_2': { - 'name': 'nonkaku_type_none' - }, - 'nonkaku_device_3': { - 'name': 'nonkaku_type_inverted', - 'type': 'inverted' + "platform": "rflink", + "devices": { + "nonkaku_device_1": { + "name": "nonkaku_type_standard", + "type": "standard", }, - 'newkaku_device_4': { - 'name': 'newkaku_type_standard', - 'type': 'standard' + "nonkaku_device_2": {"name": "nonkaku_type_none"}, + "nonkaku_device_3": { + "name": "nonkaku_type_inverted", + "type": "inverted", }, - 'newkaku_device_5': { - 'name': 'newkaku_type_none' + "newkaku_device_4": { + "name": "newkaku_type_standard", + "type": "standard", }, - 'newkaku_device_6': { - 'name': 'newkaku_type_inverted', - 'type': 'inverted' + "newkaku_device_5": {"name": "newkaku_type_none"}, + "newkaku_device_6": { + "name": "newkaku_type_inverted", + "type": "inverted", }, }, }, @@ -432,386 +426,379 @@ async def test_inverted_cover(hass, monkeypatch): # setup mocking rflink module event_callback, _, protocol, _ = await mock_rflink( - hass, config, DOMAIN, monkeypatch) + hass, config, DOMAIN, monkeypatch + ) # test default state of cover loaded from config - standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') + standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard") assert standard_cover.state == STATE_CLOSED - assert standard_cover.attributes['assumed_state'] + assert standard_cover.attributes["assumed_state"] # mock incoming up command event for nonkaku_device_1 - event_callback({ - 'id': 'nonkaku_device_1', - 'command': 'up' - }) + event_callback({"id": "nonkaku_device_1", "command": "up"}) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') + standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard") assert standard_cover.state == STATE_OPEN - assert standard_cover.attributes.get('assumed_state') + assert standard_cover.attributes.get("assumed_state") # mock incoming up command event for nonkaku_device_2 - event_callback({ - 'id': 'nonkaku_device_2', - 'command': 'up' - }) + event_callback({"id": "nonkaku_device_2", "command": "up"}) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_none') + standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_none") assert standard_cover.state == STATE_OPEN - assert standard_cover.attributes.get('assumed_state') + assert standard_cover.attributes.get("assumed_state") # mock incoming up command event for nonkaku_device_3 - event_callback({ - 'id': 'nonkaku_device_3', - 'command': 'up' - }) + event_callback({"id": "nonkaku_device_3", "command": "up"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted") assert inverted_cover.state == STATE_OPEN - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming up command event for newkaku_device_4 - event_callback({ - 'id': 'newkaku_device_4', - 'command': 'up' - }) + event_callback({"id": "newkaku_device_4", "command": "up"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard") assert inverted_cover.state == STATE_OPEN - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming up command event for newkaku_device_5 - event_callback({ - 'id': 'newkaku_device_5', - 'command': 'up' - }) + event_callback({"id": "newkaku_device_5", "command": "up"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none") assert inverted_cover.state == STATE_OPEN - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming up command event for newkaku_device_6 - event_callback({ - 'id': 'newkaku_device_6', - 'command': 'up' - }) + event_callback({"id": "newkaku_device_6", "command": "up"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted") assert inverted_cover.state == STATE_OPEN - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming down command event for nonkaku_device_1 - event_callback({ - 'id': 'nonkaku_device_1', - 'command': 'down' - }) + event_callback({"id": "nonkaku_device_1", "command": "down"}) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_standard') + standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard") assert standard_cover.state == STATE_CLOSED - assert standard_cover.attributes.get('assumed_state') + assert standard_cover.attributes.get("assumed_state") # mock incoming down command event for nonkaku_device_2 - event_callback({ - 'id': 'nonkaku_device_2', - 'command': 'down' - }) + event_callback({"id": "nonkaku_device_2", "command": "down"}) await hass.async_block_till_done() - standard_cover = hass.states.get(DOMAIN + '.nonkaku_type_none') + standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_none") assert standard_cover.state == STATE_CLOSED - assert standard_cover.attributes.get('assumed_state') + assert standard_cover.attributes.get("assumed_state") # mock incoming down command event for nonkaku_device_3 - event_callback({ - 'id': 'nonkaku_device_3', - 'command': 'down' - }) + event_callback({"id": "nonkaku_device_3", "command": "down"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted") assert inverted_cover.state == STATE_CLOSED - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming down command event for newkaku_device_4 - event_callback({ - 'id': 'newkaku_device_4', - 'command': 'down' - }) + event_callback({"id": "newkaku_device_4", "command": "down"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard") assert inverted_cover.state == STATE_CLOSED - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming down command event for newkaku_device_5 - event_callback({ - 'id': 'newkaku_device_5', - 'command': 'down' - }) + event_callback({"id": "newkaku_device_5", "command": "down"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none") assert inverted_cover.state == STATE_CLOSED - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # mock incoming down command event for newkaku_device_6 - event_callback({ - 'id': 'newkaku_device_6', - 'command': 'down' - }) + event_callback({"id": "newkaku_device_6", "command": "down"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted") assert inverted_cover.state == STATE_CLOSED - assert inverted_cover.attributes.get('assumed_state') + assert inverted_cover.attributes.get("assumed_state") # We are only testing the 'inverted' devices, the 'standard' devices # are already covered by other test cases. # should respond to group command - event_callback({ - 'id': 'nonkaku_device_3', - 'command': 'alloff', - }) + event_callback({"id": "nonkaku_device_3", "command": "alloff"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted") assert inverted_cover.state == STATE_CLOSED # should respond to group command - event_callback({ - 'id': 'nonkaku_device_3', - 'command': 'allon', - }) + event_callback({"id": "nonkaku_device_3", "command": "allon"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.nonkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted") assert inverted_cover.state == STATE_OPEN # should respond to group command - event_callback({ - 'id': 'newkaku_device_4', - 'command': 'alloff', - }) + event_callback({"id": "newkaku_device_4", "command": "alloff"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard") assert inverted_cover.state == STATE_CLOSED # should respond to group command - event_callback({ - 'id': 'newkaku_device_4', - 'command': 'allon', - }) + event_callback({"id": "newkaku_device_4", "command": "allon"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_standard') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard") assert inverted_cover.state == STATE_OPEN # should respond to group command - event_callback({ - 'id': 'newkaku_device_5', - 'command': 'alloff', - }) + event_callback({"id": "newkaku_device_5", "command": "alloff"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none") assert inverted_cover.state == STATE_CLOSED # should respond to group command - event_callback({ - 'id': 'newkaku_device_5', - 'command': 'allon', - }) + event_callback({"id": "newkaku_device_5", "command": "allon"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_none') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none") assert inverted_cover.state == STATE_OPEN # should respond to group command - event_callback({ - 'id': 'newkaku_device_6', - 'command': 'alloff', - }) + event_callback({"id": "newkaku_device_6", "command": "alloff"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted") assert inverted_cover.state == STATE_CLOSED # should respond to group command - event_callback({ - 'id': 'newkaku_device_6', - 'command': 'allon', - }) + event_callback({"id": "newkaku_device_6", "command": "allon"}) await hass.async_block_till_done() - inverted_cover = hass.states.get(DOMAIN + '.newkaku_type_inverted') + inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted") assert inverted_cover.state == STATE_OPEN # Sending the close command from HA should result # in an 'DOWN' command sent to a non-newkaku device # that has its type set to 'standard'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_standard'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_CLOSE_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_standard"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[0][0][0] == 'nonkaku_device_1' - assert protocol.send_command_ack.call_args_list[0][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".nonkaku_type_standard").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[0][0][0] == "nonkaku_device_1" + assert protocol.send_command_ack.call_args_list[0][0][1] == "DOWN" # Sending the open command from HA should result # in an 'UP' command sent to a non-newkaku device # that has its type set to 'standard'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_standard'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_OPEN_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_standard"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[1][0][0] == 'nonkaku_device_1' - assert protocol.send_command_ack.call_args_list[1][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".nonkaku_type_standard").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[1][0][0] == "nonkaku_device_1" + assert protocol.send_command_ack.call_args_list[1][0][1] == "UP" # Sending the close command from HA should result # in an 'DOWN' command sent to a non-newkaku device # that has its type not specified. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_none'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_none"} + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_none').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[2][0][0] == 'nonkaku_device_2' - assert protocol.send_command_ack.call_args_list[2][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".nonkaku_type_none").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[2][0][0] == "nonkaku_device_2" + assert protocol.send_command_ack.call_args_list[2][0][1] == "DOWN" # Sending the open command from HA should result # in an 'UP' command sent to a non-newkaku device # that has its type not specified. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_none'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_none"} + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_none').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[3][0][0] == 'nonkaku_device_2' - assert protocol.send_command_ack.call_args_list[3][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".nonkaku_type_none").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[3][0][0] == "nonkaku_device_2" + assert protocol.send_command_ack.call_args_list[3][0][1] == "UP" # Sending the close command from HA should result # in an 'UP' command sent to a non-newkaku device # that has its type set to 'inverted'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_inverted'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_CLOSE_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_inverted"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[4][0][0] == 'nonkaku_device_3' - assert protocol.send_command_ack.call_args_list[4][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".nonkaku_type_inverted").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[4][0][0] == "nonkaku_device_3" + assert protocol.send_command_ack.call_args_list[4][0][1] == "UP" # Sending the open command from HA should result # in an 'DOWN' command sent to a non-newkaku device # that has its type set to 'inverted'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.nonkaku_type_inverted'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_OPEN_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_inverted"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.nonkaku_type_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[5][0][0] == 'nonkaku_device_3' - assert protocol.send_command_ack.call_args_list[5][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".nonkaku_type_inverted").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[5][0][0] == "nonkaku_device_3" + assert protocol.send_command_ack.call_args_list[5][0][1] == "DOWN" # Sending the close command from HA should result # in an 'DOWN' command sent to a newkaku device # that has its type set to 'standard'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_standard'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_CLOSE_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_standard"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_standard').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[6][0][0] == 'newkaku_device_4' - assert protocol.send_command_ack.call_args_list[6][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".newkaku_type_standard").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[6][0][0] == "newkaku_device_4" + assert protocol.send_command_ack.call_args_list[6][0][1] == "DOWN" # Sending the open command from HA should result # in an 'UP' command sent to a newkaku device # that has its type set to 'standard'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_standard'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_OPEN_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_standard"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_standard').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[7][0][0] == 'newkaku_device_4' - assert protocol.send_command_ack.call_args_list[7][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".newkaku_type_standard").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[7][0][0] == "newkaku_device_4" + assert protocol.send_command_ack.call_args_list[7][0][1] == "UP" # Sending the close command from HA should result # in an 'UP' command sent to a newkaku device # that has its type not specified. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_none'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_none"} + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_none').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[8][0][0] == 'newkaku_device_5' - assert protocol.send_command_ack.call_args_list[8][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".newkaku_type_none").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[8][0][0] == "newkaku_device_5" + assert protocol.send_command_ack.call_args_list[8][0][1] == "UP" # Sending the open command from HA should result # in an 'DOWN' command sent to a newkaku device # that has its type not specified. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_none'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_none"} + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_none').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[9][0][0] == 'newkaku_device_5' - assert protocol.send_command_ack.call_args_list[9][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".newkaku_type_none").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[9][0][0] == "newkaku_device_5" + assert protocol.send_command_ack.call_args_list[9][0][1] == "DOWN" # Sending the close command from HA should result # in an 'UP' command sent to a newkaku device # that has its type set to 'inverted'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_inverted'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_CLOSE_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_inverted"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_inverted').state == STATE_CLOSED - assert protocol.send_command_ack.call_args_list[10][0][0] == 'newkaku_device_6' - assert protocol.send_command_ack.call_args_list[10][0][1] == 'UP' + assert hass.states.get(DOMAIN + ".newkaku_type_inverted").state == STATE_CLOSED + assert protocol.send_command_ack.call_args_list[10][0][0] == "newkaku_device_6" + assert protocol.send_command_ack.call_args_list[10][0][1] == "UP" # Sending the open command from HA should result # in an 'DOWN' command sent to a newkaku device # that has its type set to 'inverted'. - hass.async_create_task(hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + '.newkaku_type_inverted'})) + hass.async_create_task( + hass.services.async_call( + DOMAIN, + SERVICE_OPEN_COVER, + {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_inverted"}, + ) + ) await hass.async_block_till_done() - assert hass.states.get(DOMAIN + '.newkaku_type_inverted').state == STATE_OPEN - assert protocol.send_command_ack.call_args_list[11][0][0] == 'newkaku_device_6' - assert protocol.send_command_ack.call_args_list[11][0][1] == 'DOWN' + assert hass.states.get(DOMAIN + ".newkaku_type_inverted").state == STATE_OPEN + assert protocol.send_command_ack.call_args_list[11][0][0] == "newkaku_device_6" + assert protocol.send_command_ack.call_args_list[11][0][1] == "DOWN" From 28be75bf933ad6bd751de26a9b830e37f6d030d8 Mon Sep 17 00:00:00 2001 From: fmartens <17504441+fmartens@users.noreply.github.com> Date: Sun, 1 Sep 2019 14:24:26 +0200 Subject: [PATCH 18/18] entity_type_for_device_id should return 'TYPE_STANDARD' instead of 'None' --- homeassistant/components/rflink/cover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/rflink/cover.py b/homeassistant/components/rflink/cover.py index 33a082be62745..f41c4cde2f7d3 100644 --- a/homeassistant/components/rflink/cover.py +++ b/homeassistant/components/rflink/cover.py @@ -65,7 +65,7 @@ def entity_type_for_device_id(device_id): "newkaku": TYPE_INVERTED } protocol = device_id.split("_")[0] - return entity_type_mapping.get(protocol, None) + return entity_type_mapping.get(protocol, TYPE_STANDARD) def entity_class_for_type(entity_type):