From 4e5b5f22048ac769c5bfe01f62b104ebd963643b Mon Sep 17 00:00:00 2001 From: ntouran Date: Sun, 22 May 2016 22:19:10 -0700 Subject: [PATCH] LIRC: Responded to some code review requests but not the big one --- homeassistant/components/sensor/lirc.py | 19 +++++++++---------- requirements_all.txt | 3 +++ script/gen_requirements_all.py | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/sensor/lirc.py b/homeassistant/components/sensor/lirc.py index e6872e029eb..9d96d6bcd7d 100644 --- a/homeassistant/components/sensor/lirc.py +++ b/homeassistant/components/sensor/lirc.py @@ -6,9 +6,9 @@ in the .lintrc file which can be interpreted in home-assistant to trigger various actions. Sending signals to other IR receivers can be accomplished with the -shell_command component and the irsend command. +shell_command component and the irsend command for now. """ - +# pylint: disable=import-error import threading import time import logging @@ -16,8 +16,7 @@ import logging from homeassistant.helpers.entity import Entity from homeassistant.const import EVENT_HOMEASSISTANT_STOP -LIRC = None - +REQUIREMENTS = ['python-lirc>=1.2.1'] _LOGGER = logging.getLogger(__name__) ICON = 'mdi:remote' @@ -27,13 +26,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # Perform safe import of third-party python-lirc module try: import lirc - global LIRC - LIRC = lirc except ImportError: _LOGGER.error("You are missing a required dependency: python-lirc.") return False - LIRC.init('home-assistant', blocking=False) + # blocking=True gives unexpected behavior (multiple responses for 1 press) + lirc.init('home-assistant', blocking=False) sensor = LircSensor() add_devices([sensor]) @@ -44,7 +42,7 @@ class LircSensor(Entity): """Sensor entity for LIRC.""" def __init__(self, *args, **kwargs): - """Contruct a LircSensor entity.""" + """Construct a LircSensor entity.""" _LOGGER.info('Initializing LIRC sensor') Entity.__init__(self, *args, **kwargs) self.last_key_pressed = '' @@ -66,7 +64,7 @@ class LircSensor(Entity): self.last_key_pressed = new_state self.update_ha_state() - def stop(self, event): + def stop(self, _event): """Kill the helper thread on stop.""" _LOGGER.info('Ending LIRC interface thread') self._lirc_interface.stopped.set() @@ -89,8 +87,9 @@ class LircInterface(threading.Thread): def run(self): """Main loop of LIRC interface thread.""" + import lirc while not self.stopped.isSet(): - code = LIRC.nextcode() # list; empty if no buttons pressed + code = lirc.nextcode() # list; empty if no buttons pressed # interpret result from python-lirc if code: diff --git a/requirements_all.txt b/requirements_all.txt index 92c9b735b2c..b7c383f7ddc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -262,6 +262,9 @@ pysnmp==4.2.5 # homeassistant.components.sensor.forecast python-forecastio==1.3.4 +# homeassistant.components.sensor.lirc +# python-lirc>=1.2.1 + # homeassistant.components.media_player.mpd python-mpd2==0.5.5 diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index 76ed3acba39..872d13bab75 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -13,6 +13,7 @@ COMMENT_REQUIREMENTS = [ 'fritzconnection', 'pybluez', 'bluepy', + 'python-lirc', ]