Merge remote-tracking branch 'balloob/dev' into automation-decorator
# Conflicts: # homeassistant/helpers/service.py # tests/helpers/test_service.py
This commit is contained in:
commit
60dd2d441d
28 files changed
+374
-191
No files matched your search
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
tests.components.automation.test_location
|
||||
±±±~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests location automation.
|
||||
"""
|
||||
import unittest
|
||||
|
||||
from homeassistant.components import zone
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestAutomationZone(unittest.TestCase):
|
||||
""" Test the event automation. """
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup(self):
|
||||
info = {
|
||||
'name': 'Test Zone',
|
||||
'latitude': 32.880837,
|
||||
'longitude': -117.237561,
|
||||
'radius': 250,
|
||||
'passive': True
|
||||
}
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': info
|
||||
})
|
||||
|
||||
state = self.hass.states.get('zone.test_zone')
|
||||
assert info['name'] == state.name
|
||||
assert info['latitude'] == state.attributes['latitude']
|
||||
assert info['longitude'] == state.attributes['longitude']
|
||||
assert info['radius'] == state.attributes['radius']
|
||||
assert info['passive'] == state.attributes['passive']
|
||||
|
||||
def test_active_zone_skips_passive_zones(self):
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': [
|
||||
{
|
||||
'name': 'Passive Zone',
|
||||
'latitude': 32.880600,
|
||||
'longitude': -117.237561,
|
||||
'radius': 250,
|
||||
'passive': True
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
active = zone.active_zone(self.hass, 32.880600, -117.237561)
|
||||
assert active is None
|
||||
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': [
|
||||
{
|
||||
'name': 'Active Zone',
|
||||
'latitude': 32.880800,
|
||||
'longitude': -117.237561,
|
||||
'radius': 500,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
active = zone.active_zone(self.hass, 32.880700, -117.237561)
|
||||
assert 'zone.active_zone' == active.entity_id
|
||||
|
||||
def test_active_zone_prefers_smaller_zone_if_same_distance(self):
|
||||
latitude = 32.880600
|
||||
longitude = -117.237561
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': [
|
||||
{
|
||||
'name': 'Small Zone',
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'radius': 250,
|
||||
},
|
||||
{
|
||||
'name': 'Big Zone',
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'radius': 500,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
active = zone.active_zone(self.hass, latitude, longitude)
|
||||
assert 'zone.small_zone' == active.entity_id
|
||||
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': [
|
||||
{
|
||||
'name': 'Smallest Zone',
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'radius': 50,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
active = zone.active_zone(self.hass, latitude, longitude)
|
||||
assert 'zone.smallest_zone' == active.entity_id
|
||||
|
||||
def test_in_zone_works_for_passive_zones(self):
|
||||
latitude = 32.880600
|
||||
longitude = -117.237561
|
||||
assert zone.setup(self.hass, {
|
||||
'zone': [
|
||||
{
|
||||
'name': 'Passive Zone',
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'radius': 250,
|
||||
'passive': True
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
assert zone.in_zone(self.hass.states.get('zone.passive_zone'),
|
||||
latitude, longitude)
|
||||
@@ -42,3 +42,8 @@ class TestHelpersEntity(unittest.TestCase):
|
||||
|
||||
state = self.hass.states.get(self.entity.entity_id)
|
||||
self.assertTrue(state.attributes.get(ATTR_HIDDEN))
|
||||
|
||||
def test_split_entity_id(self):
|
||||
""" Test split_entity_id. """
|
||||
self.assertEqual(['domain', 'object_id'],
|
||||
entity.split_entity_id('domain.object_id'))
|
||||
@@ -7,45 +7,22 @@ Tests component helpers.
|
||||
# pylint: disable=protected-access,too-many-public-methods
|
||||
import unittest
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant import loader, helpers
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ENTITY_ID
|
||||
from homeassistant import helpers
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestComponentsCore(unittest.TestCase):
|
||||
""" Tests homeassistant.components module. """
|
||||
class TestHelpers(unittest.TestCase):
|
||||
""" Tests homeassistant.helpers module. """
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
""" Init needed objects. """
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set('light.Kitchen', STATE_OFF)
|
||||
|
||||
loader.get_component('group').setup_group(
|
||||
self.hass, 'test', ['light.Ceiling', 'light.Kitchen'])
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_extract_entity_ids(self):
|
||||
""" Test extract_entity_ids method. """
|
||||
call = ha.ServiceCall('light', 'turn_on',
|
||||
{ATTR_ENTITY_ID: 'light.Bowl'})
|
||||
|
||||
self.assertEqual(['light.bowl'],
|
||||
helpers.extract_entity_ids(self.hass, call))
|
||||
|
||||
call = ha.ServiceCall('light', 'turn_on',
|
||||
{ATTR_ENTITY_ID: 'group.test'})
|
||||
|
||||
self.assertEqual(['light.ceiling', 'light.kitchen'],
|
||||
helpers.extract_entity_ids(self.hass, call))
|
||||
|
||||
def test_extract_domain_configs(self):
|
||||
config = {
|
||||
'zone': None,
|
||||
|
||||
@@ -7,6 +7,8 @@ Test service helpers.
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import core as ha, loader
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ENTITY_ID
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_service
|
||||
@@ -78,3 +80,24 @@ class TestServiceHelpers(unittest.TestCase):
|
||||
'service': 'invalid'
|
||||
})
|
||||
self.assertEqual(3, mock_log.call_count)
|
||||
|
||||
def test_extract_entity_ids(self):
|
||||
""" Test extract_entity_ids method. """
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set('light.Kitchen', STATE_OFF)
|
||||
|
||||
loader.get_component('group').setup_group(
|
||||
self.hass, 'test', ['light.Ceiling', 'light.Kitchen'])
|
||||
|
||||
call = ha.ServiceCall('light', 'turn_on',
|
||||
{ATTR_ENTITY_ID: 'light.Bowl'})
|
||||
|
||||
self.assertEqual(['light.bowl'],
|
||||
service.extract_entity_ids(self.hass, call))
|
||||
|
||||
call = ha.ServiceCall('light', 'turn_on',
|
||||
{ATTR_ENTITY_ID: 'group.test'})
|
||||
|
||||
self.assertEqual(['light.ceiling', 'light.kitchen'],
|
||||
service.extract_entity_ids(self.hass, call))
|
||||
@@ -94,13 +94,14 @@ class TestConfig(unittest.TestCase):
|
||||
with self.assertRaises(HomeAssistantError):
|
||||
config_util.load_yaml_config_file(YAML_PATH)
|
||||
|
||||
def test_load_config_loads_yaml_config(self):
|
||||
""" Test correct YAML config loading. """
|
||||
def test_load_yaml_config_preserves_key_order(self):
|
||||
with open(YAML_PATH, 'w') as f:
|
||||
f.write('hello: world')
|
||||
f.write('hello: 0\n')
|
||||
f.write('world: 1\n')
|
||||
|
||||
self.assertEqual({'hello': 'world'},
|
||||
config_util.load_config_file(YAML_PATH))
|
||||
self.assertEqual(
|
||||
[('hello', 0), ('world', 1)],
|
||||
list(config_util.load_yaml_config_file(YAML_PATH).items()))
|
||||
|
||||
@mock.patch('homeassistant.util.location.detect_location_info',
|
||||
mock_detect_location_info)
|
||||
@@ -109,7 +110,7 @@ class TestConfig(unittest.TestCase):
|
||||
""" Test that detect location sets the correct config keys. """
|
||||
config_util.ensure_config_exists(CONFIG_DIR)
|
||||
|
||||
config = config_util.load_config_file(YAML_PATH)
|
||||
config = config_util.load_yaml_config_file(YAML_PATH)
|
||||
|
||||
self.assertIn(DOMAIN, config)
|
||||
|
||||
|
||||
@@ -36,11 +36,6 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual("test_more", util.slugify("Test More"))
|
||||
self.assertEqual("test_more", util.slugify("Test_(More)"))
|
||||
|
||||
def test_split_entity_id(self):
|
||||
""" Test split_entity_id. """
|
||||
self.assertEqual(['domain', 'object_id'],
|
||||
util.split_entity_id('domain.object_id'))
|
||||
|
||||
def test_repr_helper(self):
|
||||
""" Test repr_helper. """
|
||||
self.assertEqual("A", util.repr_helper("A"))
|
||||
|
||||
Reference in new issue
Block a user