2016-09-18 06:31:27 +00:00
|
|
|
"""
|
2017-01-05 21:03:05 +00:00
|
|
|
Receive signals from a keyboard and use it as a remote control.
|
2016-09-18 06:31:27 +00:00
|
|
|
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/keyboard_remote/
|
2016-09-18 06:31:27 +00:00
|
|
|
"""
|
|
|
|
# pylint: disable=import-error
|
|
|
|
import threading
|
|
|
|
import logging
|
|
|
|
import os
|
2017-01-05 21:03:05 +00:00
|
|
|
import time
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from homeassistant.const import (
|
2017-04-30 05:04:49 +00:00
|
|
|
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
REQUIREMENTS = ['evdev==0.6.1']
|
2017-04-30 05:04:49 +00:00
|
|
|
|
2016-09-18 06:31:27 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2017-04-30 05:04:49 +00:00
|
|
|
|
|
|
|
DEVICE_DESCRIPTOR = 'device_descriptor'
|
2017-12-14 04:07:23 +00:00
|
|
|
DEVICE_ID_GROUP = 'Device description'
|
2017-04-30 05:04:49 +00:00
|
|
|
DEVICE_NAME = 'device_name'
|
|
|
|
DOMAIN = 'keyboard_remote'
|
|
|
|
|
2016-09-18 06:31:27 +00:00
|
|
|
ICON = 'mdi:remote'
|
2017-04-30 05:04:49 +00:00
|
|
|
|
|
|
|
KEY_CODE = 'key_code'
|
|
|
|
KEY_VALUE = {'key_up': 0, 'key_down': 1, 'key_hold': 2}
|
2016-09-18 06:31:27 +00:00
|
|
|
KEYBOARD_REMOTE_COMMAND_RECEIVED = 'keyboard_remote_command_received'
|
2017-01-15 22:05:41 +00:00
|
|
|
KEYBOARD_REMOTE_CONNECTED = 'keyboard_remote_connected'
|
|
|
|
KEYBOARD_REMOTE_DISCONNECTED = 'keyboard_remote_disconnected'
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
|
2017-04-30 05:04:49 +00:00
|
|
|
TYPE = 'type'
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
2017-12-14 04:07:23 +00:00
|
|
|
DOMAIN:
|
|
|
|
vol.All(cv.ensure_list, [vol.Schema({
|
|
|
|
vol.Exclusive(DEVICE_DESCRIPTOR, DEVICE_ID_GROUP): cv.string,
|
|
|
|
vol.Exclusive(DEVICE_NAME, DEVICE_ID_GROUP): cv.string,
|
|
|
|
vol.Optional(TYPE, default='key_up'):
|
|
|
|
vol.All(cv.string, vol.Any('key_up', 'key_down', 'key_hold'))
|
|
|
|
})])
|
2016-09-18 06:31:27 +00:00
|
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the keyboard_remote."""
|
2016-09-18 06:31:27 +00:00
|
|
|
config = config.get(DOMAIN)
|
|
|
|
|
2018-05-31 22:32:09 +00:00
|
|
|
keyboard_remote = KeyboardRemote(hass, config)
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
def _start_keyboard_remote(_event):
|
|
|
|
keyboard_remote.run()
|
|
|
|
|
|
|
|
def _stop_keyboard_remote(_event):
|
2017-12-14 04:07:23 +00:00
|
|
|
keyboard_remote.stop()
|
2016-09-18 06:31:27 +00:00
|
|
|
|
2018-05-31 22:32:09 +00:00
|
|
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, _start_keyboard_remote)
|
|
|
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _stop_keyboard_remote)
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2017-12-14 04:07:23 +00:00
|
|
|
class KeyboardRemoteThread(threading.Thread):
|
2016-09-18 06:31:27 +00:00
|
|
|
"""This interfaces with the inputdevice using evdev."""
|
|
|
|
|
2017-12-14 04:07:23 +00:00
|
|
|
def __init__(self, hass, device_name, device_descriptor, key_value):
|
|
|
|
"""Construct a thread listening for events on one device."""
|
|
|
|
self.hass = hass
|
|
|
|
self.device_name = device_name
|
|
|
|
self.device_descriptor = device_descriptor
|
|
|
|
self.key_value = key_value
|
2016-09-18 06:31:27 +00:00
|
|
|
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
if self.device_descriptor:
|
|
|
|
self.device_id = self.device_descriptor
|
|
|
|
else:
|
|
|
|
self.device_id = self.device_name
|
2017-12-14 04:07:23 +00:00
|
|
|
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
self.dev = self._get_keyboard_device()
|
|
|
|
if self.dev is not None:
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.debug("Keyboard connected, %s", self.device_id)
|
2017-01-05 21:03:05 +00:00
|
|
|
else:
|
|
|
|
_LOGGER.debug(
|
2018-05-31 22:32:09 +00:00
|
|
|
"Keyboard not connected, %s. "
|
|
|
|
"Check /dev/input/event* permissions", self.device_id)
|
2017-01-05 21:03:05 +00:00
|
|
|
|
2017-07-24 06:47:38 +00:00
|
|
|
id_folder = '/dev/input/by-id/'
|
|
|
|
|
|
|
|
if os.path.isdir(id_folder):
|
2017-12-14 04:07:23 +00:00
|
|
|
from evdev import InputDevice, list_devices
|
2017-07-24 06:47:38 +00:00
|
|
|
device_names = [InputDevice(file_name).name
|
|
|
|
for file_name in list_devices()]
|
|
|
|
_LOGGER.debug(
|
2018-05-31 22:32:09 +00:00
|
|
|
"Possible device names are: %s. "
|
|
|
|
"Possible device descriptors are %s: %s",
|
|
|
|
device_names, id_folder, os.listdir(id_folder))
|
2017-07-24 06:47:38 +00:00
|
|
|
|
2016-09-18 06:31:27 +00:00
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.stopped = threading.Event()
|
|
|
|
self.hass = hass
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
|
|
|
|
def _get_keyboard_device(self):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Get the keyboard device."""
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
from evdev import InputDevice, list_devices
|
|
|
|
if self.device_name:
|
|
|
|
devices = [InputDevice(file_name) for file_name in list_devices()]
|
|
|
|
for device in devices:
|
|
|
|
if self.device_name == device.name:
|
|
|
|
return device
|
|
|
|
elif self.device_descriptor:
|
|
|
|
try:
|
|
|
|
device = InputDevice(self.device_descriptor)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
return device
|
|
|
|
return None
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
def run(self):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Run the loop of the KeyboardRemote."""
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
from evdev import categorize, ecodes
|
2016-09-18 06:31:27 +00:00
|
|
|
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
if self.dev is not None:
|
2017-01-05 21:03:05 +00:00
|
|
|
self.dev.grab()
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.debug("Interface started for %s", self.dev)
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
while not self.stopped.isSet():
|
2017-01-05 21:03:05 +00:00
|
|
|
# Sleeps to ease load on processor
|
2017-12-14 04:07:23 +00:00
|
|
|
time.sleep(.05)
|
2017-01-05 21:03:05 +00:00
|
|
|
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
if self.dev is None:
|
|
|
|
self.dev = self._get_keyboard_device()
|
|
|
|
if self.dev is not None:
|
2017-01-05 21:03:05 +00:00
|
|
|
self.dev.grab()
|
2018-05-31 22:32:09 +00:00
|
|
|
self.hass.bus.fire(KEYBOARD_REMOTE_CONNECTED)
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.debug("Keyboard re-connected, %s", self.device_id)
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
else:
|
|
|
|
continue
|
2017-01-05 21:03:05 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
event = self.dev.read_one()
|
|
|
|
except IOError: # Keyboard Disconnected
|
Update keyboard_remote.py (#5535)
* Update keyboard_remote.py
I added a couple of events: keyboard_remote_connected and keyboard_remote_disconnected, useful to trigger some action (for example: play a sound)
I changed the way the component refers to the keyboard: not by "descriptor", but by name.
The fact is that the udev system doesn't always give a name link in /dev/input/by-id folder and the actual /dev/input/eventX file changes automatically.
For example, if I had my keyboard on /dev/input/event13 and then it disconnected, if something else connects to the system it will get the first input file available, that is /dev/input/event13. If the keyboard then reconnects, it will get /dev/input/event14, thus breaking the configuration.
Now it searches every time for the right input file.
The problem might be that, in case of ha upgrade, the pre-existing configuration won't work. I thing there are some guidelines here, but I am not sure.
I think it's inevitable: the initial idea to use a /dev/input/by-id/ symbolic link was good, but unfortunately it doesn't seem to work with bluetooth devices.
I haven't updated the documentation yet: I'm waiting for some ok about the change in configuration key names.
* Update keyboard_remote.py
That should do the trick.
You are right: device names can be duplicated, thus they're not reliable in case of multiple devices. Unfortunately, the only other information available is the physical address, even more complicated.
But in case you have just one keyboard remote of same model, the name works just fine. I'll put it in the documentation which, once the code is approved, I will promptly update.
* Update keyboard_remote.py
* Update keyboard_remote.py
* Update keyboard_remote.py
* Unwrap logger error
2017-01-25 18:58:34 +00:00
|
|
|
self.dev = None
|
2018-05-31 22:32:09 +00:00
|
|
|
self.hass.bus.fire(KEYBOARD_REMOTE_DISCONNECTED)
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.debug("Keyboard disconnected, %s", self.device_id)
|
2017-01-05 21:03:05 +00:00
|
|
|
continue
|
2016-09-18 06:31:27 +00:00
|
|
|
|
|
|
|
if not event:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if event.type is ecodes.EV_KEY and event.value is self.key_value:
|
|
|
|
_LOGGER.debug(categorize(event))
|
|
|
|
self.hass.bus.fire(
|
|
|
|
KEYBOARD_REMOTE_COMMAND_RECEIVED,
|
2018-05-31 22:32:09 +00:00
|
|
|
{
|
|
|
|
KEY_CODE: event.code,
|
|
|
|
DEVICE_DESCRIPTOR: self.device_descriptor,
|
|
|
|
DEVICE_NAME: self.device_name
|
|
|
|
}
|
2016-09-18 06:31:27 +00:00
|
|
|
)
|
2017-12-14 04:07:23 +00:00
|
|
|
|
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class KeyboardRemote:
|
2017-12-14 04:07:23 +00:00
|
|
|
"""Sets up one thread per device."""
|
|
|
|
|
|
|
|
def __init__(self, hass, config):
|
|
|
|
"""Construct a KeyboardRemote interface object."""
|
|
|
|
self.threads = []
|
|
|
|
for dev_block in config:
|
|
|
|
device_descriptor = dev_block.get(DEVICE_DESCRIPTOR)
|
|
|
|
device_name = dev_block.get(DEVICE_NAME)
|
|
|
|
key_value = KEY_VALUE.get(dev_block.get(TYPE, 'key_up'))
|
|
|
|
|
|
|
|
if device_descriptor is not None\
|
|
|
|
or device_name is not None:
|
2018-05-31 22:32:09 +00:00
|
|
|
thread = KeyboardRemoteThread(
|
|
|
|
hass, device_name, device_descriptor, key_value)
|
2017-12-14 04:07:23 +00:00
|
|
|
self.threads.append(thread)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""Run all event listener threads."""
|
|
|
|
for thread in self.threads:
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
"""Stop all event listener threads."""
|
|
|
|
for thread in self.threads:
|
|
|
|
thread.stopped.set()
|