Exemplo n.º 1
0
    def test_sending_mqtt_commands_and_optimistic(self):
        """Test the sending MQTT commands in optimistic mode."""
        assert setup_component(self.hass, lock.DOMAIN, {
            lock.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'command_topic': 'command-topic',
                'payload_lock': 'LOCK',
                'payload_unlock': 'UNLOCK',
                'qos': 2
            }
        })

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
        self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))

        lock.lock(self.hass, 'lock.test')
        self.hass.block_till_done()

        self.mock_publish.async_publish.assert_called_once_with(
            'command-topic', 'LOCK', 2, False)
        self.mock_publish.async_publish.reset_mock()
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_LOCKED, state.state)

        lock.unlock(self.hass, 'lock.test')
        self.hass.block_till_done()

        self.mock_publish.async_publish.assert_called_once_with(
            'command-topic', 'UNLOCK', 2, False)
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
Exemplo n.º 2
0
    def test_sending_mqtt_commands_and_optimistic(self):
        """Test the sending MQTT commands in optimistic mode."""
        self.hass.config.components = ['mqtt']
        assert _setup_component(
            self.hass, lock.DOMAIN, {
                lock.DOMAIN: {
                    'platform': 'mqtt',
                    'name': 'test',
                    'command_topic': 'command-topic',
                    'payload_lock': 'LOCK',
                    'payload_unlock': 'UNLOCK',
                    'qos': 2
                }
            })

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
        self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))

        lock.lock(self.hass, 'lock.test')
        self.hass.block_till_done()

        self.assertEqual(('command-topic', 'LOCK', 2, False),
                         self.mock_publish.mock_calls[-1][1])
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_LOCKED, state.state)

        lock.unlock(self.hass, 'lock.test')
        self.hass.block_till_done()

        self.assertEqual(('command-topic', 'UNLOCK', 2, False),
                         self.mock_publish.mock_calls[-1][1])
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
Exemplo n.º 3
0
    def test_sending_mqtt_commands_and_optimistic(self):
        """Test the sending MQTT commands in optimistic mode."""
        self.assertTrue(lock.setup(self.hass, {
            'lock': {
                'platform': 'mqtt',
                'name': 'test',
                'command_topic': 'command-topic',
                'payload_lock': 'LOCK',
                'payload_unlock': 'UNLOCK',
                'qos': 2
            }
        }))

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
        self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))

        lock.lock(self.hass, 'lock.test')
        self.hass.pool.block_till_done()

        self.assertEqual(('command-topic', 'LOCK', 2, False),
                         self.mock_publish.mock_calls[-1][1])
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_LOCKED, state.state)

        lock.unlock(self.hass, 'lock.test')
        self.hass.pool.block_till_done()

        self.assertEqual(('command-topic', 'UNLOCK', 2, False),
                         self.mock_publish.mock_calls[-1][1])
        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
Exemplo n.º 4
0
    def test_locking(self):
        """Test the locking of a lock."""
        lock.lock(self.hass, KITCHEN)
        self.hass.block_till_done()

        self.assertTrue(lock.is_locked(self.hass, KITCHEN))
Exemplo n.º 5
0
    def test_locking(self):
        lock.lock(self.hass, KITCHEN)

        self.hass.pool.block_till_done()

        self.assertTrue(lock.is_locked(self.hass, KITCHEN))
Exemplo n.º 6
0
    def test_locking(self):
        """Test the locking of a lock."""
        lock.lock(self.hass, KITCHEN)
        self.hass.block_till_done()

        self.assertTrue(lock.is_locked(self.hass, KITCHEN))