async def test_unavailable_state_doesnt_sync(hass):
    """Test that an unavailable entity does not sync over."""
    light = DemoLight(
        None,
        'Demo Light',
        state=False,
    )
    light.hass = hass
    light.entity_id = 'light.demo_light'
    light._available = False  # pylint: disable=protected-access
    await light.async_update_ha_state()

    result = await sh.async_handle_message(
        hass, BASIC_CONFIG, 'test-agent', {
            "requestId": REQ_ID,
            "inputs": [{
                "intent": "action.devices.SYNC"
            }]
        })

    assert result == {
        'requestId': REQ_ID,
        'payload': {
            'agentUserId': 'test-agent',
            'devices': []
        }
    }
Ejemplo n.º 2
0
async def test_unavailable_state_doesnt_sync(hass):
    """Test that an unavailable entity does not sync over."""
    light = DemoLight(None, "Demo Light", state=False)
    light.hass = hass
    light.entity_id = "light.demo_light"
    light._available = False  # pylint: disable=protected-access
    await light.async_update_ha_state()

    result = await sh.async_handle_message(
        hass,
        BASIC_CONFIG,
        "test-agent",
        {
            "requestId": REQ_ID,
            "inputs": [{
                "intent": "action.devices.SYNC"
            }]
        },
    )

    assert result == {
        "requestId": REQ_ID,
        "payload": {
            "agentUserId": "test-agent",
            "devices": []
        },
    }
Ejemplo n.º 3
0
async def test_unavailable_state_doesnt_sync(hass):
    """Test that an unavailable entity does not sync over."""
    light = DemoLight(
        None, 'Demo Light',
        state=False,
    )
    light.hass = hass
    light.entity_id = 'light.demo_light'
    light._available = False    # pylint: disable=protected-access
    await light.async_update_ha_state()

    result = await sh.async_handle_message(
        hass, BASIC_CONFIG, 'test-agent',
        {
            "requestId": REQ_ID,
            "inputs": [{
                "intent": "action.devices.SYNC"
            }]
        })

    assert result == {
        'requestId': REQ_ID,
        'payload': {
            'agentUserId': 'test-agent',
            'devices': []
        }
    }
Ejemplo n.º 4
0
async def test_unavailable_state_does_sync(hass):
    """Test that an unavailable entity does sync over."""
    light = DemoLight(None, "Demo Light", state=False, hs_color=(180, 75))
    light.hass = hass
    light.entity_id = "light.demo_light"
    light._available = False  # pylint: disable=protected-access
    await light.async_update_ha_state()

    events = []
    hass.bus.async_listen(EVENT_SYNC_RECEIVED, events.append)

    result = await sh.async_handle_message(
        hass,
        BASIC_CONFIG,
        "test-agent",
        {
            "requestId": REQ_ID,
            "inputs": [{
                "intent": "action.devices.SYNC"
            }]
        },
        const.SOURCE_CLOUD,
    )

    assert result == {
        "requestId": REQ_ID,
        "payload": {
            "agentUserId":
            "test-agent",
            "devices": [{
                "id":
                "light.demo_light",
                "name": {
                    "name": "Demo Light"
                },
                "traits": [
                    trait.TRAIT_BRIGHTNESS,
                    trait.TRAIT_ONOFF,
                    trait.TRAIT_COLOR_SETTING,
                ],
                "type":
                const.TYPE_LIGHT,
                "willReportState":
                False,
                "attributes": {
                    "colorModel": "hsv",
                    "colorTemperatureRange": {
                        "temperatureMinK": 2000,
                        "temperatureMaxK": 6535,
                    },
                },
            }],
        },
    }
    await hass.async_block_till_done()

    assert len(events) == 1
    assert events[0].event_type == EVENT_SYNC_RECEIVED
    assert events[0].data == {"request_id": REQ_ID, "source": "cloud"}
Ejemplo n.º 5
0
async def test_unavailable_state_does_sync(hass):
    """Test that an unavailable entity does sync over."""
    light = DemoLight(
        None,
        "Demo Light",
        state=False,
        hs_color=(180, 75),
        effect_list=LIGHT_EFFECT_LIST,
        effect=LIGHT_EFFECT_LIST[0],
    )
    light.hass = hass
    light.entity_id = "light.demo_light"
    light._available = False  # pylint: disable=protected-access
    await light.async_update_ha_state()

    events = async_capture_events(hass, EVENT_SYNC_RECEIVED)

    result = await sh.async_handle_message(
        hass,
        BASIC_CONFIG,
        "test-agent",
        {"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
        const.SOURCE_CLOUD,
    )

    assert result == {
        "requestId": REQ_ID,
        "payload": {
            "agentUserId": "test-agent",
            "devices": [
                {
                    "id": "light.demo_light",
                    "name": {"name": "Demo Light"},
                    "traits": [
                        trait.TRAIT_BRIGHTNESS,
                        trait.TRAIT_ONOFF,
                        trait.TRAIT_COLOR_SETTING,
                        trait.TRAIT_MODES,
                    ],
                    "type": const.TYPE_LIGHT,
                    "willReportState": False,
                    "attributes": {
                        "availableModes": [
                            {
                                "name": "effect",
                                "name_values": [
                                    {"lang": "en", "name_synonym": ["effect"]}
                                ],
                                "ordered": False,
                                "settings": [
                                    {
                                        "setting_name": "rainbow",
                                        "setting_values": [
                                            {
                                                "lang": "en",
                                                "setting_synonym": ["rainbow"],
                                            }
                                        ],
                                    },
                                    {
                                        "setting_name": "none",
                                        "setting_values": [
                                            {"lang": "en", "setting_synonym": ["none"]}
                                        ],
                                    },
                                ],
                            }
                        ],
                        "colorModel": "hsv",
                        "colorTemperatureRange": {
                            "temperatureMinK": 2000,
                            "temperatureMaxK": 6535,
                        },
                    },
                }
            ],
        },
    }
    await hass.async_block_till_done()

    assert len(events) == 1
    assert events[0].event_type == EVENT_SYNC_RECEIVED
    assert events[0].data == {"request_id": REQ_ID, "source": "cloud"}