Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Sensor platform for JVC Projector integration."""
2 
3 from __future__ import annotations
4 
5 from jvcprojector import const
6 
8  SensorDeviceClass,
9  SensorEntity,
10  SensorEntityDescription,
11 )
12 from homeassistant.const import EntityCategory
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from . import JVCConfigEntry, JvcProjectorDataUpdateCoordinator
17 from .entity import JvcProjectorEntity
18 
19 JVC_SENSORS = (
21  key="power",
22  translation_key="jvc_power_status",
23  device_class=SensorDeviceClass.ENUM,
24  entity_category=EntityCategory.DIAGNOSTIC,
25  options=[
26  const.STANDBY,
27  const.ON,
28  const.WARMING,
29  const.COOLING,
30  const.ERROR,
31  ],
32  ),
33 )
34 
35 
37  hass: HomeAssistant, entry: JVCConfigEntry, async_add_entities: AddEntitiesCallback
38 ) -> None:
39  """Set up the JVC Projector platform from a config entry."""
40  coordinator = entry.runtime_data
41 
43  JvcSensor(coordinator, description) for description in JVC_SENSORS
44  )
45 
46 
48  """The entity class for JVC Projector integration."""
49 
50  def __init__(
51  self,
52  coordinator: JvcProjectorDataUpdateCoordinator,
53  description: SensorEntityDescription,
54  ) -> None:
55  """Initialize the JVC Projector sensor."""
56  super().__init__(coordinator)
57  self.entity_descriptionentity_description = description
58  self._attr_unique_id_attr_unique_id_attr_unique_id = f"{coordinator.unique_id}_{description.key}"
59 
60  @property
61  def native_value(self) -> str | None:
62  """Return the native value."""
63  return self.coordinator.data[self.entity_descriptionentity_description.key]
None __init__(self, JvcProjectorDataUpdateCoordinator coordinator, SensorEntityDescription description)
Definition: sensor.py:54
None async_setup_entry(HomeAssistant hass, JVCConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:38