Update code

This commit is contained in:
Fabian Affolter 2017-04-30 23:11:34 +02:00
parent 3bef0ad30f
commit 07112d8772
No known key found for this signature in database
GPG key ID: DDF3D6F44AAB1336
4 changed files with 18 additions and 18 deletions

View file

@ -39,35 +39,35 @@ from homeassistant.components import device_tracker, light, notify
from homeassistant.helpers.event import track_state_change
from homeassistant.const import STATE_ON, STATE_OFF, STATE_HOME, STATE_NOT_HOME
DOMAIN = "simple_alarm"
_LOGGER = logging.getLogger(__name__)
DOMAIN = 'simple_alarm"'
DEPENDENCIES = ['group', 'device_tracker', 'light']
# Attribute to tell which light has to flash when a known person comes home
# If omitted will flash all.
CONF_KNOWN_LIGHT = "known_light"
CONF_KNOWN_LIGHT = 'known_light'
# Attribute to tell which light has to flash when an unknown person comes home
# If omitted will flash all.
CONF_UNKNOWN_LIGHT = "unknown_light"
CONF_UNKNOWN_LIGHT = 'unknown_light'
# Services to test the alarms
SERVICE_TEST_KNOWN_ALARM = "test_known"
SERVICE_TEST_UNKNOWN_ALARM = "test_unknown"
SERVICE_TEST_KNOWN_ALARM = 'test_known'
SERVICE_TEST_UNKNOWN_ALARM = 'test_unknown'
def setup(hass, config):
""" Sets up the simple alarms. """
logger = logging.getLogger(__name__)
"""Set up the simple alarms."""
light_ids = []
for conf_key in (CONF_KNOWN_LIGHT, CONF_UNKNOWN_LIGHT):
light_id = config[DOMAIN].get(conf_key, light.ENTITY_ID_ALL_LIGHTS)
if hass.states.get(light_id) is None:
logger.error(
'Light id %s could not be found in state machine', light_id)
_LOGGER.error(
"Light id %s could not be found in state machine", light_id)
return False
@ -77,7 +77,7 @@ def setup(hass, config):
known_light_id, unknown_light_id = light_ids
if hass.states.get(device_tracker.ENTITY_ID_ALL_DEVICES) is None:
logger.error('No devices are being tracked, cannot setup alarm')
_LOGGER.error("No devices are being tracked, cannot setup alarm")
return False
@ -102,7 +102,7 @@ def setup(hass, config):
DOMAIN, SERVICE_TEST_UNKNOWN_ALARM, lambda call: unknown_alarm())
def unknown_alarm_if_lights_on(entity_id, old_state, new_state):
""" Called when a light has been turned on. """
"""Called when a light has been turned on."""
if not device_tracker.is_on(hass):
unknown_alarm()
@ -111,7 +111,7 @@ def setup(hass, config):
unknown_alarm_if_lights_on, STATE_OFF, STATE_ON)
def ring_known_alarm(entity_id, old_state, new_state):
""" Called when a known person comes home. """
"""Called when a known person comes home."""
if light.is_on(hass, known_light_id):
known_alarm()