Skip to content

Commit

Permalink
LIRC: Responded to some code review requests but not the big one
Browse files Browse the repository at this point in the history
  • Loading branch information
partofthething committed May 23, 2016
1 parent 80e60ef commit 4e5b5f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
19 changes: 9 additions & 10 deletions homeassistant/components/sensor/lirc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
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

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'

Expand All @@ -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])

Expand All @@ -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 = ''
Expand All @@ -66,7 +64,7 @@ def update_state(self, new_state):
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()
Expand All @@ -89,8 +87,9 @@ def __init__(self, parent):

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:
Expand Down
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions script/gen_requirements_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'fritzconnection',
'pybluez',
'bluepy',
'python-lirc',
]


Expand Down

0 comments on commit 4e5b5f2

Please sign in to comment.