Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entity for the wallbox integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.helpers.device_registry import DeviceInfo
6 from homeassistant.helpers.update_coordinator import CoordinatorEntity
7 
8 from .const import (
9  CHARGER_CURRENT_VERSION_KEY,
10  CHARGER_DATA_KEY,
11  CHARGER_NAME_KEY,
12  CHARGER_PART_NUMBER_KEY,
13  CHARGER_SERIAL_NUMBER_KEY,
14  CHARGER_SOFTWARE_KEY,
15  DOMAIN,
16 )
17 from .coordinator import WallboxCoordinator
18 
19 
20 class WallboxEntity(CoordinatorEntity[WallboxCoordinator]):
21  """Defines a base Wallbox entity."""
22 
23  _attr_has_entity_name = True
24 
25  @property
26  def device_info(self) -> DeviceInfo:
27  """Return device information about this Wallbox device."""
28  return DeviceInfo(
29  identifiers={
30  (
31  DOMAIN,
32  self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SERIAL_NUMBER_KEY],
33  )
34  },
35  name=f"Wallbox {self.coordinator.data[CHARGER_NAME_KEY]}",
36  manufacturer="Wallbox",
37  model=self.coordinator.data[CHARGER_NAME_KEY].split(" SN")[0],
38  model_id=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_PART_NUMBER_KEY],
39  sw_version=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SOFTWARE_KEY][
40  CHARGER_CURRENT_VERSION_KEY
41  ],
42  )