Convert config.components to a set (#5824)

pull/5858/head
Paulus Schoutsen 2017-02-09 10:21:57 -08:00 committed by Johann Kellerman
parent f3b9fa2f41
commit c54517de90
44 changed files with 118 additions and 104 deletions

View File

@ -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}

View File

@ -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):

View File

@ -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 = []

View File

@ -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 "

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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):

View File

@ -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',

View File

@ -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

View File

@ -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

View File

@ -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 = []

View File

@ -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

View File

@ -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 = []

View File

@ -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 = []

View File

@ -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 = []

View File

@ -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

View File

@ -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',

View File

@ -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',

View File

@ -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."""

View File

@ -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',

View File

@ -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."""

View File

@ -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."""

View File

@ -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."""

View File

@ -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',

View File

@ -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"

View File

@ -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)

View File

@ -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',

View File

@ -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: {

View File

@ -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."""

View File

@ -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',

View File

@ -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',

View File

@ -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

View File

@ -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',

View File

@ -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

View File

@ -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."""

View File

@ -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',

View File

@ -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."""

View File

@ -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."""

View File

@ -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,

View File

@ -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):

View File

@ -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()

View File

@ -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()

View File

@ -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__,
}