Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base for all BMW entities."""
2 
3 from __future__ import annotations
4 
5 from bimmer_connected.vehicle import MyBMWVehicle
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.update_coordinator import CoordinatorEntity
9 
10 from .const import DOMAIN
11 from .coordinator import BMWDataUpdateCoordinator
12 
13 
14 class BMWBaseEntity(CoordinatorEntity[BMWDataUpdateCoordinator]):
15  """Common base for BMW entities."""
16 
17  _attr_has_entity_name = True
18 
19  def __init__(
20  self,
21  coordinator: BMWDataUpdateCoordinator,
22  vehicle: MyBMWVehicle,
23  ) -> None:
24  """Initialize entity."""
25  super().__init__(coordinator)
26 
27  self.vehiclevehicle = vehicle
28 
29  self._attr_device_info_attr_device_info = DeviceInfo(
30  identifiers={(DOMAIN, vehicle.vin)},
31  manufacturer=vehicle.brand.name,
32  model=vehicle.name,
33  name=vehicle.name,
34  serial_number=vehicle.vin,
35  )
36 
37  async def async_added_to_hass(self) -> None:
38  """When entity is added to hass."""
39  await super().async_added_to_hass()
40  self._handle_coordinator_update()
None __init__(self, BMWDataUpdateCoordinator coordinator, MyBMWVehicle vehicle)
Definition: entity.py:23