1 """Switch 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.fuel_and_battery
import ChargingState
17 from .
import BMWConfigEntry
18 from .coordinator
import BMWDataUpdateCoordinator
19 from .entity
import BMWBaseEntity
21 _LOGGER = logging.getLogger(__name__)
24 @dataclass(frozen=True, kw_only=True)
26 """Describes BMW switch entity."""
28 value_fn: Callable[[MyBMWVehicle], bool]
29 remote_service_on: Callable[[MyBMWVehicle], Coroutine[Any, Any, Any]]
30 remote_service_off: Callable[[MyBMWVehicle], Coroutine[Any, Any, Any]]
31 is_available: Callable[[MyBMWVehicle], bool] =
lambda _:
False
32 dynamic_options: Callable[[MyBMWVehicle], list[str]] |
None =
None
36 ChargingState.CHARGING,
37 ChargingState.COMPLETE,
38 ChargingState.FULLY_CHARGED,
39 ChargingState.FINISHED_FULLY_CHARGED,
40 ChargingState.FINISHED_NOT_FULL,
41 ChargingState.TARGET_REACHED,
44 NUMBER_TYPES: list[BMWSwitchEntityDescription] = [
47 translation_key=
"climate",
48 is_available=
lambda v: v.is_remote_climate_stop_enabled,
49 value_fn=
lambda v: v.climate.is_climate_on,
50 remote_service_on=
lambda v: v.remote_services.trigger_remote_air_conditioning(),
51 remote_service_off=
lambda v: v.remote_services.trigger_remote_air_conditioning_stop(),
55 translation_key=
"charging",
56 is_available=
lambda v: v.is_remote_charge_stop_enabled,
57 value_fn=
lambda v: v.fuel_and_battery.charging_status
in CHARGING_STATE_ON,
58 remote_service_on=
lambda v: v.remote_services.trigger_charge_start(),
59 remote_service_off=
lambda v: v.remote_services.trigger_charge_stop(),
66 config_entry: BMWConfigEntry,
67 async_add_entities: AddEntitiesCallback,
69 """Set up the MyBMW switch from config entry."""
70 coordinator = config_entry.runtime_data.coordinator
72 entities: list[BMWSwitch] = []
74 for vehicle
in coordinator.account.vehicles:
75 if not coordinator.read_only:
78 BMWSwitch(coordinator, vehicle, description)
79 for description
in NUMBER_TYPES
80 if description.is_available(vehicle)
87 """Representation of BMW Switch entity."""
89 entity_description: BMWSwitchEntityDescription
93 coordinator: BMWDataUpdateCoordinator,
94 vehicle: MyBMWVehicle,
95 description: BMWSwitchEntityDescription,
97 """Initialize an BMW Switch."""
98 super().
__init__(coordinator, vehicle)
104 """Return the entity value to represent the entity state."""
108 """Turn the switch on."""
111 except MyBMWAPIError
as ex:
117 """Turn the switch off."""
120 except MyBMWAPIError
as ex:
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, BMWDataUpdateCoordinator coordinator, MyBMWVehicle vehicle, BMWSwitchEntityDescription description)
None async_update_listeners(self)
None async_setup_entry(HomeAssistant hass, BMWConfigEntry config_entry, AddEntitiesCallback async_add_entities)