core/homeassistant/components/demo/device_tracker.py

42 lines
1.2 KiB
Python
Raw Normal View History

"""Demo platform for the Device tracker component."""
2015-09-22 05:46:08 +00:00
import random
from .const import DOMAIN, SERVICE_RANDOMIZE_DEVICE_TRACKER_DATA
2015-09-22 05:46:08 +00:00
def setup_scanner(hass, config, see, discovery_info=None):
"""Set up the demo tracker."""
2019-07-31 19:25:30 +00:00
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,
2019-07-31 19:25:30 +00:00
gps=(hass.config.latitude + offset(), hass.config.longitude + offset()),
2015-09-22 05:46:08 +00:00
gps_accuracy=random.randrange(50, 150),
2019-07-31 19:25:30 +00:00
battery=random.randrange(10, 90),
2015-09-22 05:46:08 +00:00
)
def observe(call=None):
2016-03-07 17:12:06 +00:00
"""Observe three entities."""
2019-07-31 19:25:30 +00:00
random_see("demo_paulus", "Paulus")
random_see("demo_anne_therese", "Anne Therese")
2015-09-22 05:46:08 +00:00
observe()
see(
2019-07-31 19:25:30 +00:00
dev_id="demo_home_boy",
host_name="Home Boy",
2015-09-22 05:46:08 +00:00
gps=[hass.config.latitude - 0.00002, hass.config.longitude + 0.00002],
gps_accuracy=20,
2019-07-31 19:25:30 +00:00
battery=53,
2015-09-22 05:46:08 +00:00
)
hass.services.register(DOMAIN, SERVICE_RANDOMIZE_DEVICE_TRACKER_DATA, observe)
2015-09-22 05:46:08 +00:00
return True