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 break
def datetime_to_str(dattim): 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) return dattim.strftime(DATE_STR_FORMAT)
def str_to_datetime(dt_str): 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) return datetime.strptime(dt_str, DATE_STR_FORMAT)
def ensure_list(parameter): 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] return parameter if isinstance(parameter, list) else [parameter]
def matcher(subject, pattern): def matcher(subject, pattern):
""" Returns True if subject matches the pattern. """ Returns True if subject matches the pattern.
Pattern is either a list of allowed subjects or a '*'. Pattern is either a list of allowed subjects or a '*'.
@rtype : bool
""" """
return '*' in pattern or subject in pattern return '*' in pattern or subject in pattern

View File

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

View File

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

View File

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