Added identifier and name to connect/disconnect events (#18078)

* Added identifier and name to connect/disconnect events

* Fix indentation from failed tests
This commit is contained in:
Jared Quinn 2018-11-01 19:48:44 +11:00 committed by Fabian Affolter
parent bfa86b8138
commit 1c5800d98b

View file

@ -4,6 +4,7 @@ Receive signals from a keyboard and use it as a remote control.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/keyboard_remote/ https://home-assistant.io/components/keyboard_remote/
""" """
# pylint: disable=import-error
import threading import threading
import logging import logging
import os import os
@ -89,7 +90,6 @@ class KeyboardRemoteThread(threading.Thread):
id_folder = '/dev/input/by-id/' id_folder = '/dev/input/by-id/'
if os.path.isdir(id_folder): if os.path.isdir(id_folder):
# pylint: disable=import-error
from evdev import InputDevice, list_devices from evdev import InputDevice, list_devices
device_names = [InputDevice(file_name).name device_names = [InputDevice(file_name).name
for file_name in list_devices()] for file_name in list_devices()]
@ -104,7 +104,6 @@ class KeyboardRemoteThread(threading.Thread):
def _get_keyboard_device(self): def _get_keyboard_device(self):
"""Get the keyboard device.""" """Get the keyboard device."""
# pylint: disable=import-error
from evdev import InputDevice, list_devices from evdev import InputDevice, list_devices
if self.device_name: if self.device_name:
devices = [InputDevice(file_name) for file_name in list_devices()] devices = [InputDevice(file_name) for file_name in list_devices()]
@ -122,7 +121,6 @@ class KeyboardRemoteThread(threading.Thread):
def run(self): def run(self):
"""Run the loop of the KeyboardRemote.""" """Run the loop of the KeyboardRemote."""
# pylint: disable=import-error
from evdev import categorize, ecodes from evdev import categorize, ecodes
if self.dev is not None: if self.dev is not None:
@ -137,7 +135,13 @@ class KeyboardRemoteThread(threading.Thread):
self.dev = self._get_keyboard_device() self.dev = self._get_keyboard_device()
if self.dev is not None: if self.dev is not None:
self.dev.grab() self.dev.grab()
self.hass.bus.fire(KEYBOARD_REMOTE_CONNECTED) self.hass.bus.fire(
KEYBOARD_REMOTE_CONNECTED,
{
DEVICE_DESCRIPTOR: self.device_descriptor,
DEVICE_NAME: self.device_name
}
)
_LOGGER.debug("Keyboard re-connected, %s", self.device_id) _LOGGER.debug("Keyboard re-connected, %s", self.device_id)
else: else:
continue continue
@ -146,7 +150,13 @@ class KeyboardRemoteThread(threading.Thread):
event = self.dev.read_one() event = self.dev.read_one()
except IOError: # Keyboard Disconnected except IOError: # Keyboard Disconnected
self.dev = None self.dev = None
self.hass.bus.fire(KEYBOARD_REMOTE_DISCONNECTED) self.hass.bus.fire(
KEYBOARD_REMOTE_DISCONNECTED,
{
DEVICE_DESCRIPTOR: self.device_descriptor,
DEVICE_NAME: self.device_name
}
)
_LOGGER.debug("Keyboard disconnected, %s", self.device_id) _LOGGER.debug("Keyboard disconnected, %s", self.device_id)
continue continue