core/tests/components/rflink/test_init.py

346 lines
11 KiB
Python
Raw Normal View History

"""Common functions for RFLink component tests and generic platform tests."""
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
import pytest
from voluptuous.error import MultipleInvalid
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
from homeassistant.bootstrap import async_setup_component
from homeassistant.components.rflink import (
2019-07-31 19:25:30 +00:00
CONF_RECONNECT_INTERVAL,
DATA_ENTITY_LOOKUP,
EVENT_KEY_COMMAND,
EVENT_KEY_SENSOR,
SERVICE_SEND_COMMAND,
TMP_ENTITY,
RflinkCommand,
2019-07-31 19:25:30 +00:00
)
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_STOP_COVER, SERVICE_TURN_OFF
2019-07-31 19:25:30 +00:00
from tests.async_mock import Mock
2019-07-31 19:25:30 +00:00
async def mock_rflink(
hass, config, domain, monkeypatch, failures=None, failcommand=False
):
"""Create mock RFLink asyncio protocol, test component setup."""
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
transport, protocol = (Mock(), Mock())
async def send_command_ack(*command):
return not failcommand
2019-07-31 19:25:30 +00:00
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
protocol.send_command_ack = Mock(wraps=send_command_ack)
def send_command(*command):
return not failcommand
2019-07-31 19:25:30 +00:00
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
protocol.send_command = Mock(wraps=send_command)
async def create_rflink_connection(*args, **kwargs):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Return mocked transport and protocol."""
# failures can be a list of booleans indicating in which sequence
# creating a connection should success or fail
if failures:
fail = failures.pop()
else:
fail = False
if fail:
raise ConnectionRefusedError
else:
return transport, protocol
mock_create = Mock(wraps=create_rflink_connection)
monkeypatch.setattr(
"homeassistant.components.rflink.create_rflink_connection", mock_create
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
2019-07-31 19:25:30 +00:00
await async_setup_component(hass, "rflink", config)
await async_setup_component(hass, domain, config)
2019-04-09 20:59:15 +00:00
await hass.async_block_till_done()
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# hook into mock config for injecting events
2019-07-31 19:25:30 +00:00
event_callback = mock_create.call_args_list[0][1]["event_callback"]
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
assert event_callback
2019-07-31 19:25:30 +00:00
disconnect_callback = mock_create.call_args_list[0][1]["disconnect_callback"]
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
return event_callback, mock_create, protocol, disconnect_callback
async def test_version_banner(hass, monkeypatch):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Test sending unknown commands doesn't cause issues."""
# use sensor domain during testing main platform
2019-07-31 19:25:30 +00:00
domain = "sensor"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0"},
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
domain: {
2019-07-31 19:25:30 +00:00
"platform": "rflink",
"devices": {"test": {"name": "test", "sensor_type": "temperature"}},
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
},
}
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
event_callback, _, _, _ = await mock_rflink(hass, config, domain, monkeypatch)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
2019-07-31 19:25:30 +00:00
event_callback(
{
"hardware": "Nodo RadioFrequencyLink",
"firmware": "RFLink Gateway",
"version": "1.1",
"revision": "45",
}
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
async def test_send_no_wait(hass, monkeypatch):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""Test command sending without ack."""
2019-07-31 19:25:30 +00:00
domain = "switch"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0", "wait_for_ack": False},
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
domain: {
2019-07-31 19:25:30 +00:00
"platform": "rflink",
"devices": {
"protocol_0_0": {"name": "test", "aliases": ["test_alias_0_0"]}
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
},
},
}
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
hass.async_create_task(
2019-07-31 19:25:30 +00:00
hass.services.async_call(
domain, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "switch.test"}
)
)
await hass.async_block_till_done()
2019-07-31 19:25:30 +00:00
assert protocol.send_command.call_args_list[0][0][0] == "protocol_0_0"
assert protocol.send_command.call_args_list[0][0][1] == "off"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
async def test_cover_send_no_wait(hass, monkeypatch):
"""Test command sending to a cover device without ack."""
2019-07-31 19:25:30 +00:00
domain = "cover"
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0", "wait_for_ack": False},
domain: {
2019-07-31 19:25:30 +00:00
"platform": "rflink",
"devices": {
"RTS_0100F2_0": {"name": "test", "aliases": ["test_alias_0_0"]}
},
},
}
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
hass.async_create_task(
2019-07-31 19:25:30 +00:00
hass.services.async_call(
domain, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: "cover.test"}
)
)
await hass.async_block_till_done()
2019-07-31 19:25:30 +00:00
assert protocol.send_command.call_args_list[0][0][0] == "RTS_0100F2_0"
assert protocol.send_command.call_args_list[0][0][1] == "STOP"
async def test_send_command(hass, monkeypatch):
"""Test send_command service."""
2019-07-31 19:25:30 +00:00
domain = "rflink"
config = {"rflink": {"port": "/dev/ttyABC0"}}
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
hass.async_create_task(
2019-07-31 19:25:30 +00:00
hass.services.async_call(
domain,
SERVICE_SEND_COMMAND,
{"device_id": "newkaku_0000c6c2_1", "command": "on"},
)
)
await hass.async_block_till_done()
2019-07-31 19:25:30 +00:00
assert protocol.send_command_ack.call_args_list[0][0][0] == "newkaku_0000c6c2_1"
assert protocol.send_command_ack.call_args_list[0][0][1] == "on"
async def test_send_command_invalid_arguments(hass, monkeypatch):
"""Test send_command service."""
2019-07-31 19:25:30 +00:00
domain = "rflink"
config = {"rflink": {"port": "/dev/ttyABC0"}}
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
# one argument missing
with pytest.raises(MultipleInvalid):
await hass.services.async_call(domain, SERVICE_SEND_COMMAND, {"command": "on"})
with pytest.raises(MultipleInvalid):
await hass.services.async_call(
2019-07-31 19:25:30 +00:00
domain, SERVICE_SEND_COMMAND, {"device_id": "newkaku_0000c6c2_1"}
)
# no arguments
with pytest.raises(MultipleInvalid):
await hass.services.async_call(domain, SERVICE_SEND_COMMAND, {})
await hass.async_block_till_done()
assert protocol.send_command_ack.call_args_list == []
# bad command (no_command)
success = await hass.services.async_call(
2019-07-31 19:25:30 +00:00
domain,
SERVICE_SEND_COMMAND,
{"device_id": "newkaku_0000c6c2_1", "command": "no_command"},
)
assert not success, "send command should not succeed for unknown command"
async def test_reconnecting_after_disconnect(hass, monkeypatch):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""An unexpected disconnect should cause a reconnect."""
2019-07-31 19:25:30 +00:00
domain = "sensor"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0", CONF_RECONNECT_INTERVAL: 0},
domain: {"platform": "rflink"},
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
}
# setup mocking rflink module
_, mock_create, _, disconnect_callback = await mock_rflink(
2019-07-31 19:25:30 +00:00
hass, config, domain, monkeypatch
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
2019-07-31 19:25:30 +00:00
assert disconnect_callback, "disconnect callback not passed to rflink"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# rflink initiated disconnect
disconnect_callback(None)
await hass.async_block_till_done()
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# we expect 2 call, the initial and reconnect
assert mock_create.call_count == 2
async def test_reconnecting_after_failure(hass, monkeypatch):
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
"""A failure to reconnect should be retried."""
2019-07-31 19:25:30 +00:00
domain = "sensor"
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0", CONF_RECONNECT_INTERVAL: 0},
domain: {"platform": "rflink"},
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
}
# success first time but fail second
failures = [False, True, False]
# setup mocking rflink module
_, mock_create, _, disconnect_callback = await mock_rflink(
2019-07-31 19:25:30 +00:00
hass, config, domain, monkeypatch, failures=failures
)
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# rflink initiated disconnect
disconnect_callback(None)
# wait for reconnects to have happened
await hass.async_block_till_done()
await hass.async_block_till_done()
Rflink 433Mhz gateway platform and components (#4547) * Initial sketches of rflink component. * Add requirement. * Properly load configuration. * Bump rflink for graceful parse errors and protocol callback. * Cleanup, documentation and linting. * More documentation, first sensor implementation (temp & hum). * Add brightness/dim support for newkaku protocol. * Use separate class for dimmables. * Make sure non-dimmable newkaku devices are turned on. * Move some code around, add switches. Support loading from config. * Fix bug in ignoring devices. * Fix initial state assumption. * Improve reliability on invalid conditions. * Allow configuration of group for new devices. * Sensor icons. * Fix parsing negative numbers. * Correct icon. * Allow sending commands serial. * Pluralize. * Allow adding sensors from config. * Fix ignoring devices and bugs in previous commit. * Share know devices so devices from configuration don't get added as lights. * Lookup unit from value_key. * Remove debug. * Start implementing event protocol in place of packet protocol. - Added first test suite for sensors. - This currently breaks light and switch. * Refactor switch component to fit new rflink changes. Add test suite. * Fix style. * Refactor and test lights. Bring coverage to 100%. * Use non-broken and production tested rflink module. * Update requirements. * Bump for logging. * Improve readability. * Do not use global variable but keep known device state in intended place. * Improve docs. * Make icon support generic. * Disable overriding icons in config, as it belongs in customization. Only keep custom icon for entities that are able to detect a icon based on the thing they represent (sensors in this case). * Implement configuration schema, overall refactor of magic values. * Fix bug in config/test wait_for_ack. * Small refactors. * Move command logic into separate class. * Convert command sending logic to class based pattern instead of using the event bus. * Start not using bus for rflink event propagation to platforms. * Do not use event bus for all entity types. * Fire an event on the bus for every switch incoming rflink command. * Resolve lint errors, remove some old code. * Known devices no longer need to be registered separately. * Log bus events. * Event callback is a..... callback. * Use full entity id for events. * Move event sending to entity. * Log incoming events. * Make firing events optional inline with rfxtrx. * Add foundation for signal repetition. * Add signal repetition config and tests. * Make plain switchable type explicitly configurable. * Enable default entity settings for automatically added entities as well. * Prevent default configuration leaking accross entities. * Make sure device defaults don't get overwritten by defaults further down. * Don't let fast state switching and repetitions turn your house into a disco. * Make repetitions more responsive. * Disable on/off fallback on dimmables as it currently doesn't play nice with repetitions. * Use rflink that allows send_command_ack to be safely cancelled. * Reduce duplication and make repeat work for non-ack. * Implement reconnection logic. * Improve reconnection logic. * Also cancel repetitions when entity state is changed due to external command. * Update requirements. * Fix linting. * Fix spelling. * Don't lie. * Fix lint. * Support for automatically creating protocol translation (fixes spaces in device names). * Returned support for dimmable and on/off entity. * Duplicate code to fix linting issues with inheritance. * Allow overriding unit of measurement from config.
2017-01-31 16:11:52 +00:00
# we expect 3 calls, the initial and 2 reconnects
assert mock_create.call_count == 3
async def test_error_when_not_connected(hass, monkeypatch):
"""Sending command should error when not connected."""
2019-07-31 19:25:30 +00:00
domain = "switch"
config = {
2019-07-31 19:25:30 +00:00
"rflink": {"port": "/dev/ttyABC0", CONF_RECONNECT_INTERVAL: 0},
domain: {
2019-07-31 19:25:30 +00:00
"platform": "rflink",
"devices": {
"protocol_0_0": {"name": "test", "aliases": ["test_alias_0_0"]}
},
},
}
# success first time but fail second
failures = [False, True, False]
# setup mocking rflink module
_, _, _, disconnect_callback = await mock_rflink(
2019-07-31 19:25:30 +00:00
hass, config, domain, monkeypatch, failures=failures
)
# rflink initiated disconnect
disconnect_callback(None)
success = await hass.services.async_call(
2019-07-31 19:25:30 +00:00
domain, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "switch.test"}
)
assert not success, "changing state should not succeed when disconnected"
async def test_async_send_command_error(hass, monkeypatch):
"""Sending command should error when protocol fails."""
2019-07-31 19:25:30 +00:00
domain = "rflink"
config = {"rflink": {"port": "/dev/ttyABC0"}}
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(
2019-07-31 19:25:30 +00:00
hass, config, domain, monkeypatch, failcommand=True
)
success = await hass.services.async_call(
2019-07-31 19:25:30 +00:00
domain,
SERVICE_SEND_COMMAND,
{"device_id": "newkaku_0000c6c2_1", "command": SERVICE_TURN_OFF},
)
await hass.async_block_till_done()
2019-07-31 19:25:30 +00:00
assert not success, "send command should not succeed if failcommand=True"
assert protocol.send_command_ack.call_args_list[0][0][0] == "newkaku_0000c6c2_1"
assert protocol.send_command_ack.call_args_list[0][0][1] == SERVICE_TURN_OFF
async def test_race_condition(hass, monkeypatch):
"""Test race condition for unknown components."""
2019-07-31 19:25:30 +00:00
domain = "light"
config = {"rflink": {"port": "/dev/ttyABC0"}, domain: {"platform": "rflink"}}
tmp_entity = TMP_ENTITY.format("test3")
# setup mocking rflink module
2019-07-31 19:25:30 +00:00
event_callback, _, _, _ = await mock_rflink(hass, config, domain, monkeypatch)
# test event for new unconfigured sensor
2019-07-31 19:25:30 +00:00
event_callback({"id": "test3", "command": "off"})
event_callback({"id": "test3", "command": "on"})
# tmp_entity added to EVENT_KEY_COMMAND
2019-07-31 19:25:30 +00:00
assert tmp_entity in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND]["test3"]
# tmp_entity must no be added to EVENT_KEY_SENSOR
2019-07-31 19:25:30 +00:00
assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR]["test3"]
await hass.async_block_till_done()
# test state of new sensor
2020-04-05 22:34:24 +00:00
new_sensor = hass.states.get(f"{domain}.test3")
assert new_sensor
2019-07-31 19:25:30 +00:00
assert new_sensor.state == "off"
2019-07-31 19:25:30 +00:00
event_callback({"id": "test3", "command": "on"})
await hass.async_block_till_done()
# tmp_entity must be deleted from EVENT_KEY_COMMAND
2019-07-31 19:25:30 +00:00
assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND]["test3"]
# test state of new sensor
2020-04-05 22:34:24 +00:00
new_sensor = hass.states.get(f"{domain}.test3")
assert new_sensor
2019-07-31 19:25:30 +00:00
assert new_sensor.state == "on"
async def test_not_connected(hass, monkeypatch):
"""Test Error when sending commands to a disconnected device."""
import pytest
from homeassistant.core import HomeAssistantError
2019-07-31 19:25:30 +00:00
test_device = RflinkCommand("DUMMY_DEVICE")
RflinkCommand.set_rflink_protocol(None)
with pytest.raises(HomeAssistantError):
2019-07-31 19:25:30 +00:00
await test_device._async_handle_command("turn_on")