mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Cosmetic adjustments
This commit is contained in:
parent
2f65751087
commit
860812fa19
@ -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
|
||||||
|
|
||||||
@ -100,7 +110,7 @@ def track_time_change(eventbus, action,
|
|||||||
""" Listens for matching time_changed events. """
|
""" Listens for matching time_changed events. """
|
||||||
now = str_to_datetime(event.data['now'])
|
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 \
|
(not point_in_time and \
|
||||||
matcher(now.year, year) and \
|
matcher(now.year, year) and \
|
||||||
matcher(now.month, month) and \
|
matcher(now.month, month) and \
|
||||||
|
@ -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
|
||||||
|
@ -157,8 +157,8 @@ 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')
|
||||||
]
|
]
|
||||||
|
|
||||||
use_json = False
|
use_json = False
|
||||||
|
@ -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
|
||||||
|
@ -35,7 +35,7 @@ def ensure_homeassistant_started():
|
|||||||
core['statemachine'] = ha.StateMachine(core['eventbus'])
|
core['statemachine'] = ha.StateMachine(core['eventbus'])
|
||||||
|
|
||||||
core['eventbus'].listen('test_event', len)
|
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'],
|
hah.HTTPInterface(core['eventbus'], core['statemachine'],
|
||||||
API_PASSWORD)
|
API_PASSWORD)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user