2017-04-30 05:04:49 +00:00
|
|
|
"""
|
|
|
|
Demo platform for the Device tracker component.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/demo/
|
|
|
|
"""
|
2015-09-22 05:46:08 +00:00
|
|
|
import random
|
|
|
|
|
|
|
|
from homeassistant.components.device_tracker import DOMAIN
|
|
|
|
|
|
|
|
|
2017-02-07 19:47:11 +00:00
|
|
|
def setup_scanner(hass, config, see, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the demo tracker."""
|
2015-09-22 05:46:08 +00:00
|
|
|
def offset():
|
2016-03-07 17:12:06 +00:00
|
|
|
"""Return random offset."""
|
2015-09-22 05:46:08 +00:00
|
|
|
return (random.randrange(500, 2000)) / 2e5 * random.choice((-1, 1))
|
|
|
|
|
|
|
|
def random_see(dev_id, name):
|
2016-03-07 17:12:06 +00:00
|
|
|
"""Randomize a sighting."""
|
2015-09-22 05:46:08 +00:00
|
|
|
see(
|
|
|
|
dev_id=dev_id,
|
|
|
|
host_name=name,
|
|
|
|
gps=(hass.config.latitude + offset(),
|
|
|
|
hass.config.longitude + offset()),
|
|
|
|
gps_accuracy=random.randrange(50, 150),
|
|
|
|
battery=random.randrange(10, 90)
|
|
|
|
)
|
|
|
|
|
|
|
|
def observe(call=None):
|
2016-03-07 17:12:06 +00:00
|
|
|
"""Observe three entities."""
|
2015-09-22 05:46:08 +00:00
|
|
|
random_see('demo_paulus', 'Paulus')
|
|
|
|
random_see('demo_anne_therese', 'Anne Therese')
|
|
|
|
|
|
|
|
observe()
|
|
|
|
|
|
|
|
see(
|
|
|
|
dev_id='demo_home_boy',
|
|
|
|
host_name='Home Boy',
|
|
|
|
gps=[hass.config.latitude - 0.00002, hass.config.longitude + 0.00002],
|
|
|
|
gps_accuracy=20,
|
|
|
|
battery=53
|
|
|
|
)
|
|
|
|
|
|
|
|
hass.services.register(DOMAIN, 'demo', observe)
|
|
|
|
|
|
|
|
return True
|