Minor code cleanup

This commit is contained in:
Paulus Schoutsen 2015-08-04 18:13:55 +02:00
parent e47ac96587
commit 14023a15e6
3 changed files with 12 additions and 18 deletions

View file

@ -598,23 +598,15 @@ class ServiceRegistry(object):
if call.data[ATTR_SERVICE_CALL_ID] == call_id: if call.data[ATTR_SERVICE_CALL_ID] == call_id:
executed_event.set() executed_event.set()
self._bus.remove_listener(
EVENT_SERVICE_EXECUTED, service_executed)
self._bus.listen(EVENT_SERVICE_EXECUTED, service_executed) self._bus.listen(EVENT_SERVICE_EXECUTED, service_executed)
self._bus.fire(EVENT_CALL_SERVICE, event_data) self._bus.fire(EVENT_CALL_SERVICE, event_data)
if blocking: if blocking:
# wait will return False if event not set after our limit has success = executed_event.wait(SERVICE_CALL_LIMIT)
# passed. If not set, clean up the listener
if not executed_event.wait(SERVICE_CALL_LIMIT):
self._bus.remove_listener( self._bus.remove_listener(
EVENT_SERVICE_EXECUTED, service_executed) EVENT_SERVICE_EXECUTED, service_executed)
return success
return False
return True
def _event_to_service_call(self, event): def _event_to_service_call(self, event):
""" Calls a service from an event. """ """ Calls a service from an event. """
@ -675,8 +667,8 @@ class Config(object):
def temperature(self, value, unit): def temperature(self, value, unit):
""" Converts temperature to user preferred unit if set. """ """ Converts temperature to user preferred unit if set. """
if not (unit and self.temperature_unit and if not (unit in (TEMP_CELCIUS, TEMP_FAHRENHEIT) and
unit != self.temperature_unit): self.temperature_unit and unit != self.temperature_unit):
return value, unit return value, unit
try: try:
@ -783,7 +775,7 @@ def create_timer(hass, interval=TIMER_INTERVAL):
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_timer) hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_timer)
def create_worker_pool(): def create_worker_pool(worker_count=MIN_WORKER_THREAD):
""" Creates a worker pool to be used. """ """ Creates a worker pool to be used. """
def job_handler(job): def job_handler(job):
@ -807,4 +799,4 @@ def create_worker_pool():
_LOGGER.warning("WorkerPool:Current job from %s: %s", _LOGGER.warning("WorkerPool:Current job from %s: %s",
date_util.datetime_to_local_str(start), job) date_util.datetime_to_local_str(start), job)
return util.ThreadPool(job_handler, MIN_WORKER_THREAD, busy_callback) return util.ThreadPool(job_handler, worker_count, busy_callback)

View file

@ -205,8 +205,8 @@ def setup(hass, config):
for light in target_lights: for light in target_lights:
light.turn_off(**params) light.turn_off(**params)
if light.should_poll:
for light in target_lights: for light in target_lights:
if light.should_poll:
light.update_ha_state(True) light.update_ha_state(True)
return return

View file

@ -68,6 +68,8 @@ def track_point_in_utc_time(hass, action, point_in_time):
""" """
Adds a listener that fires once after a specific point in UTC time. Adds a listener that fires once after a specific point in UTC time.
""" """
# Ensure point_in_time is UTC
point_in_time = dt_util.as_utc(point_in_time)
@ft.wraps(action) @ft.wraps(action)
def point_in_time_listener(event): def point_in_time_listener(event):