Reverting a previous change to ensure a parameter is a list
This commit is contained in:
parent
9351acb498
commit
4f7e032bb4
3 changed files with 10 additions and 7 deletions
|
@ -3,7 +3,7 @@ from threading import RLock
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from homeassistant.EventBus import Event
|
from homeassistant.EventBus import Event
|
||||||
from homeassistant.util import matcher
|
from homeassistant.util import ensure_list, matcher
|
||||||
|
|
||||||
EVENT_STATE_CHANGED = "state_changed"
|
EVENT_STATE_CHANGED = "state_changed"
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ class StateMachine(object):
|
||||||
|
|
||||||
def track_state_change(eventbus, category, from_state, to_state, action):
|
def track_state_change(eventbus, category, from_state, to_state, action):
|
||||||
""" Helper method to track specific state changes. """
|
""" Helper method to track specific state changes. """
|
||||||
from_state = list(from_state)
|
from_state = ensure_list(from_state)
|
||||||
to_state = list(to_state)
|
to_state = ensure_list(to_state)
|
||||||
|
|
||||||
def listener(event):
|
def listener(event):
|
||||||
assert isinstance(event, Event), "event needs to be of Event type"
|
assert isinstance(event, Event), "event needs to be of Event type"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from homeassistant.EventBus import Event
|
from homeassistant.EventBus import Event
|
||||||
from homeassistant.util import matcher
|
from homeassistant.util import ensure_list, matcher
|
||||||
|
|
||||||
TIME_INTERVAL = 10 # seconds
|
TIME_INTERVAL = 10 # seconds
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ class Timer(threading.Thread):
|
||||||
|
|
||||||
|
|
||||||
def track_time_change(eventbus, action, year='*', month='*', day='*', hour='*', minute='*', second='*', point_in_time=None, listen_once=False):
|
def track_time_change(eventbus, action, year='*', month='*', day='*', hour='*', minute='*', second='*', point_in_time=None, listen_once=False):
|
||||||
year, month, day = list(year), list(month), list(day)
|
year, month, day = ensure_list(year), ensure_list(month), ensure_list(day)
|
||||||
hour, minute, second = list(hour), list(minute), list(second)
|
hour, minute, second = ensure_list(hour), ensure_list(minute), ensure_list(second)
|
||||||
|
|
||||||
def listener(event):
|
def listener(event):
|
||||||
assert isinstance(event, Event), "event needs to be of Event type"
|
assert isinstance(event, Event), "event needs to be of Event type"
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
def ensure_list(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 '*'. """
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue