mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Renamed mock_switch_platform to mock_toggledevice_platform
This commit is contained in:
parent
3e348880d5
commit
845a028d42
@ -7,7 +7,7 @@ Provides a mock switch platform.
|
|||||||
import homeassistant.components as components
|
import homeassistant.components as components
|
||||||
|
|
||||||
|
|
||||||
class MockSwitch(components.ToggleDevice):
|
class MockToggleDevice(components.ToggleDevice):
|
||||||
""" Fake switch. """
|
""" Fake switch. """
|
||||||
def __init__(self, name, state):
|
def __init__(self, name, state):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -34,22 +34,24 @@ class MockSwitch(components.ToggleDevice):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
FAKE_NO_SWITCHES = False
|
FAKE_NO_DEVICES = False
|
||||||
|
|
||||||
SWITCHES = [
|
DEVICES = [
|
||||||
MockSwitch('AC', components.STATE_ON),
|
MockToggleDevice('AC', components.STATE_ON),
|
||||||
MockSwitch('AC', components.STATE_OFF),
|
MockToggleDevice('AC', components.STATE_OFF),
|
||||||
MockSwitch(None, components.STATE_OFF)
|
MockToggleDevice(None, components.STATE_OFF)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def fake_no_switches(do_fake):
|
def fake_no_switches(do_fake):
|
||||||
""" Set the platform to act as if it has no switches. """
|
""" Set the platform to act as if it has no devices. """
|
||||||
global FAKE_NO_SWITCHES
|
global FAKE_NO_DEVICES
|
||||||
|
|
||||||
FAKE_NO_SWITCHES = do_fake
|
FAKE_NO_DEVICES = do_fake
|
||||||
|
|
||||||
|
|
||||||
def get_switches(hass, config):
|
def get_switches(hass, config):
|
||||||
""" Returns mock switches. """
|
""" Returns mock devices. """
|
||||||
return [] if FAKE_NO_SWITCHES else SWITCHES
|
return [] if FAKE_NO_DEVICES else DEVICES
|
||||||
|
|
||||||
|
get_lights = get_switches
|
@ -1,8 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
test.test_component_chromecast
|
test.test_component_switch
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Tests Chromecast component.
|
Tests switch component.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-public-methods,protected-access
|
# pylint: disable=too-many-public-methods,protected-access
|
||||||
import unittest
|
import unittest
|
||||||
@ -12,7 +12,7 @@ import homeassistant.loader as loader
|
|||||||
import homeassistant.components as components
|
import homeassistant.components as components
|
||||||
import homeassistant.components.switch as switch
|
import homeassistant.components.switch as switch
|
||||||
|
|
||||||
import mock_switch_platform
|
import mock_toggledevice_platform
|
||||||
|
|
||||||
|
|
||||||
class TestSwitch(unittest.TestCase):
|
class TestSwitch(unittest.TestCase):
|
||||||
@ -21,7 +21,7 @@ class TestSwitch(unittest.TestCase):
|
|||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
self.hass = ha.HomeAssistant()
|
self.hass = ha.HomeAssistant()
|
||||||
loader.prepare(self.hass)
|
loader.prepare(self.hass)
|
||||||
loader.set_component('switch.test', mock_switch_platform)
|
loader.set_component('switch.test', mock_toggledevice_platform)
|
||||||
|
|
||||||
self.assertTrue(switch.setup(
|
self.assertTrue(switch.setup(
|
||||||
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
|
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
|
||||||
@ -29,7 +29,7 @@ class TestSwitch(unittest.TestCase):
|
|||||||
|
|
||||||
# Switch 1 is ON, switch 2 is OFF
|
# Switch 1 is ON, switch 2 is OFF
|
||||||
self.switch_1, self.switch_2, self.switch_3 = \
|
self.switch_1, self.switch_2, self.switch_3 = \
|
||||||
mock_switch_platform.get_switches(None, None)
|
mock_toggledevice_platform.get_switches(None, None)
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
@ -92,12 +92,13 @@ class TestSwitch(unittest.TestCase):
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Test if switch component returns 0 switches
|
# Test if switch component returns 0 switches
|
||||||
mock_switch_platform.fake_no_switches(True)
|
mock_toggledevice_platform.fake_no_switches(True)
|
||||||
|
|
||||||
self.assertEqual([], mock_switch_platform.get_switches(None, None))
|
self.assertEqual(
|
||||||
|
[], mock_toggledevice_platform.get_switches(None, None))
|
||||||
|
|
||||||
self.assertFalse(switch.setup(
|
self.assertFalse(switch.setup(
|
||||||
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
|
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
|
||||||
))
|
))
|
||||||
|
|
||||||
mock_switch_platform.fake_no_switches(False)
|
mock_toggledevice_platform.fake_no_switches(False)
|
||||||
|
@ -11,7 +11,7 @@ import homeassistant as ha
|
|||||||
import homeassistant.loader as loader
|
import homeassistant.loader as loader
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
|
|
||||||
import mock_switch_platform
|
import mock_toggledevice_platform
|
||||||
|
|
||||||
|
|
||||||
class TestLoader(unittest.TestCase):
|
class TestLoader(unittest.TestCase):
|
||||||
@ -26,10 +26,10 @@ class TestLoader(unittest.TestCase):
|
|||||||
|
|
||||||
def test_set_component(self):
|
def test_set_component(self):
|
||||||
""" Test if set_component works. """
|
""" Test if set_component works. """
|
||||||
loader.set_component('switch.test', mock_switch_platform)
|
loader.set_component('switch.test', mock_toggledevice_platform)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_switch_platform, loader.get_component('switch.test'))
|
mock_toggledevice_platform, loader.get_component('switch.test'))
|
||||||
|
|
||||||
def test_get_component(self):
|
def test_get_component(self):
|
||||||
""" Test if get_component works. """
|
""" Test if get_component works. """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user