Beispiel #1
0
    def test_methods(self):
        """Test increment, decrement, and reset methods."""
        config = {
            DOMAIN: {
                'test_1': {},
            }
        }

        assert setup_component(self.hass, 'counter', config)

        entity_id = 'counter.test_1'

        state = self.hass.states.get(entity_id)
        self.assertEqual(0, int(state.state))

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(1, int(state.state))

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(2, int(state.state))

        decrement(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(1, int(state.state))

        reset(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(0, int(state.state))
Beispiel #2
0
    def test_methods(self):
        """Test increment, decrement, and reset methods."""
        config = {
            DOMAIN: {
                'test_1': {},
            }
        }

        assert setup_component(self.hass, 'counter', config)

        entity_id = 'counter.test_1'

        state = self.hass.states.get(entity_id)
        assert 0 == int(state.state)

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 1 == int(state.state)

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 2 == int(state.state)

        decrement(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 1 == int(state.state)

        reset(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 0 == int(state.state)
Beispiel #3
0
    def test_methods_with_config(self):
        """Test increment, decrement, and reset methods with configuration."""
        config = {
            DOMAIN: {
                'test': {
                    CONF_NAME: 'Hello World',
                    CONF_INITIAL: 10,
                    CONF_STEP: 5,
                }
            }
        }

        assert setup_component(self.hass, 'counter', config)

        entity_id = 'counter.test'

        state = self.hass.states.get(entity_id)
        self.assertEqual(10, int(state.state))

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(15, int(state.state))

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(20, int(state.state))

        decrement(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(15, int(state.state))
Beispiel #4
0
    def test_methods_with_config(self):
        """Test increment, decrement, and reset methods with configuration."""
        config = {
            DOMAIN: {
                'test': {
                    CONF_NAME: 'Hello World',
                    CONF_INITIAL: 10,
                    CONF_STEP: 5,
                }
            }
        }

        assert setup_component(self.hass, 'counter', config)

        entity_id = 'counter.test'

        state = self.hass.states.get(entity_id)
        assert 10 == int(state.state)

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 15 == int(state.state)

        increment(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 20 == int(state.state)

        decrement(self.hass, entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert 15 == int(state.state)