mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Updates to demo component and platforms
This commit is contained in:
parent
a4af51af14
commit
71803658f5
@ -10,7 +10,7 @@ import homeassistant as ha
|
||||
import homeassistant.bootstrap as bootstrap
|
||||
import homeassistant.loader as loader
|
||||
from homeassistant.const import (
|
||||
CONF_PLATFORM, ATTR_ENTITY_PICTURE,
|
||||
CONF_PLATFORM, ATTR_ENTITY_PICTURE, ATTR_ENTITY_ID,
|
||||
CONF_LATITUDE, CONF_LONGITUDE)
|
||||
|
||||
DOMAIN = "demo"
|
||||
@ -18,7 +18,7 @@ DOMAIN = "demo"
|
||||
DEPENDENCIES = []
|
||||
|
||||
COMPONENTS_WITH_DEMO_PLATFORM = [
|
||||
'switch', 'light', 'thermostat', 'sensor', 'media_player']
|
||||
'switch', 'light', 'thermostat', 'sensor', 'media_player', 'notify']
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
@ -29,16 +29,12 @@ def setup(hass, config):
|
||||
config.setdefault(ha.DOMAIN, {})
|
||||
config.setdefault(DOMAIN, {})
|
||||
|
||||
if config[DOMAIN].get('hide_demo_state') != '1':
|
||||
if config[DOMAIN].get('hide_demo_state') != 1:
|
||||
hass.states.set('a.Demo_Mode', 'Enabled')
|
||||
|
||||
# Setup sun
|
||||
if CONF_LATITUDE not in config[ha.DOMAIN]:
|
||||
config[ha.DOMAIN][CONF_LATITUDE] = '32.87336'
|
||||
|
||||
if CONF_LONGITUDE not in config[ha.DOMAIN]:
|
||||
config[ha.DOMAIN][CONF_LONGITUDE] = '-117.22743'
|
||||
|
||||
config[ha.DOMAIN].setdefault(CONF_LATITUDE, '32.87336')
|
||||
config[ha.DOMAIN].setdefault(CONF_LONGITUDE, '-117.22743')
|
||||
loader.get_component('sun').setup(hass, config)
|
||||
|
||||
# Setup demo platforms
|
||||
@ -52,18 +48,40 @@ def setup(hass, config):
|
||||
group.setup_group(hass, 'living room', [lights[0], lights[1], switches[0]])
|
||||
group.setup_group(hass, 'bedroom', [lights[2], switches[1]])
|
||||
|
||||
# Setup device tracker
|
||||
hass.states.set("device_tracker.Paulus", "home",
|
||||
# Setup scripts
|
||||
bootstrap.setup_component(
|
||||
hass, 'script',
|
||||
{'script':
|
||||
{'demo': {
|
||||
'alias': 'Demo {}'.format(lights[0]),
|
||||
'sequence': [{
|
||||
'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]}
|
||||
}]
|
||||
}}})
|
||||
|
||||
# Setup fake device tracker
|
||||
hass.states.set("device_tracker.paulus", "home",
|
||||
{ATTR_ENTITY_PICTURE:
|
||||
"http://graph.facebook.com/schoutsen/picture"})
|
||||
hass.states.set("device_tracker.Anne_Therese", "not_home",
|
||||
hass.states.set("device_tracker.anne_therese", "not_home",
|
||||
{ATTR_ENTITY_PICTURE:
|
||||
"http://graph.facebook.com/anne.t.frederiksen/picture"})
|
||||
|
||||
hass.states.set("group.all_devices", "home",
|
||||
{
|
||||
"auto": True,
|
||||
"entity_id": [
|
||||
ATTR_ENTITY_ID: [
|
||||
"device_tracker.Paulus",
|
||||
"device_tracker.Anne_Therese"
|
||||
]
|
||||
|
@ -30,6 +30,11 @@ class DemoLight(ToggleDevice):
|
||||
self._xy = xy or random.choice(LIGHT_COLORS)
|
||||
self._brightness = brightness
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo light. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device if any. """
|
||||
|
@ -34,6 +34,11 @@ class DemoMediaPlayer(MediaPlayerDevice):
|
||||
self.media_title = media_title
|
||||
self.volume = 1.0
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo componentn. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device. """
|
||||
|
31
homeassistant/components/notify/demo.py
Normal file
31
homeassistant/components/notify/demo.py
Normal file
@ -0,0 +1,31 @@
|
||||
"""
|
||||
homeassistant.components.notify.demo
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Demo notification service.
|
||||
"""
|
||||
from homeassistant.components.notify import ATTR_TITLE, BaseNotificationService
|
||||
|
||||
|
||||
EVENT_NOTIFY = "notify"
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the demo notification service. """
|
||||
|
||||
return DemoNotificationService(hass)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class DemoNotificationService(BaseNotificationService):
|
||||
""" Implements demo notification service. """
|
||||
|
||||
def __init__(self, hass):
|
||||
self.hass = hass
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
||||
self.hass.bus.fire(EVENT_NOTIFY, {"title": title, "message": message})
|
@ -21,6 +21,11 @@ class DemoSensor(Device):
|
||||
self._state = state
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo sensor. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device. """
|
||||
|
@ -18,6 +18,11 @@ class DemoSwitch(ToggleDevice):
|
||||
self._name = name or DEVICE_DEFAULT_NAME
|
||||
self._state = state
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo switch. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device if any. """
|
||||
|
@ -26,6 +26,11 @@ class DemoThermostat(ThermostatDevice):
|
||||
self._away = away
|
||||
self._current_temperature = current_temperature
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo thermostat. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name. """
|
||||
|
@ -63,12 +63,14 @@ class TestDemo(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
STATE_OFF, self.hass.states.get(entity_id).state)
|
||||
|
||||
def test_hiding_demo_state(self):
|
||||
""" Test if you can hide the demo card. """
|
||||
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': '1'}})
|
||||
|
||||
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|
||||
|
||||
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': '0'}})
|
||||
def test_if_demo_state_shows_by_default(self):
|
||||
""" Test if demo state shows if we give no configuration. """
|
||||
demo.setup(self.hass, {demo.DOMAIN: {}})
|
||||
|
||||
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
||||
|
||||
def test_hiding_demo_state(self):
|
||||
""" Test if you can hide the demo card. """
|
||||
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
||||
|
||||
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user