Async cover template tests (#18690)

This commit is contained in:
Adam Mills 2018-11-25 11:39:35 -05:00 committed by GitHub
parent 91c526d9fe
commit 78b90be116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,8 @@
"""The tests the cover command line platform.""" """The tests the cover command line platform."""
import logging import logging
import unittest import pytest
from homeassistant import setup from homeassistant import setup
from homeassistant.core import callback
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_POSITION, ATTR_TILT_POSITION, DOMAIN) ATTR_POSITION, ATTR_TILT_POSITION, DOMAIN)
from homeassistant.const import ( from homeassistant.const import (
@ -12,41 +11,23 @@ from homeassistant.const import (
SERVICE_SET_COVER_TILT_POSITION, SERVICE_STOP_COVER, SERVICE_SET_COVER_TILT_POSITION, SERVICE_STOP_COVER,
STATE_CLOSED, STATE_OPEN) STATE_CLOSED, STATE_OPEN)
from tests.common import ( from tests.common import assert_setup_component, async_mock_service
get_test_home_assistant, assert_setup_component)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ENTITY_COVER = 'cover.test_template_cover' ENTITY_COVER = 'cover.test_template_cover'
class TestTemplateCover(unittest.TestCase): @pytest.fixture
"""Test the cover command line platform.""" def calls(hass):
"""Track calls to a mock serivce."""
return async_mock_service(hass, 'test', 'automation')
hass = None
calls = None
# pylint: disable=invalid-name
def setup_method(self, method): async def test_template_state_text(hass, calls):
"""Initialize services when tests are started."""
self.hass = get_test_home_assistant()
self.calls = []
@callback
def record_call(service):
"""Track function calls.."""
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
def test_template_state_text(self):
"""Test the state text of a template.""" """Test the state text of a template."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -66,25 +47,26 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.set('cover.test_state', STATE_OPEN) state = hass.states.async_set('cover.test_state', STATE_OPEN)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
state = self.hass.states.set('cover.test_state', STATE_CLOSED) state = hass.states.async_set('cover.test_state', STATE_CLOSED)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_CLOSED assert state.state == STATE_CLOSED
def test_template_state_boolean(self):
async def test_template_state_boolean(hass, calls):
"""Test the value_template attribute.""" """Test the value_template attribute."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -104,16 +86,17 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
def test_template_position(self):
async def test_template_position(hass, calls):
"""Test the position_template attribute.""" """Test the position_template attribute."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -133,41 +116,42 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.set('cover.test', STATE_CLOSED) state = hass.states.async_set('cover.test', STATE_CLOSED)
self.hass.block_till_done() await hass.async_block_till_done()
entity = self.hass.states.get('cover.test') entity = hass.states.get('cover.test')
attrs = dict() attrs = dict()
attrs['position'] = 42 attrs['position'] = 42
self.hass.states.set( hass.states.async_set(
entity.entity_id, entity.state, entity.entity_id, entity.state,
attributes=attrs) attributes=attrs)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 42.0 assert state.attributes.get('current_position') == 42.0
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
state = self.hass.states.set('cover.test', STATE_OPEN) state = hass.states.async_set('cover.test', STATE_OPEN)
self.hass.block_till_done() await hass.async_block_till_done()
entity = self.hass.states.get('cover.test') entity = hass.states.get('cover.test')
attrs['position'] = 0.0 attrs['position'] = 0.0
self.hass.states.set( hass.states.async_set(
entity.entity_id, entity.state, entity.entity_id, entity.state,
attributes=attrs) attributes=attrs)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 0.0 assert state.attributes.get('current_position') == 0.0
assert state.state == STATE_CLOSED assert state.state == STATE_CLOSED
def test_template_tilt(self):
async def test_template_tilt(hass, calls):
"""Test the tilt_template attribute.""" """Test the tilt_template attribute."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -189,16 +173,17 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 42.0 assert state.attributes.get('current_tilt_position') == 42.0
def test_template_out_of_bounds(self):
async def test_template_out_of_bounds(hass, calls):
"""Test template out-of-bounds condition.""" """Test template out-of-bounds condition."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -220,17 +205,18 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') is None assert state.attributes.get('current_tilt_position') is None
assert state.attributes.get('current_position') is None assert state.attributes.get('current_position') is None
def test_template_mutex(self):
async def test_template_mutex(hass, calls):
"""Test that only value or position template can be used.""" """Test that only value or position template can be used."""
with assert_setup_component(0, 'cover'): with assert_setup_component(0, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -256,15 +242,16 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
assert self.hass.states.all() == [] assert hass.states.async_all() == []
def test_template_open_or_position(self):
async def test_template_open_or_position(hass, calls):
"""Test that at least one of open_cover or set_position is used.""" """Test that at least one of open_cover or set_position is used."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -276,15 +263,16 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
assert self.hass.states.all() == [] assert hass.states.async_all() == []
def test_template_open_and_close(self):
async def test_template_open_and_close(hass, calls):
"""Test that if open_cover is specified, close_cover is too.""" """Test that if open_cover is specified, close_cover is too."""
with assert_setup_component(0, 'cover'): with assert_setup_component(0, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -300,15 +288,16 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
assert self.hass.states.all() == [] assert hass.states.async_all() == []
def test_template_non_numeric(self):
async def test_template_non_numeric(hass, calls):
"""Test that tilt_template values are numeric.""" """Test that tilt_template values are numeric."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -334,17 +323,18 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') is None assert state.attributes.get('current_tilt_position') is None
assert state.attributes.get('current_position') is None assert state.attributes.get('current_position') is None
def test_open_action(self):
async def test_open_action(hass, calls):
"""Test the open_cover command.""" """Test the open_cover command."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -363,23 +353,24 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_CLOSED assert state.state == STATE_CLOSED
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, DOMAIN, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.calls) == 1 assert len(calls) == 1
def test_close_stop_action(self):
async def test_close_stop_action(hass, calls):
"""Test the close-cover and stop_cover commands.""" """Test the close-cover and stop_cover commands."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -401,28 +392,29 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, DOMAIN, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_STOP_COVER, DOMAIN, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.calls) == 2 assert len(calls) == 2
def test_set_position(self):
async def test_set_position(hass, calls):
"""Test the set_position command.""" """Test the set_position command."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'input_number', { assert await setup.async_setup_component(hass, 'input_number', {
'input_number': { 'input_number': {
'test': { 'test': {
'min': '0', 'min': '0',
@ -431,7 +423,7 @@ class TestTemplateCover(unittest.TestCase):
} }
} }
}) })
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -450,39 +442,40 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.set('input_number.test', 42) state = hass.states.async_set('input_number.test', 42)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, DOMAIN, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 100.0 assert state.attributes.get('current_position') == 100.0
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, DOMAIN, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 0.0 assert state.attributes.get('current_position') == 0.0
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_SET_COVER_POSITION, DOMAIN, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 25}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 25}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 25.0 assert state.attributes.get('current_position') == 25.0
def test_set_tilt_position(self):
async def test_set_tilt_position(hass, calls):
"""Test the set_tilt_position command.""" """Test the set_tilt_position command."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -505,21 +498,22 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_SET_COVER_TILT_POSITION, DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42}, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42},
blocking=True) blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.calls) == 1 assert len(calls) == 1
def test_open_tilt_action(self):
async def test_open_tilt_action(hass, calls):
"""Test the open_cover_tilt command.""" """Test the open_cover_tilt command."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -542,20 +536,21 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER_TILT, DOMAIN, SERVICE_OPEN_COVER_TILT,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.calls) == 1 assert len(calls) == 1
def test_close_tilt_action(self):
async def test_close_tilt_action(hass, calls):
"""Test the close_cover_tilt command.""" """Test the close_cover_tilt command."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -578,20 +573,21 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER_TILT, DOMAIN, SERVICE_CLOSE_COVER_TILT,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.calls) == 1 assert len(calls) == 1
def test_set_position_optimistic(self):
async def test_set_position_optimistic(hass, calls):
"""Test optimistic position mode.""" """Test optimistic position mode."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -603,37 +599,38 @@ class TestTemplateCover(unittest.TestCase):
} }
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') is None assert state.attributes.get('current_position') is None
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_SET_COVER_POSITION, DOMAIN, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 42}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 42}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 42.0 assert state.attributes.get('current_position') == 42.0
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, DOMAIN, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_CLOSED assert state.state == STATE_CLOSED
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, DOMAIN, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
def test_set_tilt_position_optimistic(self):
async def test_set_tilt_position_optimistic(hass, calls):
"""Test the optimistic tilt_position mode.""" """Test the optimistic tilt_position mode."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -650,38 +647,39 @@ class TestTemplateCover(unittest.TestCase):
} }
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') is None assert state.attributes.get('current_tilt_position') is None
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_SET_COVER_TILT_POSITION, DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42}, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42},
blocking=True) blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 42.0 assert state.attributes.get('current_tilt_position') == 42.0
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER_TILT, DOMAIN, SERVICE_CLOSE_COVER_TILT,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 0.0 assert state.attributes.get('current_tilt_position') == 0.0
self.hass.services.call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER_TILT, DOMAIN, SERVICE_OPEN_COVER_TILT,
{ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True) {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 100.0 assert state.attributes.get('current_tilt_position') == 100.0
def test_icon_template(self):
async def test_icon_template(hass, calls):
"""Test icon template.""" """Test icon template."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -705,23 +703,24 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('icon') == '' assert state.attributes.get('icon') == ''
state = self.hass.states.set('cover.test_state', STATE_OPEN) state = hass.states.async_set('cover.test_state', STATE_OPEN)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes['icon'] == 'mdi:check' assert state.attributes['icon'] == 'mdi:check'
def test_entity_picture_template(self):
async def test_entity_picture_template(hass, calls):
"""Test icon template.""" """Test icon template."""
with assert_setup_component(1, 'cover'): with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', { assert await setup.async_setup_component(hass, 'cover', {
'cover': { 'cover': {
'platform': 'template', 'platform': 'template',
'covers': { 'covers': {
@ -745,15 +744,15 @@ class TestTemplateCover(unittest.TestCase):
} }
}) })
self.hass.start() await hass.async_start()
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes.get('entity_picture') == '' assert state.attributes.get('entity_picture') == ''
state = self.hass.states.set('cover.test_state', STATE_OPEN) state = hass.states.async_set('cover.test_state', STATE_OPEN)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get('cover.test_template_cover') state = hass.states.get('cover.test_template_cover')
assert state.attributes['entity_picture'] == '/local/cover.png' assert state.attributes['entity_picture'] == '/local/cover.png'