Cosmetic adjustments

This commit is contained in:
Paulus Schoutsen 2013-11-10 09:31:34 -08:00
parent 2f65751087
commit 860812fa19
5 changed files with 21 additions and 11 deletions

View File

@ -42,21 +42,31 @@ def start_home_assistant(eventbus):
break
def datetime_to_str(dattim):
""" Converts datetime to a string format. """
""" Converts datetime to a string format.
@rtype : str
"""
return dattim.strftime(DATE_STR_FORMAT)
def str_to_datetime(dt_str):
""" Converts a string to a datetime object. """
""" Converts a string to a datetime object.
@rtype: datetime
"""
return datetime.strptime(dt_str, DATE_STR_FORMAT)
def ensure_list(parameter):
""" Wraps parameter in a list if it is not one and returns it. """
""" Wraps parameter in a list if it is not one and returns it.
@rtype : list
"""
return parameter if isinstance(parameter, list) else [parameter]
def matcher(subject, pattern):
""" Returns True if subject matches the pattern.
Pattern is either a list of allowed subjects or a '*'.
@rtype : bool
"""
return '*' in pattern or subject in pattern
@ -100,7 +110,7 @@ def track_time_change(eventbus, action,
""" Listens for matching time_changed events. """
now = str_to_datetime(event.data['now'])
if (point_in_time and now > point_in_time) or \
if (point_in_time and now > point_in_time) or \
(not point_in_time and \
matcher(now.year, year) and \
matcher(now.month, month) and \

View File

@ -97,11 +97,11 @@ class LightTrigger(object):
start_point = self._time_for_light_before_sun_set()
def turn_on(light_id):
def turn_on(light):
""" Lambda can keep track of function parameters but not local
parameters. If we put the lambda directly in the below statement
only the last light would be turned on.. """
return lambda now: self._turn_light_on_before_sunset(light_id)
return lambda now: self._turn_light_on_before_sunset(light)
for index, light_id in enumerate(self.light_control.light_ids):
ha.track_time_change(self.eventbus, turn_on(light_id),
@ -146,7 +146,7 @@ class LightTrigger(object):
# if someone would be home?
# Check this by seeing if current time is later then the point
# in time when we would start putting the lights on.
elif now > start_point and now < self._next_sun_setting():
elif start_point < now < self._next_sun_setting():
# Check for every light if it would be on if someone was home
# when the fading in started and turn it on if so

View File

@ -157,8 +157,8 @@ class RequestHandler(BaseHTTPRequestHandler):
'_handle_fire_event'),
# Statis files
('GET', re.compile(r'/static/(?P<file>[a-zA-Z\._\-0-9\/]+)'),
'_handle_get_static')
('GET', re.compile(r'/static/(?P<file>[a-zA-Z\._\-0-9/]+)'),
'_handle_get_static')
]
use_json = False

View File

@ -49,7 +49,7 @@ def track_sun(eventbus, statemachine, latitude, longitude):
try:
import ephem
except ImportError:
logger.exception(("TrackSun:Error while importing dependency ephem."))
logger.exception("TrackSun:Error while importing dependency ephem.")
return False
sun = ephem.Sun() # pylint: disable=no-member

View File

@ -35,7 +35,7 @@ def ensure_homeassistant_started():
core['statemachine'] = ha.StateMachine(core['eventbus'])
core['eventbus'].listen('test_event', len)
core['statemachine'].set_state('test','a_state')
core['statemachine'].set_state('test', 'a_state')
hah.HTTPInterface(core['eventbus'], core['statemachine'],
API_PASSWORD)