From c54517de909974b355f64840ed06d528b629c4d4 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 9 Feb 2017 10:21:57 -0800 Subject: [PATCH] Convert config.components to a set (#5824) --- homeassistant/bootstrap.py | 2 +- homeassistant/components/configurator.py | 17 ++++++++-------- homeassistant/components/homematic.py | 1 - homeassistant/components/notify/ios.py | 2 +- homeassistant/core.py | 2 +- homeassistant/helpers/entity_component.py | 2 +- homeassistant/remote.py | 10 +++++++++- tests/common.py | 2 +- .../alarm_control_panel/test_mqtt.py | 20 +++++++++---------- tests/components/automation/test_event.py | 2 +- tests/components/automation/test_init.py | 2 +- tests/components/automation/test_mqtt.py | 2 +- .../automation/test_numeric_state.py | 2 +- tests/components/automation/test_state.py | 2 +- tests/components/automation/test_sun.py | 4 ++-- tests/components/automation/test_template.py | 2 +- tests/components/automation/test_time.py | 2 +- tests/components/automation/test_zone.py | 2 +- tests/components/binary_sensor/test_mqtt.py | 6 +++--- tests/components/camera/test_uvc.py | 2 +- tests/components/cover/test_mqtt.py | 14 ++++++------- tests/components/cover/test_rfxtrx.py | 2 +- .../components/device_tracker/test_asuswrt.py | 2 +- tests/components/device_tracker/test_ddwrt.py | 2 +- tests/components/device_tracker/test_mqtt.py | 4 ++-- .../device_tracker/test_upc_connect.py | 2 +- tests/components/light/test_mqtt.py | 16 +++++++-------- tests/components/light/test_mqtt_json.py | 14 ++++++------- tests/components/light/test_mqtt_template.py | 14 ++++++------- tests/components/light/test_rfxtrx.py | 2 +- tests/components/lock/test_mqtt.py | 6 +++--- tests/components/mqtt/test_init.py | 10 +++++----- tests/components/mqtt/test_server.py | 4 ++-- tests/components/sensor/test_mqtt.py | 4 ++-- tests/components/sensor/test_pilight.py | 2 +- tests/components/sensor/test_rfxtrx.py | 2 +- tests/components/switch/test_mqtt.py | 6 +++--- tests/components/switch/test_rfxtrx.py | 2 +- tests/components/test_api.py | 8 ++++++-- tests/components/test_logbook.py | 2 +- tests/components/test_script.py | 2 +- tests/components/test_websocket_api.py | 4 ++++ tests/test_bootstrap.py | 10 +++++----- tests/test_core.py | 2 +- 44 files changed, 118 insertions(+), 104 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 87fd9f7d9e5..72780707f66 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -166,7 +166,7 @@ def _async_setup_component(hass: core.HomeAssistant, loader.set_component(domain, None) return False - hass.config.components.append(component.DOMAIN) + hass.config.components.add(component.DOMAIN) hass.bus.async_fire( EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: component.DOMAIN} diff --git a/homeassistant/components/configurator.py b/homeassistant/components/configurator.py index 5e99e02d371..d912f9914b5 100644 --- a/homeassistant/components/configurator.py +++ b/homeassistant/components/configurator.py @@ -6,15 +6,16 @@ This will return a request id that has to be used for future calls. A callback has to be provided to `request_config` which will be called when the user has submitted configuration information. """ +import asyncio import logging from homeassistant.const import EVENT_TIME_CHANGED, ATTR_FRIENDLY_NAME, \ ATTR_ENTITY_PICTURE from homeassistant.helpers.entity import generate_entity_id -_INSTANCES = {} _LOGGER = logging.getLogger(__name__) _REQUESTS = {} +_KEY_INSTANCE = 'configurator' ATTR_CONFIGURE_ID = 'configure_id' ATTR_DESCRIPTION = 'description' @@ -72,22 +73,20 @@ def request_done(request_id): pass -def setup(hass, config): +@asyncio.coroutine +def async_setup(hass, config): """Setup the configurator component.""" return True def _get_instance(hass): """Get an instance per hass object.""" - try: - return _INSTANCES[hass] - except KeyError: - _INSTANCES[hass] = Configurator(hass) + instance = hass.data.get(_KEY_INSTANCE) - if DOMAIN not in hass.config.components: - hass.config.components.append(DOMAIN) + if instance is None: + instance = hass.data[_KEY_INSTANCE] = Configurator(hass) - return _INSTANCES[hass] + return instance class Configurator(object): diff --git a/homeassistant/components/homematic.py b/homeassistant/components/homematic.py index ce1df98d727..365c843f854 100644 --- a/homeassistant/components/homematic.py +++ b/homeassistant/components/homematic.py @@ -276,7 +276,6 @@ def setup(hass, config): # Stops server when Homeassistant is shutting down hass.bus.listen_once( EVENT_HOMEASSISTANT_STOP, hass.data[DATA_HOMEMATIC].stop) - hass.config.components.append(DOMAIN) # init homematic hubs entity_hubs = [] diff --git a/homeassistant/components/notify/ios.py b/homeassistant/components/notify/ios.py index 0db05b261b3..e788beda0c4 100644 --- a/homeassistant/components/notify/ios.py +++ b/homeassistant/components/notify/ios.py @@ -43,7 +43,7 @@ def get_service(hass, config, discovery_info=None): """Get the iOS notification service.""" if "notify.ios" not in hass.config.components: # Need this to enable requirements checking in the app. - hass.config.components.append("notify.ios") + hass.config.components.add("notify.ios") if not ios.devices_with_push(): _LOGGER.error(("The notify.ios platform was loaded but no " diff --git a/homeassistant/core.py b/homeassistant/core.py index 5bede3da7a6..85b65ebc477 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1047,7 +1047,7 @@ class Config(object): self.skip_pip = False # type: bool # List of loaded components - self.components = [] + self.components = set() # Remote.API object pointing at local API self.api = None diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 4b773d50bb9..e453d609858 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -151,7 +151,7 @@ class EntityComponent(object): entity_platform.add_entities, discovery_info ) - self.hass.config.components.append( + self.hass.config.components.add( '{}.{}'.format(self.domain, platform_type)) except Exception: # pylint: disable=broad-except self.logger.exception( diff --git a/homeassistant/remote.py b/homeassistant/remote.py index c124d509f9c..15421ebfc11 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -312,6 +312,8 @@ class JSONEncoder(json.JSONEncoder): """ if isinstance(obj, datetime): return obj.isoformat() + elif isinstance(obj, set): + return list(obj) elif hasattr(obj, 'as_dict'): return obj.as_dict() @@ -548,7 +550,13 @@ def get_config(api): try: req = api(METHOD_GET, URL_API_CONFIG) - return req.json() if req.status_code == 200 else {} + if req.status_code != 200: + return {} + + result = req.json() + if 'components' in result: + result['components'] = set(result['components']) + return result except (HomeAssistantError, ValueError): # ValueError if req.json() can't parse the JSON diff --git a/tests/common.py b/tests/common.py index e384a4f1b37..70afae75155 100644 --- a/tests/common.py +++ b/tests/common.py @@ -213,7 +213,7 @@ def mock_state_change_event(hass, new_state, old_state=None): def mock_http_component(hass): """Mock the HTTP component.""" hass.http = MagicMock() - hass.config.components.append('http') + hass.config.components.add('http') hass.http.views = {} def mock_register_view(view): diff --git a/tests/components/alarm_control_panel/test_mqtt.py b/tests/components/alarm_control_panel/test_mqtt.py index 871bc6afd76..c253c4a49fb 100644 --- a/tests/components/alarm_control_panel/test_mqtt.py +++ b/tests/components/alarm_control_panel/test_mqtt.py @@ -30,7 +30,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_fail_setup_without_state_topic(self): """Test for failing with no state topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(0) as config: assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { @@ -42,7 +42,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_fail_setup_without_command_topic(self): """Test failing with no command topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(0): assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { @@ -53,7 +53,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_update_state_via_state_topic(self): """Test updating with via state topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -77,7 +77,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_ignore_update_state_if_unknown_via_state_topic(self): """Test ignoring updates via state topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -98,7 +98,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_arm_home_publishes_mqtt(self): """Test publishing of MQTT messages while armed.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -115,7 +115,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_arm_home_not_publishes_mqtt_with_invalid_code(self): """Test not publishing of MQTT messages with invalid code.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -133,7 +133,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_arm_away_publishes_mqtt(self): """Test publishing of MQTT messages while armed.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -150,7 +150,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_arm_away_not_publishes_mqtt_with_invalid_code(self): """Test not publishing of MQTT messages with invalid code.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -168,7 +168,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_disarm_publishes_mqtt(self): """Test publishing of MQTT messages while disarmed.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', @@ -185,7 +185,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase): def test_disarm_not_publishes_mqtt_with_invalid_code(self): """Test not publishing of MQTT messages with invalid code.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/automation/test_event.py b/tests/components/automation/test_event.py index a81e4200f48..18e112fc498 100644 --- a/tests/components/automation/test_event.py +++ b/tests/components/automation/test_event.py @@ -15,7 +15,7 @@ class TestAutomationEvent(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.calls = [] @callback diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 39df4af719d..ca8eef4fc0d 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -21,7 +21,7 @@ class TestAutomation(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.calls = [] @callback diff --git a/tests/components/automation/test_mqtt.py b/tests/components/automation/test_mqtt.py index 7ee2aadeaf6..a2746728fe3 100644 --- a/tests/components/automation/test_mqtt.py +++ b/tests/components/automation/test_mqtt.py @@ -15,7 +15,7 @@ class TestAutomationMQTT(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') mock_mqtt_component(self.hass) self.calls = [] diff --git a/tests/components/automation/test_numeric_state.py b/tests/components/automation/test_numeric_state.py index c7db55726eb..85842ccf5eb 100644 --- a/tests/components/automation/test_numeric_state.py +++ b/tests/components/automation/test_numeric_state.py @@ -15,7 +15,7 @@ class TestAutomationNumericState(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.calls = [] @callback diff --git a/tests/components/automation/test_state.py b/tests/components/automation/test_state.py index 3f54c876c5f..00048f1f577 100644 --- a/tests/components/automation/test_state.py +++ b/tests/components/automation/test_state.py @@ -20,7 +20,7 @@ class TestAutomationState(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.hass.states.set('test.entity', 'hello') self.calls = [] diff --git a/tests/components/automation/test_sun.py b/tests/components/automation/test_sun.py index 582533d8476..bad592a740a 100644 --- a/tests/components/automation/test_sun.py +++ b/tests/components/automation/test_sun.py @@ -20,8 +20,8 @@ class TestAutomationSun(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') - self.hass.config.components.append('sun') + self.hass.config.components.add('group') + self.hass.config.components.add('sun') self.calls = [] diff --git a/tests/components/automation/test_template.py b/tests/components/automation/test_template.py index 7de2954a270..1971fb26d31 100644 --- a/tests/components/automation/test_template.py +++ b/tests/components/automation/test_template.py @@ -15,7 +15,7 @@ class TestAutomationTemplate(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.hass.states.set('test.entity', 'hello') self.calls = [] diff --git a/tests/components/automation/test_time.py b/tests/components/automation/test_time.py index 10e7910adcb..8f323dd4b37 100644 --- a/tests/components/automation/test_time.py +++ b/tests/components/automation/test_time.py @@ -19,7 +19,7 @@ class TestAutomationTime(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') self.calls = [] @callback diff --git a/tests/components/automation/test_zone.py b/tests/components/automation/test_zone.py index 72a79faa828..f2b304070b4 100644 --- a/tests/components/automation/test_zone.py +++ b/tests/components/automation/test_zone.py @@ -15,7 +15,7 @@ class TestAutomationZone(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') assert setup_component(self.hass, zone.DOMAIN, { 'zone': { 'name': 'test', diff --git a/tests/components/binary_sensor/test_mqtt.py b/tests/components/binary_sensor/test_mqtt.py index 3bff4420a66..5e4a2640a34 100644 --- a/tests/components/binary_sensor/test_mqtt.py +++ b/tests/components/binary_sensor/test_mqtt.py @@ -23,7 +23,7 @@ class TestSensorMQTT(unittest.TestCase): def test_setting_sensor_value_via_mqtt_message(self): """Test the setting of the value via MQTT.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, binary_sensor.DOMAIN, { binary_sensor.DOMAIN: { 'platform': 'mqtt', @@ -49,7 +49,7 @@ class TestSensorMQTT(unittest.TestCase): def test_valid_sensor_class(self): """Test the setting of a valid sensor class.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, binary_sensor.DOMAIN, { binary_sensor.DOMAIN: { 'platform': 'mqtt', @@ -64,7 +64,7 @@ class TestSensorMQTT(unittest.TestCase): def test_invalid_sensor_class(self): """Test the setting of an invalid sensor class.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, binary_sensor.DOMAIN, { binary_sensor.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/camera/test_uvc.py b/tests/components/camera/test_uvc.py index f5cb0992ec0..c5b8b6a9f78 100644 --- a/tests/components/camera/test_uvc.py +++ b/tests/components/camera/test_uvc.py @@ -19,7 +19,7 @@ class TestUVCSetup(unittest.TestCase): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() self.hass.http = mock.MagicMock() - self.hass.config.components = ['http'] + self.hass.config.components = set(['http']) def tearDown(self): """Stop everything that was started.""" diff --git a/tests/components/cover/test_mqtt.py b/tests/components/cover/test_mqtt.py index 3986fc2466e..05fa29263a9 100644 --- a/tests/components/cover/test_mqtt.py +++ b/tests/components/cover/test_mqtt.py @@ -23,7 +23,7 @@ class TestCoverMQTT(unittest.TestCase): def test_state_via_state_topic(self): """Test the controlling state via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -72,7 +72,7 @@ class TestCoverMQTT(unittest.TestCase): def test_state_via_template(self): """Test the controlling state via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -101,7 +101,7 @@ class TestCoverMQTT(unittest.TestCase): def test_optimistic_state_change(self): """Test changing state optimistically.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -132,7 +132,7 @@ class TestCoverMQTT(unittest.TestCase): def test_send_open_cover_command(self): """Test the sending of open_cover.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -156,7 +156,7 @@ class TestCoverMQTT(unittest.TestCase): def test_send_close_cover_command(self): """Test the sending of close_cover.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -180,7 +180,7 @@ class TestCoverMQTT(unittest.TestCase): def test_send_stop__cover_command(self): """Test the sending of stop_cover.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', @@ -204,7 +204,7 @@ class TestCoverMQTT(unittest.TestCase): def test_current_cover_position(self): """Test the current cover position.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) self.assertTrue(setup_component(self.hass, cover.DOMAIN, { cover.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/cover/test_rfxtrx.py b/tests/components/cover/test_rfxtrx.py index 5f6ecd01e4e..18e2051afd6 100644 --- a/tests/components/cover/test_rfxtrx.py +++ b/tests/components/cover/test_rfxtrx.py @@ -16,7 +16,7 @@ class TestCoverRfxtrx(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['rfxtrx'] + self.hass.config.components = set(['rfxtrx']) def tearDown(self): """Stop everything that was started.""" diff --git a/tests/components/device_tracker/test_asuswrt.py b/tests/components/device_tracker/test_asuswrt.py index 9dfa010edb3..e2a97fd4c76 100644 --- a/tests/components/device_tracker/test_asuswrt.py +++ b/tests/components/device_tracker/test_asuswrt.py @@ -43,7 +43,7 @@ class TestComponentsDeviceTrackerASUSWRT(unittest.TestCase): def setup_method(self, _): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['zone'] + self.hass.config.components = set(['zone']) def teardown_method(self, _): """Stop everything that was started.""" diff --git a/tests/components/device_tracker/test_ddwrt.py b/tests/components/device_tracker/test_ddwrt.py index f7a1c011d10..340bac254b1 100644 --- a/tests/components/device_tracker/test_ddwrt.py +++ b/tests/components/device_tracker/test_ddwrt.py @@ -39,7 +39,7 @@ class TestDdwrt(unittest.TestCase): def setup_method(self, _): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['zone'] + self.hass.config.components = set(['zone']) def teardown_method(self, _): """Stop everything that was started.""" diff --git a/tests/components/device_tracker/test_mqtt.py b/tests/components/device_tracker/test_mqtt.py index 9405c944552..3ce3a358b87 100644 --- a/tests/components/device_tracker/test_mqtt.py +++ b/tests/components/device_tracker/test_mqtt.py @@ -43,7 +43,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase): dev_id = 'paulus' topic = '/location/paulus' - self.hass.config.components = ['mqtt', 'zone'] + self.hass.config.components = set(['mqtt', 'zone']) assert setup_component(self.hass, device_tracker.DOMAIN, { device_tracker.DOMAIN: { CONF_PLATFORM: 'mqtt', @@ -59,7 +59,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase): topic = '/location/paulus' location = 'work' - self.hass.config.components = ['mqtt', 'zone'] + self.hass.config.components = set(['mqtt', 'zone']) assert setup_component(self.hass, device_tracker.DOMAIN, { device_tracker.DOMAIN: { CONF_PLATFORM: 'mqtt', diff --git a/tests/components/device_tracker/test_upc_connect.py b/tests/components/device_tracker/test_upc_connect.py index 1bcbc841d3a..010c597cc31 100644 --- a/tests/components/device_tracker/test_upc_connect.py +++ b/tests/components/device_tracker/test_upc_connect.py @@ -30,7 +30,7 @@ class TestUPCConnect(object): def setup_method(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['zone'] + self.hass.config.components = set(['zone']) self.host = "127.0.0.1" diff --git a/tests/components/light/test_mqtt.py b/tests/components/light/test_mqtt.py index 667f2342603..fb6f98f37b4 100644 --- a/tests/components/light/test_mqtt.py +++ b/tests/components/light/test_mqtt.py @@ -99,7 +99,7 @@ class TestLightMQTT(unittest.TestCase): def test_fail_setup_if_no_command_topic(self): """Test if command fails with command topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(0): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -112,7 +112,7 @@ class TestLightMQTT(unittest.TestCase): def test_no_color_or_brightness_or_color_temp_if_no_topics(self): \ # pylint: disable=invalid-name """Test if there is no color and brightness if no topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -157,7 +157,7 @@ class TestLightMQTT(unittest.TestCase): 'payload_off': 0 }} - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, config) @@ -213,7 +213,7 @@ class TestLightMQTT(unittest.TestCase): def test_controlling_scale(self): """Test the controlling scale.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -276,7 +276,7 @@ class TestLightMQTT(unittest.TestCase): 'rgb_value_template': '{{ value_json.hello | join(",") }}', }} - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, config) @@ -316,7 +316,7 @@ class TestLightMQTT(unittest.TestCase): 'payload_off': 'off' }} - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, config) @@ -373,7 +373,7 @@ class TestLightMQTT(unittest.TestCase): 'state_topic': 'test_light_rgb/status', }} - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, config) @@ -398,7 +398,7 @@ class TestLightMQTT(unittest.TestCase): 'state_topic': 'test_light_rgb/status' }} - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, config) diff --git a/tests/components/light/test_mqtt_json.py b/tests/components/light/test_mqtt_json.py index fc9ade7d6ac..cbfa0470fed 100755 --- a/tests/components/light/test_mqtt_json.py +++ b/tests/components/light/test_mqtt_json.py @@ -53,7 +53,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_fail_setup_if_no_command_topic(self): \ # pylint: disable=invalid-name """Test if setup fails with no command topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(0): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -66,7 +66,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_no_color_or_brightness_if_no_config(self): \ # pylint: disable=invalid-name """Test if there is no color and brightness if they aren't defined.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', @@ -92,7 +92,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_controlling_state_via_topic(self): \ # pylint: disable=invalid-name """Test the controlling of the state via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', @@ -152,7 +152,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_sending_mqtt_commands_and_optimistic(self): \ # pylint: disable=invalid-name """Test the sending of command in optimistic mode.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', @@ -208,7 +208,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_flash_short_and_long(self): \ # pylint: disable=invalid-name """Test for flash length being sent when included.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', @@ -250,7 +250,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_transition(self): """Test for transition time being sent when included.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', @@ -292,7 +292,7 @@ class TestLightMQTTJSON(unittest.TestCase): def test_invalid_color_and_brightness_values(self): \ # pylint: disable=invalid-name """Test that invalid color/brightness values are ignored.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { 'platform': 'mqtt_json', diff --git a/tests/components/light/test_mqtt_template.py b/tests/components/light/test_mqtt_template.py index 954f3087646..b2a37c97001 100755 --- a/tests/components/light/test_mqtt_template.py +++ b/tests/components/light/test_mqtt_template.py @@ -45,7 +45,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_setup_fails(self): \ # pylint: disable=invalid-name """Test that setup fails with missing required configuration items.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(0): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -58,7 +58,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_state_change_via_topic(self): \ # pylint: disable=invalid-name """Test state change via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -93,7 +93,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_state_brightness_color_effect_change_via_topic(self): \ # pylint: disable=invalid-name """Test state, brightness, color and effect change via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -170,7 +170,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_optimistic(self): \ # pylint: disable=invalid-name """Test optimistic mode.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -232,7 +232,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_flash(self): \ # pylint: disable=invalid-name """Test flash.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -276,7 +276,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_transition(self): """Test for transition time being sent when included.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { @@ -320,7 +320,7 @@ class TestLightMQTTTemplate(unittest.TestCase): def test_invalid_values(self): \ # pylint: disable=invalid-name """Test that invalid values are ignored.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) with assert_setup_component(1): assert setup_component(self.hass, light.DOMAIN, { light.DOMAIN: { diff --git a/tests/components/light/test_rfxtrx.py b/tests/components/light/test_rfxtrx.py index 6a9311b7892..ca50a9cc925 100644 --- a/tests/components/light/test_rfxtrx.py +++ b/tests/components/light/test_rfxtrx.py @@ -16,7 +16,7 @@ class TestLightRfxtrx(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['rfxtrx'] + self.hass.config.components = set(['rfxtrx']) def tearDown(self): """Stop everything that was started.""" diff --git a/tests/components/lock/test_mqtt.py b/tests/components/lock/test_mqtt.py index 0c85360fc00..f22729a1e5b 100644 --- a/tests/components/lock/test_mqtt.py +++ b/tests/components/lock/test_mqtt.py @@ -23,7 +23,7 @@ class TestLockMQTT(unittest.TestCase): def test_controlling_state_via_topic(self): """Test the controlling state via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, lock.DOMAIN, { lock.DOMAIN: { 'platform': 'mqtt', @@ -53,7 +53,7 @@ class TestLockMQTT(unittest.TestCase): def test_sending_mqtt_commands_and_optimistic(self): """Test the sending MQTT commands in optimistic mode.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, lock.DOMAIN, { lock.DOMAIN: { 'platform': 'mqtt', @@ -87,7 +87,7 @@ class TestLockMQTT(unittest.TestCase): def test_controlling_state_via_topic_and_json_message(self): """Test the controlling state via topic and JSON message.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, lock.DOMAIN, { lock.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 54566a09f59..204f1fe15b4 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -57,11 +57,11 @@ class TestMQTT(unittest.TestCase): with mock.patch('homeassistant.components.mqtt.MQTT', side_effect=socket.error()): - self.hass.config.components = [] + self.hass.config.components = set() assert not setup_component(self.hass, mqtt.DOMAIN, test_broker_cfg) # Ensure if we dont raise it sets up correctly - self.hass.config.components = [] + self.hass.config.components = set() assert setup_component(self.hass, mqtt.DOMAIN, test_broker_cfg) @mock.patch('paho.mqtt.client.Client') @@ -71,13 +71,13 @@ class TestMQTT(unittest.TestCase): with mock.patch('homeassistant.components.mqtt.server.start', return_value=(True, client_config)) as _start: - self.hass.config.components = [] + self.hass.config.components = set() assert setup_component(self.hass, mqtt.DOMAIN, {mqtt.DOMAIN: {}}) assert _start.call_count == 1 # Test with `embedded: None` - self.hass.config.components = [] + self.hass.config.components = set() assert setup_component(self.hass, mqtt.DOMAIN, {mqtt.DOMAIN: {'embedded': None}}) assert _start.call_count == 2 # Another call @@ -234,7 +234,7 @@ class TestMQTTCallbacks(unittest.TestCase): # mock_mqtt_component(self.hass) with mock.patch('paho.mqtt.client.Client'): - self.hass.config.components = [] + self.hass.config.components = set() assert setup_component(self.hass, mqtt.DOMAIN, { mqtt.DOMAIN: { mqtt.CONF_BROKER: 'mock-broker', diff --git a/tests/components/mqtt/test_server.py b/tests/components/mqtt/test_server.py index 03caf8cc4c0..ceb648c6ef5 100644 --- a/tests/components/mqtt/test_server.py +++ b/tests/components/mqtt/test_server.py @@ -13,7 +13,7 @@ class TestMQTT: def setup_method(self, method): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('http') + self.hass.config.components.add('http') def teardown_method(self, method): """Stop everything that was started.""" @@ -38,7 +38,7 @@ class TestMQTT: mock_mqtt.reset_mock() - self.hass.config.components = ['http'] + self.hass.config.components = set(['http']) self.hass.config.api = MagicMock(api_password=None) assert setup_component(self.hass, mqtt.DOMAIN, {}) assert mock_mqtt.called diff --git a/tests/components/sensor/test_mqtt.py b/tests/components/sensor/test_mqtt.py index cac02d6bcd2..771aa999210 100644 --- a/tests/components/sensor/test_mqtt.py +++ b/tests/components/sensor/test_mqtt.py @@ -22,7 +22,7 @@ class TestSensorMQTT(unittest.TestCase): def test_setting_sensor_value_via_mqtt_message(self): """Test the setting of the value via MQTT.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, sensor.DOMAIN, { sensor.DOMAIN: { 'platform': 'mqtt', @@ -42,7 +42,7 @@ class TestSensorMQTT(unittest.TestCase): def test_setting_sensor_value_via_mqtt_json_message(self): """Test the setting of the value via MQTT with JSON playload.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, sensor.DOMAIN, { sensor.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/sensor/test_pilight.py b/tests/components/sensor/test_pilight.py index 943369f209c..2bade2af1a3 100644 --- a/tests/components/sensor/test_pilight.py +++ b/tests/components/sensor/test_pilight.py @@ -23,7 +23,7 @@ def setup_function(): global HASS HASS = get_test_home_assistant() - HASS.config.components = ['pilight'] + HASS.config.components = set(['pilight']) # pylint: disable=invalid-name diff --git a/tests/components/sensor/test_rfxtrx.py b/tests/components/sensor/test_rfxtrx.py index e70f8b5641d..092a9b60f85 100644 --- a/tests/components/sensor/test_rfxtrx.py +++ b/tests/components/sensor/test_rfxtrx.py @@ -17,7 +17,7 @@ class TestSensorRfxtrx(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['rfxtrx'] + self.hass.config.components = set(['rfxtrx']) def tearDown(self): """Stop everything that was started.""" diff --git a/tests/components/switch/test_mqtt.py b/tests/components/switch/test_mqtt.py index f39f4d11ec5..f6f9ffa0f86 100644 --- a/tests/components/switch/test_mqtt.py +++ b/tests/components/switch/test_mqtt.py @@ -22,7 +22,7 @@ class TestSensorMQTT(unittest.TestCase): def test_controlling_state_via_topic(self): """Test the controlling state via topic.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, switch.DOMAIN, { switch.DOMAIN: { 'platform': 'mqtt', @@ -52,7 +52,7 @@ class TestSensorMQTT(unittest.TestCase): def test_sending_mqtt_commands_and_optimistic(self): """Test the sending MQTT commands in optimistic mode.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, switch.DOMAIN, { switch.DOMAIN: { 'platform': 'mqtt', @@ -86,7 +86,7 @@ class TestSensorMQTT(unittest.TestCase): def test_controlling_state_via_topic_and_json_message(self): """Test the controlling state via topic and JSON message.""" - self.hass.config.components = ['mqtt'] + self.hass.config.components = set(['mqtt']) assert setup_component(self.hass, switch.DOMAIN, { switch.DOMAIN: { 'platform': 'mqtt', diff --git a/tests/components/switch/test_rfxtrx.py b/tests/components/switch/test_rfxtrx.py index ddee7cccaf7..26af42be4a9 100644 --- a/tests/components/switch/test_rfxtrx.py +++ b/tests/components/switch/test_rfxtrx.py @@ -16,7 +16,7 @@ class TestSwitchRfxtrx(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components = ['rfxtrx'] + self.hass.config.components = set(['rfxtrx']) def tearDown(self): """Stop everything that was started.""" diff --git a/tests/components/test_api.py b/tests/components/test_api.py index 28ffa7405e7..38222ff8f00 100644 --- a/tests/components/test_api.py +++ b/tests/components/test_api.py @@ -235,13 +235,17 @@ class TestAPI(unittest.TestCase): """Test the return of the configuration.""" req = requests.get(_url(const.URL_API_CONFIG), headers=HA_HEADERS) - self.assertEqual(hass.config.as_dict(), req.json()) + result = req.json() + if 'components' in result: + result['components'] = set(result['components']) + + self.assertEqual(hass.config.as_dict(), result) def test_api_get_components(self): """Test the return of the components.""" req = requests.get(_url(const.URL_API_COMPONENTS), headers=HA_HEADERS) - self.assertEqual(hass.config.components, req.json()) + self.assertEqual(hass.config.components, set(req.json())) def test_api_get_error_log(self): """Test the return of the error log.""" diff --git a/tests/components/test_logbook.py b/tests/components/test_logbook.py index 047ca480f6f..1e755a5155b 100644 --- a/tests/components/test_logbook.py +++ b/tests/components/test_logbook.py @@ -25,7 +25,7 @@ class TestComponentLogbook(unittest.TestCase): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() mock_http_component(self.hass) - self.hass.config.components += ['frontend', 'recorder', 'api'] + self.hass.config.components &= set(['frontend', 'recorder', 'api']) with patch('homeassistant.components.logbook.' 'register_built_in_panel'): assert setup_component(self.hass, logbook.DOMAIN, diff --git a/tests/components/test_script.py b/tests/components/test_script.py index 438ae75e9c6..4e8d94ade21 100644 --- a/tests/components/test_script.py +++ b/tests/components/test_script.py @@ -19,7 +19,7 @@ class TestScriptComponent(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.config.components.append('group') + self.hass.config.components.add('group') # pylint: disable=invalid-name def tearDown(self): diff --git a/tests/components/test_websocket_api.py b/tests/components/test_websocket_api.py index a6748e7fc16..3cdc77414ee 100644 --- a/tests/components/test_websocket_api.py +++ b/tests/components/test_websocket_api.py @@ -265,6 +265,10 @@ def test_get_config(hass, websocket_client): assert msg['id'] == 5 assert msg['type'] == wapi.TYPE_RESULT assert msg['success'] + + if 'components' in msg['result']: + msg['result']['components'] = set(msg['result']['components']) + assert msg['result'] == hass.config.as_dict() diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 0a1e3633916..b2c644a68b9 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -61,7 +61,7 @@ class TestBootstrap: @mock.patch('homeassistant.helpers.signal.async_register_signal_handling') def test_from_config_file(self, mock_upgrade, mock_detect, mock_signal): """Test with configuration file.""" - components = ['browser', 'conversation', 'script'] + components = set(['browser', 'conversation', 'script']) files = { 'config.yaml': ''.join( '{}:\n'.format(comp) @@ -76,8 +76,8 @@ class TestBootstrap: patch_yaml_files(files, True): self.hass = bootstrap.from_config_file('config.yaml') - components.append('group') - assert sorted(components) == sorted(self.hass.config.components) + components.add('group') + assert components == self.hass.config.components def test_handle_setup_circular_dependency(self): """Test the setup of circular dependencies.""" @@ -91,7 +91,7 @@ class TestBootstrap: loader.set_component('comp_a', MockModule('comp_a', setup=setup_a)) bootstrap.setup_component(self.hass, 'comp_a') - assert ['comp_a'] == self.hass.config.components + assert set(['comp_a']) == self.hass.config.components def test_validate_component_config(self): """Test validating component configuration.""" @@ -251,7 +251,7 @@ class TestBootstrap: thread = threading.Thread(target=setup_component) thread.start() - self.hass.config.components.append('comp') + self.hass.config.components.add('comp') thread.join() diff --git a/tests/test_core.py b/tests/test_core.py index 14276584ae2..98909ff8616 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -728,7 +728,7 @@ class TestConfig(unittest.TestCase): CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(), 'location_name': None, 'time_zone': 'UTC', - 'components': [], + 'components': set(), 'config_dir': '/tmp/ha-config', 'version': __version__, }