2019-04-03 15:40:03 +00:00
|
|
|
"""Demo platform for the Device tracker component."""
|
2021-12-30 17:50:51 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-01-11 16:29:04 +00:00
|
|
|
from collections.abc import Callable
|
2015-09-22 05:46:08 +00:00
|
|
|
import random
|
|
|
|
|
2022-01-11 16:29:04 +00:00
|
|
|
from homeassistant.core import HomeAssistant, ServiceCall
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2021-12-30 17:50:51 +00:00
|
|
|
|
2019-11-28 04:36:40 +00:00
|
|
|
from .const import DOMAIN, SERVICE_RANDOMIZE_DEVICE_TRACKER_DATA
|
2015-09-22 05:46:08 +00:00
|
|
|
|
|
|
|
|
2022-01-11 16:29:04 +00:00
|
|
|
def setup_scanner(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
see: Callable[..., None],
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> bool:
|
2017-04-30 05:04:49 +00:00
|
|
|
"""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
|
|
|
)
|
|
|
|
|
2021-12-30 17:50:51 +00:00
|
|
|
def observe(call: ServiceCall | None = None) -> 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
|
|
|
)
|
|
|
|
|
2019-11-28 04:36:40 +00:00
|
|
|
hass.services.register(DOMAIN, SERVICE_RANDOMIZE_DEVICE_TRACKER_DATA, observe)
|
2015-09-22 05:46:08 +00:00
|
|
|
|
|
|
|
return True
|