1 """Support for BMW notifications."""
3 from __future__
import annotations
6 from typing
import Any, cast
8 from bimmer_connected.models
import MyBMWAPIError, PointOfInterest
9 from bimmer_connected.vehicle
import MyBMWVehicle
10 import voluptuous
as vol
15 BaseNotificationService,
23 from .
import DOMAIN, BMWConfigEntry
25 ATTR_LOCATION_ATTRIBUTES = [
"street",
"city",
"postal_code",
"country"]
27 POI_SCHEMA = vol.Schema(
29 vol.Required(ATTR_LATITUDE): cv.latitude,
30 vol.Required(ATTR_LONGITUDE): cv.longitude,
31 vol.Optional(
"street"): cv.string,
32 vol.Optional(
"city"): cv.string,
33 vol.Optional(
"postal_code"): cv.string,
34 vol.Optional(
"country"): cv.string,
38 _LOGGER = logging.getLogger(__name__)
44 discovery_info: DiscoveryInfoType |
None =
None,
45 ) -> BMWNotificationService:
46 """Get the BMW notification service."""
47 config_entry: BMWConfigEntry |
None = hass.config_entries.async_get_entry(
48 (discovery_info
or {})[CONF_ENTITY_ID]
54 and (coordinator := config_entry.runtime_data.coordinator)
55 and not coordinator.read_only
57 targets.update({v.name: v
for v
in coordinator.account.vehicles})
62 """Send Notifications to BMW."""
64 vehicle_targets: dict[str, MyBMWVehicle]
66 def __init__(self, targets: dict[str, MyBMWVehicle]) ->
None:
67 """Set up the notification service."""
71 def targets(self) -> dict[str, Any] | None:
72 """Return a dictionary of registered targets."""
76 """Send a message or POI to the car."""
80 poi_data = kwargs.get(ATTR_DATA)
or {}
84 poi = PointOfInterest(
85 lat=poi_data.pop(ATTR_LATITUDE),
86 lon=poi_data.pop(ATTR_LONGITUDE),
87 name=(message
or None),
91 except (vol.Invalid, TypeError, ValueError)
as ex:
93 translation_domain=DOMAIN,
94 translation_key=
"invalid_poi",
95 translation_placeholders={
96 "poi_exception":
str(ex),
100 for vehicle
in kwargs[ATTR_TARGET]:
101 vehicle = cast(MyBMWVehicle, vehicle)
102 _LOGGER.debug(
"Sending message to %s", vehicle.name)
105 await vehicle.remote_services.trigger_send_poi(poi)
106 except MyBMWAPIError
as ex:
dict[str, Any]|None targets(self)
None __init__(self, dict[str, MyBMWVehicle] targets)
None async_send_message(self, str message="", **Any kwargs)
BMWNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)