2014-11-25 08:20:36 +00:00
|
|
|
"""
|
|
|
|
test.mock.switch_platform
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Provides a mock switch platform.
|
|
|
|
"""
|
|
|
|
import homeassistant.components as components
|
|
|
|
|
|
|
|
|
2014-11-26 03:16:42 +00:00
|
|
|
class MockToggleDevice(components.ToggleDevice):
|
2014-11-25 08:20:36 +00:00
|
|
|
""" Fake switch. """
|
|
|
|
def __init__(self, name, state):
|
|
|
|
self.name = name
|
|
|
|
self.state = state
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
""" Returns the name of the device if any. """
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
""" Turn the device on. """
|
|
|
|
self.state = components.STATE_ON
|
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
""" Turn the device off. """
|
|
|
|
self.state = components.STATE_OFF
|
|
|
|
|
|
|
|
def is_on(self):
|
|
|
|
""" True if device is on. """
|
|
|
|
return self.state == components.STATE_ON
|
|
|
|
|
|
|
|
def get_state_attributes(self):
|
|
|
|
""" Returns optional state attributes. """
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2014-11-26 03:16:42 +00:00
|
|
|
FAKE_NO_DEVICES = False
|
2014-11-25 08:20:36 +00:00
|
|
|
|
2014-11-26 03:16:42 +00:00
|
|
|
DEVICES = [
|
|
|
|
MockToggleDevice('AC', components.STATE_ON),
|
|
|
|
MockToggleDevice('AC', components.STATE_OFF),
|
|
|
|
MockToggleDevice(None, components.STATE_OFF)
|
2014-11-25 08:20:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def fake_no_switches(do_fake):
|
2014-11-26 03:16:42 +00:00
|
|
|
""" Set the platform to act as if it has no devices. """
|
|
|
|
global FAKE_NO_DEVICES
|
2014-11-25 08:20:36 +00:00
|
|
|
|
2014-11-26 03:16:42 +00:00
|
|
|
FAKE_NO_DEVICES = do_fake
|
2014-11-25 08:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_switches(hass, config):
|
2014-11-26 03:16:42 +00:00
|
|
|
""" Returns mock devices. """
|
|
|
|
return [] if FAKE_NO_DEVICES else DEVICES
|
|
|
|
|
|
|
|
get_lights = get_switches
|