1 """Support for LIRC devices."""
14 _LOGGER = logging.getLogger(__name__)
16 BUTTON_NAME =
"button_name"
20 EVENT_IR_COMMAND_RECEIVED =
"ir_command_received"
24 CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
27 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
28 """Set up the LIRC capability."""
32 lirc.init(
"home-assistant", blocking=
False)
35 def _start_lirc(_event):
36 lirc_interface.start()
38 def _stop_lirc(_event):
39 lirc_interface.stopped.set()
41 hass.bus.listen_once(EVENT_HOMEASSISTANT_START, _start_lirc)
42 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _stop_lirc)
48 """Interfaces with the lirc daemon to read IR commands.
50 When using lirc in blocking mode, sometimes repeated commands get produced
51 in the next read of a command so we use a thread here to just wait
52 around until a non-empty response is obtained from lirc.
56 """Construct a LIRC interface object."""
57 threading.Thread.__init__(self)
63 """Run the loop of the LIRC interface thread."""
64 _LOGGER.debug(
"LIRC interface thread started")
65 while not self.
stoppedstopped.is_set():
67 code = lirc.nextcode()
68 except lirc.NextCodeError:
69 _LOGGER.warning(
"Error reading next code from LIRC")
74 _LOGGER.debug(
"Got new LIRC code %s", code)
75 self.
hasshass.bus.fire(EVENT_IR_COMMAND_RECEIVED, {BUTTON_NAME: code})
79 _LOGGER.debug(
"LIRC interface thread stopped")
bool setup(HomeAssistant hass, ConfigType config)