Combine garage_door and rollershutter to cover (#2891)

* First draft for cover component

* Efficiency from @martinhjelmare

* migrate demo

* migrate demo test

* migrate command_line rollershutter

* migrate command_line test

* migrate rpi_gpio garage_door

* make some abstract methods optional

* migrate homematic

* migrate scsgate

* migrate rfxtrx and test

* migrate zwave

* migrate wink

* migrate mqtt rollershutter and test

* requirements

* coverage

* Update mqtt with garage door

* Naming and cleanup

* update test_demo.py

* update demo and core

* Add deprecated warning to rollershutter and garage_door

* Naming again

* Update

* String constants

* Make sure set_position works properly in demo too

* Make sure position is not set if not available.

* Naming, and is_closed

* Update zwave.py

* requirements

* Update test_rfxtrx.py

* fix mqtt

* requirements

* fix wink version

* Fixed demo test

* naming
This commit is contained in:
John Arild Berentsen 2016-08-24 03:23:18 +02:00 committed by Paulus Schoutsen
parent a43ea81d8e
commit cf832499cd
21 changed files with 2006 additions and 11 deletions

View file

@ -0,0 +1,84 @@
"""The tests the cover command line platform."""
import os
import tempfile
import unittest
from unittest import mock
import homeassistant.core as ha
import homeassistant.components.cover as cover
from homeassistant.components.cover import (
command_line as cmd_rs)
class TestCommandCover(unittest.TestCase):
"""Test the cover command line platform."""
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = ha.HomeAssistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.rs = cmd_rs.CommandCover(self.hass, 'foo',
'cmd_open', 'cmd_close',
'cmd_stop', 'cmd_state',
None) # FIXME
def teardown_method(self, method):
"""Stop down everything that was started."""
self.hass.stop()
def test_should_poll(self):
"""Test the setting of polling."""
self.assertTrue(self.rs.should_poll)
self.rs._command_state = None
self.assertFalse(self.rs.should_poll)
def test_query_state_value(self):
"""Test with state value."""
with mock.patch('subprocess.check_output') as mock_run:
mock_run.return_value = b' foo bar '
result = self.rs._query_state_value('runme')
self.assertEqual('foo bar', result)
mock_run.assert_called_once_with('runme', shell=True)
def test_state_value(self):
"""Test with state value."""
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'cover_status')
test_cover = {
'statecmd': 'cat {}'.format(path),
'opencmd': 'echo 1 > {}'.format(path),
'closecmd': 'echo 1 > {}'.format(path),
'stopcmd': 'echo 0 > {}'.format(path),
'value_template': '{{ value }}'
}
self.assertTrue(cover.setup(self.hass, {
'cover': {
'platform': 'command_line',
'covers': {
'test': test_cover
}
}
}))
state = self.hass.states.get('cover.test')
self.assertEqual('unknown', state.state)
cover.open_cover(self.hass, 'cover.test')
self.hass.pool.block_till_done()
state = self.hass.states.get('cover.test')
self.assertEqual('open', state.state)
cover.close_cover(self.hass, 'cover.test')
self.hass.pool.block_till_done()
state = self.hass.states.get('cover.test')
self.assertEqual('open', state.state)
cover.stop_cover(self.hass, 'cover.test')
self.hass.pool.block_till_done()
state = self.hass.states.get('cover.test')
self.assertEqual('closed', state.state)