2019-02-13 20:21:14 +00:00
|
|
|
"""Support for tracking a Volvo."""
|
2022-01-10 15:13:54 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from collections.abc import Awaitable, Callable
|
|
|
|
|
2018-11-30 18:07:42 +00:00
|
|
|
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
|
2022-01-10 15:13:54 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-10 15:13:54 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.util import slugify
|
|
|
|
|
|
|
|
from . import DATA_KEY, SIGNAL_STATE_UPDATED
|
2016-10-02 06:00:01 +00:00
|
|
|
|
|
|
|
|
2022-01-10 15:13:54 +00:00
|
|
|
async def async_setup_scanner(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
async_see: Callable[..., Awaitable[None]],
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
2022-01-10 21:47:24 +00:00
|
|
|
) -> bool:
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Volvo tracker."""
|
2017-02-19 01:09:25 +00:00
|
|
|
if discovery_info is None:
|
2022-01-10 21:47:24 +00:00
|
|
|
return False
|
2016-10-02 06:00:01 +00:00
|
|
|
|
2021-12-03 19:07:03 +00:00
|
|
|
vin, component, attr, slug_attr = discovery_info
|
2018-11-30 18:07:42 +00:00
|
|
|
data = hass.data[DATA_KEY]
|
2021-12-03 19:07:03 +00:00
|
|
|
instrument = data.instrument(vin, component, attr, slug_attr)
|
2016-11-18 22:12:51 +00:00
|
|
|
|
2018-11-30 18:07:42 +00:00
|
|
|
async def see_vehicle():
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Handle the reporting of the vehicle position."""
|
2018-11-30 18:07:42 +00:00
|
|
|
host_name = instrument.vehicle_name
|
2021-04-09 16:58:27 +00:00
|
|
|
dev_id = f"volvo_{slugify(host_name)}"
|
2019-07-31 19:25:30 +00:00
|
|
|
await async_see(
|
|
|
|
dev_id=dev_id,
|
|
|
|
host_name=host_name,
|
|
|
|
source_type=SOURCE_TYPE_GPS,
|
|
|
|
gps=instrument.state,
|
|
|
|
icon="mdi:car",
|
|
|
|
)
|
2018-11-30 18:07:42 +00:00
|
|
|
|
|
|
|
async_dispatcher_connect(hass, SIGNAL_STATE_UPDATED, see_vehicle)
|
2022-01-10 21:47:24 +00:00
|
|
|
|
|
|
|
return True
|