1 """Select platform for BMW."""
3 from collections.abc
import Callable, Coroutine
4 from dataclasses
import dataclass
8 from bimmer_connected.models
import MyBMWAPIError
9 from bimmer_connected.vehicle
import MyBMWVehicle
10 from bimmer_connected.vehicle.charging_profile
import ChargingMode
18 from .
import BMWConfigEntry
19 from .coordinator
import BMWDataUpdateCoordinator
20 from .entity
import BMWBaseEntity
22 _LOGGER = logging.getLogger(__name__)
25 @dataclass(frozen=True, kw_only=True)
27 """Describes BMW sensor entity."""
29 current_option: Callable[[MyBMWVehicle], str]
30 remote_service: Callable[[MyBMWVehicle, str], Coroutine[Any, Any, Any]]
31 is_available: Callable[[MyBMWVehicle], bool] =
lambda _:
False
32 dynamic_options: Callable[[MyBMWVehicle], list[str]] |
None =
None
35 SELECT_TYPES: tuple[BMWSelectEntityDescription, ...] = (
38 translation_key=
"ac_limit",
39 is_available=
lambda v: v.is_remote_set_ac_limit_enabled,
40 dynamic_options=
lambda v: [
42 for lim
in v.charging_profile.ac_available_limits
44 current_option=
lambda v:
str(v.charging_profile.ac_current_limit),
45 remote_service=
lambda v, o: v.remote_services.trigger_charging_settings_update(
48 unit_of_measurement=UnitOfElectricCurrent.AMPERE,
52 translation_key=
"charging_mode",
53 is_available=
lambda v: v.is_charging_plan_supported,
54 options=[c.value.lower()
for c
in ChargingMode
if c != ChargingMode.UNKNOWN],
55 current_option=
lambda v: v.charging_profile.charging_mode.value.lower(),
56 remote_service=
lambda v, o: v.remote_services.trigger_charging_profile_update(
57 charging_mode=ChargingMode(o)
65 config_entry: BMWConfigEntry,
66 async_add_entities: AddEntitiesCallback,
68 """Set up the MyBMW lock from config entry."""
69 coordinator = config_entry.runtime_data.coordinator
71 entities: list[BMWSelect] = []
73 for vehicle
in coordinator.account.vehicles:
74 if not coordinator.read_only:
77 BMWSelect(coordinator, vehicle, description)
78 for description
in SELECT_TYPES
79 if description.is_available(vehicle)
86 """Representation of BMW select entity."""
88 entity_description: BMWSelectEntityDescription
92 coordinator: BMWDataUpdateCoordinator,
93 vehicle: MyBMWVehicle,
94 description: BMWSelectEntityDescription,
96 """Initialize an BMW select."""
97 super().
__init__(coordinator, vehicle)
100 if description.dynamic_options:
106 """Handle updated data from the coordinator."""
114 """Update to the vehicle."""
116 "Executing '%s' on vehicle '%s' to value '%s'",
123 except MyBMWAPIError
as ex:
None _handle_coordinator_update(self)
None async_select_option(self, str option)
None __init__(self, BMWDataUpdateCoordinator coordinator, MyBMWVehicle vehicle, BMWSelectEntityDescription description)
str|None current_option(self)
None async_update_listeners(self)
None async_setup_entry(HomeAssistant hass, BMWConfigEntry config_entry, AddEntitiesCallback async_add_entities)