Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Remote platform for the jvc_projector integration."""
2 
3 from __future__ import annotations
4 
5 import asyncio
6 from collections.abc import Iterable
7 import logging
8 from typing import Any
9 
10 from jvcprojector import const
11 
12 from homeassistant.components.remote import RemoteEntity
13 from homeassistant.core import HomeAssistant
14 from homeassistant.exceptions import HomeAssistantError
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from . import JVCConfigEntry
18 from .entity import JvcProjectorEntity
19 
20 COMMANDS = {
21  "menu": const.REMOTE_MENU,
22  "up": const.REMOTE_UP,
23  "down": const.REMOTE_DOWN,
24  "left": const.REMOTE_LEFT,
25  "right": const.REMOTE_RIGHT,
26  "ok": const.REMOTE_OK,
27  "back": const.REMOTE_BACK,
28  "mpc": const.REMOTE_MPC,
29  "hide": const.REMOTE_HIDE,
30  "info": const.REMOTE_INFO,
31  "input": const.REMOTE_INPUT,
32  "cmd": const.REMOTE_CMD,
33  "advanced_menu": const.REMOTE_ADVANCED_MENU,
34  "picture_mode": const.REMOTE_PICTURE_MODE,
35  "color_profile": const.REMOTE_COLOR_PROFILE,
36  "lens_control": const.REMOTE_LENS_CONTROL,
37  "setting_memory": const.REMOTE_SETTING_MEMORY,
38  "gamma_settings": const.REMOTE_GAMMA_SETTINGS,
39  "hdmi_1": const.REMOTE_HDMI_1,
40  "hdmi_2": const.REMOTE_HDMI_2,
41  "mode_1": const.REMOTE_MODE_1,
42  "mode_2": const.REMOTE_MODE_2,
43  "mode_3": const.REMOTE_MODE_3,
44  "lens_ap": const.REMOTE_LENS_AP,
45  "gamma": const.REMOTE_GAMMA,
46  "color_temp": const.REMOTE_COLOR_TEMP,
47  "natural": const.REMOTE_NATURAL,
48  "cinema": const.REMOTE_CINEMA,
49  "anamo": const.REMOTE_ANAMO,
50  "3d_format": const.REMOTE_3D_FORMAT,
51 }
52 
53 _LOGGER = logging.getLogger(__name__)
54 
55 
57  hass: HomeAssistant, entry: JVCConfigEntry, async_add_entities: AddEntitiesCallback
58 ) -> None:
59  """Set up the JVC Projector platform from a config entry."""
60  coordinator = entry.runtime_data
61  async_add_entities([JvcProjectorRemote(coordinator)], True)
62 
63 
65  """Representation of a JVC Projector device."""
66 
67  _attr_name = None
68 
69  @property
70  def is_on(self) -> bool:
71  """Return True if entity is on."""
72  return self.coordinator.data["power"] in [const.ON, const.WARMING]
73 
74  async def async_turn_on(self, **kwargs: Any) -> None:
75  """Turn the device on."""
76  await self.devicedevicedevice.power_on()
77  await asyncio.sleep(1)
78  await self.coordinator.async_refresh()
79 
80  async def async_turn_off(self, **kwargs: Any) -> None:
81  """Turn the device off."""
82  await self.devicedevicedevice.power_off()
83  await asyncio.sleep(1)
84  await self.coordinator.async_refresh()
85 
86  async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
87  """Send a remote command to the device."""
88  for cmd in command:
89  if cmd not in COMMANDS:
90  raise HomeAssistantError(f"{cmd} is not a known command")
91  _LOGGER.debug("Sending command '%s'", cmd)
92  await self.devicedevicedevice.remote(COMMANDS[cmd])
None async_send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:86
None async_setup_entry(HomeAssistant hass, JVCConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:58