optimistic mode for template covers (w/o timed movement) (#8402)

* Emulate set_current_position in cover.template

* Add opportunistic mode

* Prevent another move when cover is already moving.  Add tests for opotunistic/timed-delay mode

* Remove timed-move capabilities

* Set init state to unknown

* cleanup template

* Update test_template.py
This commit is contained in:
PhracturedBlue authored and Pascal Vizeli committed 2017-08-25 12:33:53 +02:00
1 parent fb5019e73f
commit 2ec0d25a38
2 files changed
+118 -49

No files matched your search

+80 -27
View File
@@ -21,7 +21,7 @@ class TestTemplateCover(unittest.TestCase):
# pylint: disable=invalid-name
def setup_method(self, method):
"""Setup things to be run when tests are started."""
"""Initialize services when tests are started."""
self.hass = get_test_home_assistant()
self.calls = []
@@ -254,32 +254,6 @@ class TestTemplateCover(unittest.TestCase):
assert self.hass.states.all() == []
def test_template_position_or_value(self):
"""Test that at least one of value or position template is used."""
with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', {
'cover': {
'platform': 'template',
'covers': {
'test_template_cover': {
'open_cover': {
'service': 'cover.open_cover',
'entity_id': 'cover.test_state'
},
'close_cover': {
'service': 'cover.close_cover',
'entity_id': 'cover.test_state'
},
},
}
}
})
self.hass.start()
self.hass.block_till_done()
assert self.hass.states.all() == []
def test_template_open_or_position(self):
"""Test that at least one of open_cover or set_position is used."""
with assert_setup_component(1, 'cover'):
@@ -590,6 +564,85 @@ class TestTemplateCover(unittest.TestCase):
assert len(self.calls) == 1
def test_set_position_optimistic(self):
"""Test optimistic position mode."""
with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', {
'cover': {
'platform': 'template',
'covers': {
'test_template_cover': {
'set_cover_position': {
'service': 'test.automation',
},
}
}
}
})
self.hass.start()
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') is None
cover.set_cover_position(self.hass, 42,
'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_position') == 42.0
cover.close_cover(self.hass, 'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.state == STATE_CLOSED
cover.open_cover(self.hass, 'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.state == STATE_OPEN
def test_set_tilt_position_optimistic(self):
"""Test the optimistic tilt_position mode."""
with assert_setup_component(1, 'cover'):
assert setup.setup_component(self.hass, 'cover', {
'cover': {
'platform': 'template',
'covers': {
'test_template_cover': {
'position_template':
"{{ 100 }}",
'set_cover_position': {
'service': 'test.automation',
},
'set_cover_tilt_position': {
'service': 'test.automation',
},
}
}
}
})
self.hass.start()
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') is None
cover.set_cover_tilt_position(self.hass, 42,
'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 42.0
cover.close_cover_tilt(self.hass, 'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 0.0
cover.open_cover_tilt(self.hass, 'cover.test_template_cover')
self.hass.block_till_done()
state = self.hass.states.get('cover.test_template_cover')
assert state.attributes.get('current_tilt_position') == 100.0
def test_icon_template(self):
"""Test icon template."""
with assert_setup_component(1, 'cover'):