Exemplo n.º 1
0
    def test_stop_covers(self):
        """Test stop cover function."""
        with assert_setup_component(2, DOMAIN):
            assert setup.setup_component(self.hass, DOMAIN, CONFIG)

        cover.open_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
        cover.stop_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()

        state = self.hass.states.get(COVER_GROUP)
        self.assertEqual(state.state, STATE_OPEN)
        self.assertEqual(state.attributes.get(ATTR_CURRENT_POSITION), 100)

        self.assertEqual(self.hass.states.get(DEMO_COVER).state, STATE_OPEN)
        self.assertEqual(
            self.hass.states.get(DEMO_COVER_POS).attributes.get(
                ATTR_CURRENT_POSITION), 20)
        self.assertEqual(
            self.hass.states.get(DEMO_COVER_TILT).attributes.get(
                ATTR_CURRENT_POSITION), 80)
Exemplo n.º 2
0
    def test_stop_covers(self):
        """Test stop cover function."""
        with assert_setup_component(2, DOMAIN):
            assert setup.setup_component(self.hass, DOMAIN, CONFIG)

        cover.open_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
        cover.stop_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()

        state = self.hass.states.get(COVER_GROUP)
        self.assertEqual(state.state, STATE_OPEN)
        self.assertEqual(state.attributes.get(ATTR_CURRENT_POSITION), 100)

        self.assertEqual(self.hass.states.get(DEMO_COVER).state, STATE_OPEN)
        self.assertEqual(self.hass.states.get(DEMO_COVER_POS)
                         .attributes.get(ATTR_CURRENT_POSITION), 20)
        self.assertEqual(self.hass.states.get(DEMO_COVER_TILT)
                         .attributes.get(ATTR_CURRENT_POSITION), 80)
Exemplo n.º 3
0
    def test_send_stop__cover_command(self):
        """Test the sending of stop_cover."""
        self.hass.config.components = set(['mqtt'])
        self.assertTrue(
            setup_component(
                self.hass, cover.DOMAIN, {
                    cover.DOMAIN: {
                        'platform': 'mqtt',
                        'name': 'test',
                        'state_topic': 'state-topic',
                        'command_topic': 'command-topic',
                        'qos': 2
                    }
                }))

        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)

        cover.stop_cover(self.hass, 'cover.test')
        self.hass.block_till_done()

        self.assertEqual(('command-topic', 'STOP', 2, False),
                         self.mock_publish.mock_calls[-2][1])
        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)
Exemplo n.º 4
0
 def test_stop_cover(self):
     """Test stopping the cover."""
     state = self.hass.states.get(ENTITY_COVER)
     self.assertEqual(70, state.attributes.get('current_position'))
     cover.open_cover(self.hass, ENTITY_COVER)
     self.hass.block_till_done()
     future = dt_util.utcnow() + timedelta(seconds=1)
     fire_time_changed(self.hass, future)
     self.hass.block_till_done()
     cover.stop_cover(self.hass, ENTITY_COVER)
     self.hass.block_till_done()
     fire_time_changed(self.hass, future)
     state = self.hass.states.get(ENTITY_COVER)
     self.assertEqual(80, state.attributes.get('current_position'))
Exemplo n.º 5
0
 def test_stop_cover(self):
     """Test stopping the cover."""
     state = self.hass.states.get(ENTITY_COVER)
     self.assertEqual(70, state.attributes.get('current_position'))
     cover.open_cover(self.hass, ENTITY_COVER)
     self.hass.block_till_done()
     future = dt_util.utcnow() + timedelta(seconds=1)
     fire_time_changed(self.hass, future)
     self.hass.block_till_done()
     cover.stop_cover(self.hass, ENTITY_COVER)
     self.hass.block_till_done()
     fire_time_changed(self.hass, future)
     state = self.hass.states.get(ENTITY_COVER)
     self.assertEqual(80, state.attributes.get('current_position'))
    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)
    def test_state_value(self):
        """Test with state value."""
        with tempfile.TemporaryDirectory() as tempdirname:
            path = os.path.join(tempdirname, 'cover_status')
            test_cover = {
                'command_state': 'cat {}'.format(path),
                'command_open': 'echo 1 > {}'.format(path),
                'command_close': 'echo 1 > {}'.format(path),
                'command_stop': 'echo 0 > {}'.format(path),
                'value_template': '{{ value }}'
            }
            self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
                '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.block_till_done()

            state = self.hass.states.get('cover.test')
            self.assertEqual('open', state.state)

            cover.close_cover(self.hass, 'cover.test')
            self.hass.block_till_done()

            state = self.hass.states.get('cover.test')
            self.assertEqual('open', state.state)

            cover.stop_cover(self.hass, 'cover.test')
            self.hass.block_till_done()

            state = self.hass.states.get('cover.test')
            self.assertEqual('closed', state.state)
Exemplo n.º 8
0
    def test_send_stop__cover_command(self):
        """Test the sending of stop_cover."""
        self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'qos': 2
            }
        }))

        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)

        cover.stop_cover(self.hass, 'cover.test')
        self.hass.block_till_done()

        self.mock_publish.async_publish.assert_called_once_with(
            'command-topic', 'STOP', 2, False)
        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)
Exemplo n.º 9
0
    def test_close_stop_action(self):
        """Test the close-cover and stop_cover commands."""
        with assert_setup_component(1, 'cover'):
            assert setup.setup_component(self.hass, 'cover', {
                'cover': {
                    'platform': 'template',
                    'covers': {
                        'test_template_cover': {
                            'position_template':
                                "{{ 100 }}",
                            'open_cover': {
                                'service': 'cover.open_cover',
                                'entity_id': 'cover.test_state'
                            },
                            'close_cover': {
                                'service': 'test.automation',
                            },
                            'stop_cover': {
                                'service': 'test.automation',
                            },
                        }
                    }
                }
            })

        self.hass.start()
        self.hass.block_till_done()

        state = self.hass.states.get('cover.test_template_cover')
        assert state.state == STATE_OPEN

        cover.close_cover(self.hass, 'cover.test_template_cover')
        self.hass.block_till_done()

        cover.stop_cover(self.hass, 'cover.test_template_cover')
        self.hass.block_till_done()

        assert len(self.calls) == 2
Exemplo n.º 10
0
    def test_send_stop__cover_command(self):
        """Test the sending of stop_cover."""
        self.hass.config.components = ['mqtt']
        assert _setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'qos': 2
            }
        })

        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)

        cover.stop_cover(self.hass, 'cover.test')
        self.hass.pool.block_till_done()

        self.assertEqual(('command-topic', 'STOP', 2, False),
                         self.mock_publish.mock_calls[-1][1])
        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNKNOWN, state.state)