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
|
|
|
|
|
2022-07-31 12:01:18 +00:00
|
|
|
from homeassistant.components.device_tracker import AsyncSeeCallback, SourceType
|
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
|
|
|
|
|
2022-08-04 17:44:39 +00:00
|
|
|
from . import DATA_KEY, SIGNAL_STATE_UPDATED, VolvoUpdateCoordinator
|
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,
|
2022-07-28 22:27:47 +00:00
|
|
|
async_see: AsyncSeeCallback,
|
2022-01-10 15:13:54 +00:00
|
|
|
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
|
2022-08-04 17:44:39 +00:00
|
|
|
coordinator: VolvoUpdateCoordinator = hass.data[DATA_KEY]
|
|
|
|
volvo_data = coordinator.volvo_data
|
|
|
|
instrument = volvo_data.instrument(vin, component, attr, slug_attr)
|
|
|
|
|
|
|
|
if instrument is None:
|
|
|
|
return False
|
2016-11-18 22:12:51 +00:00
|
|
|
|
2022-07-28 22:27:47 +00:00
|
|
|
async def see_vehicle() -> None:
|
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,
|
2022-07-31 12:01:18 +00:00
|
|
|
source_type=SourceType.GPS,
|
2019-07-31 19:25:30 +00:00
|
|
|
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
|