Merge pull request #412 from balloob/dev

0.7.3rc2
This commit is contained in:
Paulus Schoutsen 2015-09-19 21:07:24 -07:00
commit 9736761968
24 changed files with 281 additions and 137 deletions

7
.gitignore vendored
View File

@ -15,10 +15,6 @@ tests/config/home-assistant.log
*.sublime-project *.sublime-project
*.sublime-workspace *.sublime-workspace
# Hide code validator output
pep8.txt
pylint.txt
# Hide some OS X stuff # Hide some OS X stuff
.DS_Store .DS_Store
.AppleDouble .AppleDouble
@ -30,6 +26,9 @@ Icon
.idea .idea
# pytest
.cache
# GITHUB Proposed Python stuff: # GITHUB Proposed Python stuff:
*.py[cod] *.py[cod]

View File

@ -16,9 +16,9 @@ DOMAIN = 'automation'
DEPENDENCIES = ['group'] DEPENDENCIES = ['group']
CONF_ALIAS = 'alias' CONF_ALIAS = 'alias'
CONF_SERVICE = 'execute_service' CONF_SERVICE = 'service'
CONF_SERVICE_ENTITY_ID = 'service_entity_id' CONF_SERVICE_ENTITY_ID = 'entity_id'
CONF_SERVICE_DATA = 'service_data' CONF_SERVICE_DATA = 'data'
CONF_CONDITION = 'condition' CONF_CONDITION = 'condition'
CONF_ACTION = 'action' CONF_ACTION = 'action'
@ -40,25 +40,45 @@ def setup(hass, config):
found = 1 found = 1
while config_key in config: while config_key in config:
p_config = _migrate_old_config(config[config_key]) # check for one block syntax
if isinstance(config[config_key], dict):
config_block = _migrate_old_config(config[config_key])
name = config_block.get(CONF_ALIAS, config_key)
_setup_automation(hass, config_block, name, config)
# check for multiple block syntax
elif isinstance(config[config_key], list):
for list_no, config_block in enumerate(config[config_key]):
name = config_block.get(CONF_ALIAS,
"{}, {}".format(config_key, list_no))
_setup_automation(hass, config_block, name, config)
# any scalar value is incorrect
else:
_LOGGER.error('Error in config in section %s.', config_key)
found += 1 found += 1
config_key = "{} {}".format(DOMAIN, found) config_key = "{} {}".format(DOMAIN, found)
name = p_config.get(CONF_ALIAS, config_key) return True
action = _get_action(hass, p_config.get(CONF_ACTION, {}), name)
def _setup_automation(hass, config_block, name, config):
""" Setup one instance of automation """
action = _get_action(hass, config_block.get(CONF_ACTION, {}), name)
if action is None:
return False
if CONF_CONDITION in config_block or CONF_CONDITION_TYPE in config_block:
action = _process_if(hass, config, config_block, action)
if action is None: if action is None:
continue return False
if CONF_CONDITION in p_config or CONF_CONDITION_TYPE in p_config:
action = _process_if(hass, config, p_config, action)
if action is None:
continue
_process_trigger(hass, config, p_config.get(CONF_TRIGGER, []), name,
action)
_process_trigger(hass, config, config_block.get(CONF_TRIGGER, []), name,
action)
return True return True
@ -118,7 +138,10 @@ def _migrate_old_config(config):
('trigger', 'state_from', 'from'), ('trigger', 'state_from', 'from'),
('trigger', 'state_hours', 'hours'), ('trigger', 'state_hours', 'hours'),
('trigger', 'state_minutes', 'minutes'), ('trigger', 'state_minutes', 'minutes'),
('trigger', 'state_seconds', 'seconds')): ('trigger', 'state_seconds', 'seconds'),
('action', 'execute_service', 'service'),
('action', 'service_entity_id', 'entity_id'),
('action', 'service_data', 'data')):
if key in new_conf[cat]: if key in new_conf[cat]:
new_conf[cat][new_key] = new_conf[cat].pop(key) new_conf[cat][new_key] = new_conf[cat].pop(key)

View File

@ -20,11 +20,12 @@ def trigger(hass, config, action):
_LOGGER.error("Missing configuration key %s", CONF_EVENT_TYPE) _LOGGER.error("Missing configuration key %s", CONF_EVENT_TYPE)
return False return False
event_data = config.get(CONF_EVENT_DATA, {}) event_data = config.get(CONF_EVENT_DATA)
def handle_event(event): def handle_event(event):
""" Listens for events and calls the action when data matches. """ """ Listens for events and calls the action when data matches. """
if event_data == event.data: if not event_data or all(val == event.data.get(key) for key, val
in event_data.items()):
action() action()
hass.bus.listen(event_type, handle_event) hass.bus.listen(event_type, handle_event)

View File

@ -27,8 +27,7 @@ def trigger(hass, config, action):
if CONF_AFTER in config: if CONF_AFTER in config:
after = dt_util.parse_time_str(config[CONF_AFTER]) after = dt_util.parse_time_str(config[CONF_AFTER])
if after is None: if after is None:
_LOGGER.error( _error_time(config[CONF_AFTER], CONF_AFTER)
'Received invalid after value: %s', config[CONF_AFTER])
return False return False
hours, minutes, seconds = after.hour, after.minute, after.second hours, minutes, seconds = after.hour, after.minute, after.second
elif (CONF_HOURS in config or CONF_MINUTES in config elif (CONF_HOURS in config or CONF_MINUTES in config
@ -63,28 +62,28 @@ def if_action(hass, config):
CONF_BEFORE, CONF_AFTER, CONF_WEEKDAY) CONF_BEFORE, CONF_AFTER, CONF_WEEKDAY)
return None return None
if before is not None:
before = dt_util.parse_time_str(before)
if before is None:
_error_time(before, CONF_BEFORE)
return None
if after is not None:
after = dt_util.parse_time_str(after)
if after is None:
_error_time(after, CONF_AFTER)
return None
def time_if(): def time_if():
""" Validate time based if-condition """ """ Validate time based if-condition """
now = dt_util.now() now = dt_util.now()
if before is not None: if before is not None and now > now.replace(hour=before.hour,
time = dt_util.parse_time_str(before) minute=before.minute):
if time is None: return False
return False
before_point = now.replace(hour=time.hour, minute=time.minute) if after is not None and now < now.replace(hour=after.hour,
minute=after.minute):
if now > before_point: return False
return False
if after is not None:
time = dt_util.parse_time_str(after)
if time is None:
return False
after_point = now.replace(hour=time.hour, minute=time.minute)
if now < after_point:
return False
if weekday is not None: if weekday is not None:
now_weekday = WEEKDAYS[now.weekday()] now_weekday = WEEKDAYS[now.weekday()]
@ -96,3 +95,11 @@ def if_action(hass, config):
return True return True
return time_if return time_if
def _error_time(value, key):
""" Helper method to print error. """
_LOGGER.error(
"Received invalid value for '%s': %s", key, value)
if isinstance(value, int):
_LOGGER.error('Make sure you wrap time values in quotes')

View File

@ -352,7 +352,7 @@ def load_config(path, hass, consider_home):
Device(hass, consider_home, device.get('track', False), Device(hass, consider_home, device.get('track', False),
str(dev_id).lower(), str(device.get('mac')).upper(), str(dev_id).lower(), str(device.get('mac')).upper(),
device.get('name'), device.get('picture'), device.get('name'), device.get('picture'),
device.get(CONF_AWAY_HIDE, False)) device.get(CONF_AWAY_HIDE, DEFAULT_AWAY_HIDE))
for dev_id, device in load_yaml_config_file(path).items()] for dev_id, device in load_yaml_config_file(path).items()]

@ -1 +1 @@
Subproject commit 63e039a221ae6771e0d7c6990d9a93b7cc22fc64 Subproject commit 68f6c6ae5d37a1f0fcd1c36a8803581f9367ac5f

View File

@ -147,8 +147,6 @@ def _api_history_period(handler, path_match, data):
end_time = start_time + one_day end_time = start_time + one_day
print("Fetching", start_time, end_time)
entity_id = data.get('filter_entity_id') entity_id = data.get('filter_entity_id')
handler.write_json( handler.write_json(

View File

@ -132,7 +132,10 @@ def humanify(events):
# Process events # Process events
for event in events_batch: for event in events_batch:
if event.event_type == EVENT_STATE_CHANGED: if event.event_type == EVENT_STATE_CHANGED:
entity_id = event.data['entity_id'] entity_id = event.data.get('entity_id')
if entity_id is None:
continue
if entity_id.startswith('sensor.'): if entity_id.startswith('sensor.'):
last_sensor_event[entity_id] = event last_sensor_event[entity_id] = event

View File

@ -1,7 +1,7 @@
""" """
homeassistant.components.script homeassistant.components.script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
entity_id
Scripts are a sequence of actions that can be triggered manually Scripts are a sequence of actions that can be triggered manually
by the user or automatically based upon automation events, etc. by the user or automatically based upon automation events, etc.
""" """
@ -25,6 +25,7 @@ CONF_SEQUENCE = "sequence"
CONF_EVENT = "event" CONF_EVENT = "event"
CONF_EVENT_DATA = "event_data" CONF_EVENT_DATA = "event_data"
CONF_DELAY = "delay" CONF_DELAY = "delay"
ATTR_ENTITY_ID = "entity_id"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -43,15 +44,22 @@ def setup(hass, config):
hass.services.register(DOMAIN, name, script) hass.services.register(DOMAIN, name, script)
scripts.append(script) scripts.append(script)
def _get_entities(service):
""" Make sure that we always get a list of entities """
if isinstance(service.data[ATTR_ENTITY_ID], list):
return service.data[ATTR_ENTITY_ID]
else:
return [service.data[ATTR_ENTITY_ID]]
def turn_on(service): def turn_on(service):
""" Calls a script. """ """ Calls a script. """
for entity_id in service.data['entity_id']: for entity_id in _get_entities(service):
domain, service = split_entity_id(entity_id) domain, service = split_entity_id(entity_id)
hass.services.call(domain, service, {}) hass.services.call(domain, service, {})
def turn_off(service): def turn_off(service):
""" Cancels a script. """ """ Cancels a script. """
for entity_id in service.data['entity_id']: for entity_id in _get_entities(service):
for script in scripts: for script in scripts:
if script.entity_id == entity_id: if script.entity_id == entity_id:
script.cancel() script.cancel()

View File

@ -70,7 +70,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
data, data,
config.get('name', DEFAULT_NAME), config.get('name', DEFAULT_NAME),
config.get('unit_of_measurement'), config.get('unit_of_measurement'),
config.get('correction_factor', None), config.get('correction_factor', 1.0),
config.get('decimal_places', 0) config.get('decimal_places', 0)
)]) )])
@ -108,12 +108,15 @@ class CommandSensor(Entity):
self.data.update() self.data.update()
value = self.data.value value = self.data.value
if value is not None: try:
if self._corr_factor is not None: if value is not None:
self._state = round((int(value) * self._corr_factor), if self._corr_factor is not None:
self._decimal_places) self._state = round((float(value) * self._corr_factor),
else: self._decimal_places)
self._state = value else:
self._state = value
except ValueError:
self._state = value
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods

View File

@ -31,7 +31,7 @@ Details for the API : http://transport.opendata.ch
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
from requests import get import requests
from homeassistant.util import Throttle from homeassistant.util import Throttle
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -53,8 +53,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
try: try:
for location in [config.get('from', None), config.get('to', None)]: for location in [config.get('from', None), config.get('to', None)]:
# transport.opendata.ch doesn't play nice with requests.Session # transport.opendata.ch doesn't play nice with requests.Session
result = get(_RESOURCE + 'locations?query=%s' % location, result = requests.get(_RESOURCE + 'locations?query=%s' % location,
timeout=10) timeout=10)
journey.append(result.json()['stations'][0]['name']) journey.append(result.json()['stations'][0]['name'])
except KeyError: except KeyError:
_LOGGER.exception( _LOGGER.exception(
@ -110,7 +110,7 @@ class PublicTransportData(object):
def update(self): def update(self):
""" Gets the latest data from opendata.ch. """ """ Gets the latest data from opendata.ch. """
response = get( response = requests.get(
_RESOURCE + _RESOURCE +
'connections?' + 'connections?' +
'from=' + self.start + '&' + 'from=' + self.start + '&' +

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
testpaths = tests

View File

@ -4,4 +4,9 @@
# designed to run on the continuous integration server. # designed to run on the continuous integration server.
script/test coverage script/test coverage
STATUS=$?
coveralls coveralls
exit $STATUS

View File

@ -34,25 +34,27 @@ RUN_AS="USER"
PID_FILE="/var/run/hass.pid" PID_FILE="/var/run/hass.pid"
CONFIG_DIR="/var/opt/homeassistant" CONFIG_DIR="/var/opt/homeassistant"
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon" FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
REDIRECT="> $CONFIG_DIR/home-assistant.log 2>&1"
start() { start() {
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE); then if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
echo 'Service already running' >&2 echo 'Service already running' >&2
return 1 return 1
fi fi
echo 'Starting service…' >&2 echo 'Starting service…' >&2
local CMD="$PRE_EXEC hass $FLAGS;" local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
su -c "$CMD" $RUN_AS su -c "$CMD" $RUN_AS
echo 'Service started' >&2 echo 'Service started' >&2
} }
stop() { stop() {
if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE"); then if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then
echo 'Service not running' >&2 echo 'Service not running' >&2
return 1 return 1
fi fi
echo 'Stopping service…' >&2 echo 'Stopping service…' >&2
kill -3 $(cat "$PID_FILE") kill -3 $(cat "$PID_FILE")
while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;
echo 'Service stopped' >&2 echo 'Service stopped' >&2
} }

View File

@ -3,7 +3,16 @@
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
echo "Checking style with flake8..." echo "Checking style with flake8..."
flake8 homeassistant flake8 --exclude www_static homeassistant
STATUS=$?
echo "Checking style with pylint..." echo "Checking style with pylint..."
pylint homeassistant pylint homeassistant
if [ $STATUS -eq 0 ]
then
exit $?
else
exit $STATUS
fi

View File

@ -2,3 +2,4 @@ cd "$(dirname "$0")/.."
git submodule init git submodule init
script/bootstrap script/bootstrap
python3 setup.py develop

View File

@ -7,10 +7,19 @@ cd "$(dirname "$0")/.."
script/lint script/lint
STATUS=$?
echo "Running tests..." echo "Running tests..."
if [ "$1" = "coverage" ]; then if [ "$1" = "coverage" ]; then
py.test --cov homeassistant tests py.test --cov --cov-report=
else else
py.test tests py.test
fi
if [ $STATUS -eq 0 ]
then
exit $?
else
exit $STATUS
fi fi

View File

@ -75,7 +75,7 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -93,12 +93,13 @@ class TestAutomationEvent(unittest.TestCase):
'event_data': {'some_attr': 'some_value'} 'event_data': {'some_attr': 'some_value'}
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
self.hass.bus.fire('test_event', {'some_attr': 'some_value'}) self.hass.bus.fire('test_event', {'some_attr': 'some_value',
'another': 'value'})
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
@ -111,7 +112,7 @@ class TestAutomationEvent(unittest.TestCase):
'event_data': {'some_attr': 'some_value'} 'event_data': {'some_attr': 'some_value'}
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))

View File

@ -10,7 +10,7 @@ import homeassistant.components.automation as automation
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
class TestAutomationEvent(unittest.TestCase): class TestAutomation(unittest.TestCase):
""" Test the event automation. """ """ Test the event automation. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
@ -26,7 +26,7 @@ class TestAutomationEvent(unittest.TestCase):
""" Stop down stuff we started. """ """ Stop down stuff we started. """
self.hass.stop() self.hass.stop()
def test_service_data_not_a_dict(self): def test_old_config_service_data_not_a_dict(self):
automation.setup(self.hass, { automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
'platform': 'event', 'platform': 'event',
@ -87,6 +87,24 @@ class TestAutomationEvent(unittest.TestCase):
self.assertEqual(['hello.world', 'hello.world2'], self.assertEqual(['hello.world', 'hello.world2'],
self.calls[0].data.get(ATTR_ENTITY_ID)) self.calls[0].data.get(ATTR_ENTITY_ID))
def test_service_data_not_a_dict(self):
automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'data': 100,
}
}
})
self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
def test_service_specify_data(self): def test_service_specify_data(self):
automation.setup(self.hass, { automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
@ -95,8 +113,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_data': {'some': 'data'} 'data': {'some': 'data'}
} }
} }
}) })
@ -114,8 +132,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_entity_id': 'hello.world' 'entity_id': 'hello.world'
} }
} }
}) })
@ -134,8 +152,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_entity_id': ['hello.world', 'hello.world2'] 'entity_id': ['hello.world', 'hello.world2']
} }
} }
}) })
@ -160,7 +178,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -195,7 +213,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -239,7 +257,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -278,7 +296,7 @@ class TestAutomationEvent(unittest.TestCase):
], ],
'condition': 'use_trigger_values', 'condition': 'use_trigger_values',
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -314,7 +332,7 @@ class TestAutomationEvent(unittest.TestCase):
], ],
'condition': 'use_trigger_values', 'condition': 'use_trigger_values',
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -322,3 +340,34 @@ class TestAutomationEvent(unittest.TestCase):
self.hass.bus.fire('test_event') self.hass.bus.fire('test_event')
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
def test_automation_list_setting(self):
""" Event is not a valid condition. Will it still work? """
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: [{
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
}
}, {
'trigger': {
'platform': 'event',
'event_type': 'test_event_2',
},
'action': {
'service': 'test.automation',
}
}]
}))
self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
self.hass.bus.fire('test_event_2')
self.hass.pool.block_till_done()
self.assertEqual(2, len(self.calls))

View File

@ -77,7 +77,7 @@ class TestAutomationState(unittest.TestCase):
'topic': 'test-topic' 'topic': 'test-topic'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -95,7 +95,7 @@ class TestAutomationState(unittest.TestCase):
'payload': 'hello' 'payload': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -113,7 +113,7 @@ class TestAutomationState(unittest.TestCase):
'payload': 'hello' 'payload': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))

View File

@ -35,7 +35,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -56,7 +56,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -78,7 +78,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -97,7 +97,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -119,7 +119,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -142,7 +142,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -162,7 +162,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -181,7 +181,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -203,7 +203,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -226,7 +226,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -244,7 +244,7 @@ class TestAutomationNumericState(unittest.TestCase):
'entity_id': 'test.another_entity', 'entity_id': 'test.another_entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -269,7 +269,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': test_state + 2 'below': test_state + 2
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })

View File

@ -164,7 +164,7 @@ class TestAutomationState(unittest.TestCase):
'entity_id': 'test.entity', 'entity_id': 'test.entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -182,7 +182,7 @@ class TestAutomationState(unittest.TestCase):
'from': 'hello' 'from': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -200,7 +200,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -218,7 +218,7 @@ class TestAutomationState(unittest.TestCase):
'state': 'world' 'state': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -237,7 +237,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -256,7 +256,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -277,7 +277,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -294,7 +294,7 @@ class TestAutomationState(unittest.TestCase):
'entity_id': 'test.anoter_entity', 'entity_id': 'test.anoter_entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -318,7 +318,7 @@ class TestAutomationState(unittest.TestCase):
'state': test_state 'state': test_state
}], }],
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })

View File

@ -51,7 +51,7 @@ class TestAutomationSun(unittest.TestCase):
'event': 'sunset', 'event': 'sunset',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -77,7 +77,7 @@ class TestAutomationSun(unittest.TestCase):
'event': 'sunrise', 'event': 'sunrise',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -104,7 +104,7 @@ class TestAutomationSun(unittest.TestCase):
'offset': '0:30:00' 'offset': '0:30:00'
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -131,7 +131,7 @@ class TestAutomationSun(unittest.TestCase):
'offset': '-0:30:00' 'offset': '-0:30:00'
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))

View File

@ -36,9 +36,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_hour_matches(self): def test_old_config_if_fires_when_hour_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_HOURS: 0, time.CONF_HOURS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -51,9 +51,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_minute_matches(self): def test_old_config_if_fires_when_minute_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_MINUTES: 0, time.CONF_MINUTES: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -66,9 +66,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_second_matches(self): def test_old_config_if_fires_when_second_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_SECONDS: 0, time.CONF_SECONDS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -85,7 +85,7 @@ class TestAutomationTime(unittest.TestCase):
time.CONF_HOURS: 0, time.CONF_HOURS: 0,
time.CONF_MINUTES: 0, time.CONF_MINUTES: 0,
time.CONF_SECONDS: 0, time.CONF_SECONDS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -101,7 +101,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_BEFORE: '10:00' time.CONF_BEFORE: '10:00'
@ -131,7 +131,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_AFTER: '10:00' time.CONF_AFTER: '10:00'
@ -161,7 +161,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_WEEKDAY: 'mon', time.CONF_WEEKDAY: 'mon',
@ -192,7 +192,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_WEEKDAY: ['mon', 'tue'], time.CONF_WEEKDAY: ['mon', 'tue'],
@ -234,7 +234,7 @@ class TestAutomationTime(unittest.TestCase):
'hours': 0, 'hours': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -252,7 +252,7 @@ class TestAutomationTime(unittest.TestCase):
'minutes': 0, 'minutes': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -270,7 +270,7 @@ class TestAutomationTime(unittest.TestCase):
'seconds': 0, 'seconds': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -285,18 +285,18 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
'trigger': { 'trigger': {
'platform': 'time', 'platform': 'time',
'hours': 0, 'hours': 1,
'minutes': 0, 'minutes': 2,
'seconds': 0, 'seconds': 3,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
fire_time_changed(self.hass, dt_util.utcnow().replace( fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=0, minute=0, second=0)) hour=1, minute=2, second=3))
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
@ -309,7 +309,7 @@ class TestAutomationTime(unittest.TestCase):
'after': '5:00:00', 'after': '5:00:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -320,6 +320,30 @@ class TestAutomationTime(unittest.TestCase):
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
@patch('homeassistant.components.automation.time._LOGGER.error')
def test_if_not_fires_using_wrong_after(self, mock_error):
""" YAML translates time values to total seconds. This should break the
before rule. """
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'after': 3605,
# Total seconds. Hour = 3600 second
},
'action': {
'service': 'test.automation'
}
}
}))
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=1, minute=0, second=5))
self.hass.pool.block_till_done()
self.assertEqual(0, len(self.calls))
self.assertEqual(2, mock_error.call_count)
def test_if_action_before(self): def test_if_action_before(self):
automation.setup(self.hass, { automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
@ -332,7 +356,7 @@ class TestAutomationTime(unittest.TestCase):
'before': '10:00', 'before': '10:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -366,7 +390,7 @@ class TestAutomationTime(unittest.TestCase):
'after': '10:00', 'after': '10:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -400,7 +424,7 @@ class TestAutomationTime(unittest.TestCase):
'weekday': 'mon', 'weekday': 'mon',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -435,7 +459,7 @@ class TestAutomationTime(unittest.TestCase):
'weekday': ['mon', 'tue'], 'weekday': ['mon', 'tue'],
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })