1 """Support for Volvo On Call."""
3 from aiohttp.client_exceptions
import ClientResponseError
4 from volvooncall
import Connection
5 from volvooncall.dashboard
import Instrument
18 UNIT_SYSTEM_SCANDINAVIAN_MILES,
21 from .errors
import InvalidAuth
25 """Hold component state."""
30 connection: Connection,
33 """Initialize the component state."""
35 self.vehicles: set[str] = set()
36 self.instruments: set[Instrument] = set()
41 """Return corresponding instrument."""
44 for instrument
in self.instruments
45 if instrument.vehicle.vin == vin
46 and instrument.component == component
47 and instrument.attr == attr
48 and instrument.slug_attr == slug_attr
52 """Provide a friendly name for a vehicle."""
53 if vehicle.registration_number
and vehicle.registration_number !=
"UNKNOWN":
54 return vehicle.registration_number
60 """Load relevant platforms."""
61 self.vehicles.
add(vehicle.vin)
63 dashboard = vehicle.dashboard(
64 mutable=self.
config_entryconfig_entry.data[CONF_MUTABLE],
67 == UNIT_SYSTEM_SCANDINAVIAN_MILES
70 self.
config_entryconfig_entry.data[CONF_UNIT_SYSTEM] == UNIT_SYSTEM_IMPERIAL
76 for instrument
in dashboard.instruments
77 if instrument.component
in PLATFORMS
79 self.instruments.
add(instrument)
83 """Update status from the online service."""
86 except ClientResponseError
as ex:
91 for vehicle
in self.
connectionconnection.vehicles:
92 if vehicle.vin
not in self.vehicles:
96 """Check if provided username/password/region authenticate."""
99 except ClientResponseError
as exc:
100 raise InvalidAuth
from exc
def instrument(self, vin, component, attr, slug_attr)
def discover_vehicle(self, vehicle)
def vehicle_name(self, vehicle)
None __init__(self, HomeAssistant hass, Connection connection, ConfigEntry entry)
bool add(self, _T matcher)
web.Response get(self, web.Request request, str config_key)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)