Home Assistant Unofficial Reference 2024.12.1
select.py
Go to the documentation of this file.
1 """Select platform for the jvc_projector integration."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Awaitable, Callable
6 from dataclasses import dataclass
7 from typing import Final
8 
9 from jvcprojector import JvcProjector, const
10 
11 from homeassistant.components.select import SelectEntity, SelectEntityDescription
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from . import JVCConfigEntry, JvcProjectorDataUpdateCoordinator
16 from .entity import JvcProjectorEntity
17 
18 
19 @dataclass(frozen=True, kw_only=True)
21  """Describes JVC Projector select entities."""
22 
23  command: Callable[[JvcProjector, str], Awaitable[None]]
24 
25 
26 OPTIONS: Final[dict[str, dict[str, str]]] = {
27  "input": {const.HDMI1: const.REMOTE_HDMI_1, const.HDMI2: const.REMOTE_HDMI_2}
28 }
29 
30 SELECTS: Final[list[JvcProjectorSelectDescription]] = [
32  key="input",
33  translation_key="input",
34  options=list(OPTIONS["input"]),
35  command=lambda device, option: device.remote(OPTIONS["input"][option]),
36  )
37 ]
38 
39 
41  hass: HomeAssistant,
42  entry: JVCConfigEntry,
43  async_add_entities: AddEntitiesCallback,
44 ) -> None:
45  """Set up the JVC Projector platform from a config entry."""
46  coordinator = entry.runtime_data
47 
49  JvcProjectorSelectEntity(coordinator, description) for description in SELECTS
50  )
51 
52 
54  """Representation of a JVC Projector select entity."""
55 
56  entity_description: JvcProjectorSelectDescription
57 
58  def __init__(
59  self,
60  coordinator: JvcProjectorDataUpdateCoordinator,
61  description: JvcProjectorSelectDescription,
62  ) -> None:
63  """Initialize the entity."""
64  super().__init__(coordinator)
65  self.entity_descriptionentity_description = description
66  self._attr_unique_id_attr_unique_id_attr_unique_id = f"{coordinator.unique_id}_{description.key}"
67 
68  @property
69  def current_option(self) -> str | None:
70  """Return the selected entity option to represent the entity state."""
71  return self.coordinator.data[self.entity_descriptionentity_description.key]
72 
73  async def async_select_option(self, option: str) -> None:
74  """Change the selected option."""
75  await self.entity_descriptionentity_description.command(self.coordinator.device, option)
None __init__(self, JvcProjectorDataUpdateCoordinator coordinator, JvcProjectorSelectDescription description)
Definition: select.py:62
None async_setup_entry(HomeAssistant hass, JVCConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: select.py:44