Example #1
0
async def test_methods_with_config(hass):
    """Test increment, decrement, and reset methods with configuration."""
    config = {
        DOMAIN: {"test": {CONF_NAME: "Hello World", CONF_INITIAL: 10, CONF_STEP: 5}}
    }

    assert await async_setup_component(hass, "counter", config)

    entity_id = "counter.test"

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

    async_increment(hass, entity_id)
    await hass.async_block_till_done()

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

    async_increment(hass, entity_id)
    await hass.async_block_till_done()

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

    async_decrement(hass, entity_id)
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert 15 == int(state.state)
Example #2
0
async def test_methods(hass):
    """Test increment, decrement, and reset methods."""
    config = {DOMAIN: {"test_1": {}}}

    assert await async_setup_component(hass, "counter", config)

    entity_id = "counter.test_1"

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

    async_increment(hass, entity_id)
    await hass.async_block_till_done()

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

    async_increment(hass, entity_id)
    await hass.async_block_till_done()

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

    async_decrement(hass, entity_id)
    await hass.async_block_till_done()

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

    async_reset(hass, entity_id)
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert 0 == int(state.state)
Example #3
0
async def test_methods(opp):
    """Test increment, decrement, and reset methods."""
    config = {DOMAIN: {"test_1": {}}}

    assert await async_setup_component(opp, "counter", config)

    entity_id = "counter.test_1"

    state = opp.states.get(entity_id)
    assert int(state.state) == 0

    async_increment(opp, entity_id)
    await opp.async_block_till_done()

    state = opp.states.get(entity_id)
    assert int(state.state) == 1

    async_increment(opp, entity_id)
    await opp.async_block_till_done()

    state = opp.states.get(entity_id)
    assert int(state.state) == 2

    async_decrement(opp, entity_id)
    await opp.async_block_till_done()

    state = opp.states.get(entity_id)
    assert int(state.state) == 1

    async_reset(opp, entity_id)
    await opp.async_block_till_done()

    state = opp.states.get(entity_id)
    assert int(state.state) == 0