def test_tilt_position_altered_range(self):
        """Test tilt via method invocation with altered range."""
        self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'qos': 0,
                'payload_open': 'OPEN',
                'payload_close': 'CLOSE',
                'payload_stop': 'STOP',
                'tilt_command_topic': 'tilt-command-topic',
                'tilt_status_topic': 'tilt-status-topic',
                'tilt_opened_value': 400,
                'tilt_closed_value': 125,
                'tilt_min': 0,
                'tilt_max': 50
            }
        }))

        cover.set_cover_tilt_position(self.hass, 50, 'cover.test')
        self.hass.block_till_done()

        self.mock_publish.async_publish.assert_called_once_with(
            'tilt-command-topic', 25, 0, False)
Exemple #2
0
    def test_tilt_position(self):
        """Test tilt via method invocation."""
        self.assertTrue(
            setup_component(
                self.hass, cover.DOMAIN, {
                    cover.DOMAIN: {
                        'platform': 'mqtt',
                        'name': 'test',
                        'state_topic': 'state-topic',
                        'command_topic': 'command-topic',
                        'qos': 0,
                        'payload_open': 'OPEN',
                        'payload_close': 'CLOSE',
                        'payload_stop': 'STOP',
                        'tilt_command_topic': 'tilt-command-topic',
                        'tilt_status_topic': 'tilt-status-topic',
                        'tilt_opened_value': 400,
                        'tilt_closed_value': 125
                    }
                }))

        cover.set_cover_tilt_position(self.hass, 50, 'cover.test')
        self.hass.block_till_done()

        self.mock_publish.async_publish.assert_called_once_with(
            'tilt-command-topic', 50, 0, False)
Exemple #3
0
    def test_tilt_position_altered_range(self):
        """Test tilt via method invocation with altered range."""
        self.assertTrue(
            setup_component(
                self.hass, cover.DOMAIN, {
                    cover.DOMAIN: {
                        'platform': 'mqtt',
                        'name': 'test',
                        'state_topic': 'state-topic',
                        'command_topic': 'command-topic',
                        'qos': 0,
                        'payload_open': 'OPEN',
                        'payload_close': 'CLOSE',
                        'payload_stop': 'STOP',
                        'tilt_command_topic': 'tilt-command-topic',
                        'tilt_status_topic': 'tilt-status-topic',
                        'tilt_opened_value': 400,
                        'tilt_closed_value': 125,
                        'tilt_min': 0,
                        'tilt_max': 50
                    }
                }))

        cover.set_cover_tilt_position(self.hass, 50, 'cover.test')
        self.hass.block_till_done()

        self.assertEqual(('tilt-command-topic', 25, 0, False),
                         self.mock_publish.mock_calls[-2][1])
Exemple #4
0
    def test_set_tilt_position(self):
        """Test the set_tilt_position command."""
        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': 'cover.close_cover',
                                'entity_id': 'cover.test_state'
                            },
                            'set_cover_tilt_position': {
                                'service': 'test.automation',
                            },
                        }
                    }
                }
            })

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

        cover.set_cover_tilt_position(self.hass, 42,
                                      'cover.test_template_cover')
        self.hass.block_till_done()

        assert len(self.calls) == 1
    def test_set_cover_tilt_position(self):
        """Test moving the cover til to a specific position."""
        state = self.hass.states.get(ENTITY_COVER)
        self.assertEqual(50, state.attributes.get('current_tilt_position'))
        cover.set_cover_tilt_position(self.hass, 90, ENTITY_COVER)
        self.hass.block_till_done()
        for _ in range(7):
            future = dt_util.utcnow() + timedelta(seconds=1)
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(ENTITY_COVER)
        self.assertEqual(90, state.attributes.get('current_tilt_position'))
Exemple #6
0
    def test_set_cover_tilt_position(self):
        """Test moving the cover til to a specific position."""
        state = self.hass.states.get(ENTITY_COVER)
        self.assertEqual(50, state.attributes.get('current_tilt_position'))
        cover.set_cover_tilt_position(self.hass, 90, ENTITY_COVER)
        self.hass.block_till_done()
        for _ in range(7):
            future = dt_util.utcnow() + timedelta(seconds=1)
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(ENTITY_COVER)
        self.assertEqual(90, state.attributes.get('current_tilt_position'))
    def test_set_tilt_positions(self):
        """Test set tilt position function."""
        with assert_setup_component(2, DOMAIN):
            assert setup.setup_component(self.hass, DOMAIN, CONFIG)

        cover.set_cover_tilt_position(self.hass, 80, COVER_GROUP)
        self.hass.block_till_done()
        for _ in range(3):
            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_TILT_POSITION), 80)

        self.assertEqual(self.hass.states.get(DEMO_COVER_TILT)
                         .attributes.get(ATTR_CURRENT_TILT_POSITION), 80)
Exemple #8
0
    def test_set_tilt_positions(self):
        """Test set tilt position function."""
        with assert_setup_component(2, DOMAIN):
            assert setup.setup_component(self.hass, DOMAIN, CONFIG)

        cover.set_cover_tilt_position(self.hass, 80, COVER_GROUP)
        self.hass.block_till_done()
        for _ in range(3):
            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_TILT_POSITION), 80)

        self.assertEqual(
            self.hass.states.get(DEMO_COVER_TILT).attributes.get(
                ATTR_CURRENT_TILT_POSITION), 80)
Exemple #9
0
    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
Exemple #10
0
    def test_tilt_position(self):
        """Test tilt via method invocation."""
        self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'qos': 0,
                'payload_open': 'OPEN',
                'payload_close': 'CLOSE',
                'payload_stop': 'STOP',
                'tilt_command_topic': 'tilt-command-topic',
                'tilt_status_topic': 'tilt-status-topic',
                'tilt_opened_value': 400,
                'tilt_closed_value': 125
            }
        }))

        cover.set_cover_tilt_position(self.hass, 50, 'cover.test')
        self.hass.block_till_done()

        self.assertEqual(('tilt-command-topic', 50, 0, False),
                         self.mock_publish.mock_calls[-2][1])