2014-11-02 17:41:41 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.demo
|
2015-05-13 17:18:30 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2015-05-13 17:18:30 +00:00
|
|
|
Sets up a demo environment that mimics interaction with devices.
|
2014-11-02 17:41:41 +00:00
|
|
|
"""
|
2015-01-19 08:02:25 +00:00
|
|
|
import time
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2015-08-17 03:44:46 +00:00
|
|
|
import homeassistant.core as ha
|
2015-02-28 15:31:39 +00:00
|
|
|
import homeassistant.bootstrap as bootstrap
|
2014-11-05 07:34:19 +00:00
|
|
|
import homeassistant.loader as loader
|
2014-12-07 07:57:02 +00:00
|
|
|
from homeassistant.const import (
|
2015-08-24 02:46:18 +00:00
|
|
|
CONF_PLATFORM, ATTR_ENTITY_PICTURE, ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME)
|
2014-11-02 17:41:41 +00:00
|
|
|
|
|
|
|
DOMAIN = "demo"
|
|
|
|
|
2015-08-30 06:21:26 +00:00
|
|
|
DEPENDENCIES = ['introduction', 'conversation']
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2015-03-04 07:50:54 +00:00
|
|
|
COMPONENTS_WITH_DEMO_PLATFORM = [
|
2015-09-13 15:08:46 +00:00
|
|
|
'switch', 'light', 'sensor', 'thermostat', 'media_player', 'notify']
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2014-11-02 17:41:41 +00:00
|
|
|
|
|
|
|
def setup(hass, config):
|
|
|
|
""" Setup a demo environment. """
|
2014-11-05 07:34:19 +00:00
|
|
|
group = loader.get_component('group')
|
2015-01-19 08:02:25 +00:00
|
|
|
configurator = loader.get_component('configurator')
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2014-11-29 06:49:29 +00:00
|
|
|
config.setdefault(ha.DOMAIN, {})
|
|
|
|
config.setdefault(DOMAIN, {})
|
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
if config[DOMAIN].get('hide_demo_state') != 1:
|
2014-11-02 17:41:41 +00:00
|
|
|
hass.states.set('a.Demo_Mode', 'Enabled')
|
|
|
|
|
|
|
|
# Setup sun
|
2015-04-26 00:44:05 +00:00
|
|
|
if not hass.config.latitude:
|
|
|
|
hass.config.latitude = '32.87336'
|
|
|
|
|
|
|
|
if not hass.config.longitude:
|
|
|
|
hass.config.longitude = '117.22743'
|
|
|
|
|
|
|
|
bootstrap.setup_component(hass, 'sun')
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
# Setup demo platforms
|
|
|
|
for component in COMPONENTS_WITH_DEMO_PLATFORM:
|
|
|
|
bootstrap.setup_component(
|
|
|
|
hass, component, {component: {CONF_PLATFORM: 'demo'}})
|
2014-11-02 17:41:41 +00:00
|
|
|
|
|
|
|
# Setup room groups
|
2015-08-30 20:48:40 +00:00
|
|
|
lights = sorted(hass.states.entity_ids('light'))
|
|
|
|
switches = sorted(hass.states.entity_ids('switch'))
|
2015-08-24 02:46:18 +00:00
|
|
|
media_players = sorted(hass.states.entity_ids('media_player'))
|
2015-08-30 20:48:40 +00:00
|
|
|
group.setup_group(hass, 'living room', [lights[2], lights[1], switches[0],
|
2015-08-24 02:46:18 +00:00
|
|
|
media_players[1]])
|
2015-08-30 20:48:40 +00:00
|
|
|
group.setup_group(hass, 'bedroom', [lights[0], switches[1],
|
2015-08-24 02:46:18 +00:00
|
|
|
media_players[0]])
|
2014-11-02 17:41:41 +00:00
|
|
|
|
2015-07-11 06:17:26 +00:00
|
|
|
# Setup IP Camera
|
|
|
|
bootstrap.setup_component(
|
|
|
|
hass, 'camera',
|
|
|
|
{'camera': {
|
|
|
|
'platform': 'generic',
|
|
|
|
'name': 'IP Camera',
|
|
|
|
'still_image_url': 'http://194.218.96.92/jpg/image.jpg',
|
|
|
|
}})
|
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
# Setup scripts
|
|
|
|
bootstrap.setup_component(
|
|
|
|
hass, 'script',
|
2015-03-17 05:45:42 +00:00
|
|
|
{'script': {
|
|
|
|
'demo': {
|
2015-08-30 20:48:40 +00:00
|
|
|
'alias': 'Toggle {}'.format(lights[0].split('.')[1]),
|
2015-03-17 05:20:31 +00:00
|
|
|
'sequence': [{
|
2015-03-17 05:45:42 +00:00
|
|
|
'execute_service': 'light.turn_off',
|
|
|
|
'service_data': {ATTR_ENTITY_ID: lights[0]}
|
|
|
|
}, {
|
|
|
|
'delay': {'seconds': 5}
|
|
|
|
}, {
|
|
|
|
'execute_service': 'light.turn_on',
|
|
|
|
'service_data': {ATTR_ENTITY_ID: lights[0]}
|
|
|
|
}, {
|
|
|
|
'delay': {'seconds': 5}
|
|
|
|
}, {
|
|
|
|
'execute_service': 'light.turn_off',
|
|
|
|
'service_data': {ATTR_ENTITY_ID: lights[0]}
|
|
|
|
}]
|
2015-03-17 05:20:31 +00:00
|
|
|
}}})
|
|
|
|
|
2015-03-17 05:35:57 +00:00
|
|
|
# Setup scenes
|
|
|
|
bootstrap.setup_component(
|
|
|
|
hass, 'scene',
|
|
|
|
{'scene': [
|
|
|
|
{'name': 'Romantic lights',
|
|
|
|
'entities': {
|
2015-03-17 05:45:42 +00:00
|
|
|
lights[0]: True,
|
|
|
|
lights[1]: {'state': 'on', 'xy_color': [0.33, 0.66],
|
|
|
|
'brightness': 200},
|
2015-03-17 05:35:57 +00:00
|
|
|
}},
|
|
|
|
{'name': 'Switch on and off',
|
|
|
|
'entities': {
|
2015-03-17 05:45:42 +00:00
|
|
|
switches[0]: True,
|
|
|
|
switches[1]: False,
|
2015-03-17 05:35:57 +00:00
|
|
|
}},
|
2015-03-17 05:45:42 +00:00
|
|
|
]})
|
2015-03-17 05:35:57 +00:00
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
# Setup fake device tracker
|
|
|
|
hass.states.set("device_tracker.paulus", "home",
|
2014-11-02 19:22:22 +00:00
|
|
|
{ATTR_ENTITY_PICTURE:
|
2015-08-24 02:46:18 +00:00
|
|
|
"http://graph.facebook.com/297400035/picture",
|
|
|
|
ATTR_FRIENDLY_NAME: 'Paulus'})
|
2015-03-17 05:20:31 +00:00
|
|
|
hass.states.set("device_tracker.anne_therese", "not_home",
|
2015-08-24 02:46:18 +00:00
|
|
|
{ATTR_FRIENDLY_NAME: 'Anne Therese'})
|
2014-11-02 19:22:22 +00:00
|
|
|
|
2014-11-02 17:41:41 +00:00
|
|
|
hass.states.set("group.all_devices", "home",
|
|
|
|
{
|
|
|
|
"auto": True,
|
2015-03-17 05:20:31 +00:00
|
|
|
ATTR_ENTITY_ID: [
|
2015-06-22 07:25:56 +00:00
|
|
|
"device_tracker.paulus",
|
|
|
|
"device_tracker.anne_therese"
|
2014-11-02 17:41:41 +00:00
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
# Setup configurator
|
2015-01-19 08:02:25 +00:00
|
|
|
configurator_ids = []
|
|
|
|
|
|
|
|
def hue_configuration_callback(data):
|
|
|
|
""" Fake callback, mark config as done. """
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
# First time it is called, pretend it failed.
|
|
|
|
if len(configurator_ids) == 1:
|
|
|
|
configurator.notify_errors(
|
2015-01-20 05:39:24 +00:00
|
|
|
configurator_ids[0],
|
2015-01-19 08:02:25 +00:00
|
|
|
"Failed to register, please try again.")
|
|
|
|
|
|
|
|
configurator_ids.append(0)
|
|
|
|
else:
|
2015-01-20 05:39:24 +00:00
|
|
|
configurator.request_done(configurator_ids[0])
|
2015-01-19 08:02:25 +00:00
|
|
|
|
|
|
|
request_id = configurator.request_config(
|
|
|
|
hass, "Philips Hue", hue_configuration_callback,
|
|
|
|
description=("Press the button on the bridge to register Philips Hue "
|
|
|
|
"with Home Assistant."),
|
|
|
|
description_image="/static/images/config_philips_hue.jpg",
|
|
|
|
submit_caption="I have pressed the button"
|
|
|
|
)
|
|
|
|
|
|
|
|
configurator_ids.append(request_id)
|
|
|
|
|
2014-11-02 17:41:41 +00:00
|
|
|
return True
|