コード例 #1
0
async def test_turn_on(hass: HomeAssistant):
    """Test support of the light.turn_on service."""
    client = ClientMock()
    client.is_on = False
    client.brightness = 20
    entity, _, _ = await _create_entries(hass, client)

    assert hass.states.get(entity.entity_id).state == "off"

    await hass.services.async_call(
        "light", "turn_on", service_data={"entity_id": entity.entity_id})
    await hass.async_block_till_done()

    state = hass.states.get(entity.entity_id)

    assert state.state == "on"
    assert state.attributes["brightness"] == 51
コード例 #2
0
async def test_turn_on_with_brightness(opp: OpenPeerPower):
    """Test support of the light.turn_on service with a brightness parameter."""
    client = ClientMock()
    client.is_on = False
    client.brightness = 20
    entity, _, _ = await _create_entries(opp, client)

    assert opp.states.get(entity.entity_id).state == "off"

    await opp.services.async_call(
        "light",
        "turn_on",
        service_data={
            "entity_id": entity.entity_id,
            "brightness": 255
        },
    )
    await opp.async_block_till_done()

    state = opp.states.get(entity.entity_id)

    assert state.state == "on"
    assert state.attributes["brightness"] == 255