Custom component loading cleanup (#14211)

* Clean up custom component loading

* Fix some tests

* Fix some stuff

* Make imports work again

* Fix tests

* Remove debug print

* Lint
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2018-05-01 20:57:30 +02:00
1 parent 5d96751168
commit 83d300fd11
50 files changed
+315 -392

No files matched your search

@@ -116,7 +116,7 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
def test_heater_switch(self):
"""Test heater switching test switch."""
platform = loader.get_component('switch.test')
platform = loader.get_component(self.hass, 'switch.test')
platform.init()
self.switch_1 = platform.DEVICES[1]
assert setup_component(self.hass, switch.DOMAIN, {'switch': {
@@ -17,10 +17,10 @@ from homeassistant.loader import set_component
from tests.common import MockConfigEntry, MockModule, mock_coro_func
@pytest.fixture(scope='session', autouse=True)
def mock_test_component():
@pytest.fixture(autouse=True)
def mock_test_component(hass):
"""Ensure a component called 'test' exists."""
set_component('test', MockModule('test'))
set_component(hass, 'test', MockModule('test'))
@pytest.fixture
@@ -172,7 +172,8 @@ def test_abort(hass, client):
def test_create_account(hass, client):
"""Test a flow that creates an account."""
set_component(
'test', MockModule('test', async_setup_entry=mock_coro_func(True)))
hass, 'test',
MockModule('test', async_setup_entry=mock_coro_func(True)))
class TestFlow(FlowHandler):
VERSION = 1
@@ -204,7 +205,8 @@ def test_create_account(hass, client):
def test_two_step_flow(hass, client):
"""Test we can finish a two step flow."""
set_component(
'test', MockModule('test', async_setup_entry=mock_coro_func(True)))
hass, 'test',
MockModule('test', async_setup_entry=mock_coro_func(True)))
class TestFlow(FlowHandler):
VERSION = 1
@@ -3,9 +3,9 @@ import os
from datetime import timedelta
import unittest
from unittest import mock
import socket
import voluptuous as vol
from future.backports import socket
from homeassistant.setup import setup_component
from homeassistant.components import device_tracker
+5 -5
View File
@@ -189,7 +189,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
def test_update_stale(self):
"""Test stalled update."""
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('DEV1')
@@ -251,7 +251,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
hide_if_away=True)
device_tracker.update_config(self.yaml_devices, dev_id, device)
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
scanner.reset()
with assert_setup_component(1, device_tracker.DOMAIN):
@@ -270,7 +270,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
hide_if_away=True)
device_tracker.update_config(self.yaml_devices, dev_id, device)
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
scanner.reset()
with assert_setup_component(1, device_tracker.DOMAIN):
@@ -431,7 +431,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
'zone': zone_info
})
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('dev1')
@@ -547,7 +547,7 @@ def test_bad_platform(hass):
async def test_adding_unknown_device_to_config(mock_device_tracker_conf, hass):
"""Test the adding of unknown devices to configuration file."""
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(hass, 'device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('DEV1')
+3 -3
View File
@@ -118,7 +118,7 @@ class TestLight(unittest.TestCase):
def test_services(self):
"""Test the provided services."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
@@ -267,7 +267,7 @@ class TestLight(unittest.TestCase):
def test_broken_light_profiles(self):
"""Test light profiles."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
@@ -282,7 +282,7 @@ class TestLight(unittest.TestCase):
def test_light_profiles(self):
"""Test light profiles."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
+1 -1
View File
@@ -16,7 +16,7 @@ class TestScene(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
test_light = loader.get_component('light.test')
test_light = loader.get_component(self.hass, 'light.test')
test_light.init()
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
+16 -16
View File
@@ -71,7 +71,7 @@ class TestSwitchFlux(unittest.TestCase):
def test_flux_when_switch_is_off(self):
"""Test the flux switch when it is off."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -113,7 +113,7 @@ class TestSwitchFlux(unittest.TestCase):
def test_flux_before_sunrise(self):
"""Test the flux switch before sunrise."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -160,7 +160,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_after_sunrise_before_sunset(self):
"""Test the flux switch after sunrise and before sunset."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -207,7 +207,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_after_sunset_before_stop(self):
"""Test the flux switch after sunset and before stop."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -255,7 +255,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_after_stop_before_sunrise(self):
"""Test the flux switch after stop and before sunrise."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -302,7 +302,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_with_custom_start_stop_times(self):
"""Test the flux with custom start and stop times."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -353,7 +353,7 @@ class TestSwitchFlux(unittest.TestCase):
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -405,7 +405,7 @@ class TestSwitchFlux(unittest.TestCase):
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -456,7 +456,7 @@ class TestSwitchFlux(unittest.TestCase):
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -507,7 +507,7 @@ class TestSwitchFlux(unittest.TestCase):
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -558,7 +558,7 @@ class TestSwitchFlux(unittest.TestCase):
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -606,7 +606,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_with_custom_colortemps(self):
"""Test the flux with custom start and stop colortemps."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -656,7 +656,7 @@ class TestSwitchFlux(unittest.TestCase):
# pylint: disable=invalid-name
def test_flux_with_custom_brightness(self):
"""Test the flux with custom start and stop colortemps."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -704,7 +704,7 @@ class TestSwitchFlux(unittest.TestCase):
def test_flux_with_multiple_lights(self):
"""Test the flux switch with multiple light entities."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -773,7 +773,7 @@ class TestSwitchFlux(unittest.TestCase):
def test_flux_with_mired(self):
"""Test the flux switch´s mode mired."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
@@ -818,7 +818,7 @@ class TestSwitchFlux(unittest.TestCase):
def test_flux_with_rgb(self):
"""Test the flux switch´s mode rgb."""
platform = loader.get_component('light.test')
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
+3 -3
View File
@@ -17,7 +17,7 @@ class TestSwitch(unittest.TestCase):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
platform = loader.get_component('switch.test')
platform = loader.get_component(self.hass, 'switch.test')
platform.init()
# Switch 1 is ON, switch 2 is OFF
self.switch_1, self.switch_2, self.switch_3 = \
@@ -79,10 +79,10 @@ class TestSwitch(unittest.TestCase):
def test_setup_two_platforms(self):
"""Test with bad configuration."""
# Test if switch component returns 0 switches
test_platform = loader.get_component('switch.test')
test_platform = loader.get_component(self.hass, 'switch.test')
test_platform.init(True)
loader.set_component('switch.test2', test_platform)
loader.set_component(self.hass, 'switch.test2', test_platform)
test_platform.init(False)
self.assertTrue(setup_component(
@@ -22,12 +22,12 @@ class TestDeviceSunLightTrigger(unittest.TestCase):
self.hass = get_test_home_assistant()
self.scanner = loader.get_component(
'device_tracker.test').get_scanner(None, None)
self.hass, 'device_tracker.test').get_scanner(None, None)
self.scanner.reset()
self.scanner.come_home('DEV1')
loader.get_component('light.test').init()
loader.get_component(self.hass, 'light.test').init()
with patch(
'homeassistant.components.device_tracker.load_yaml_config_file',