Пример #1
0
async def test_google_entity_sync_serialize_with_local_sdk(hass):
    """Test sync serialize attributes of a GoogleEntity."""
    hass.states.async_set("light.ceiling_lights", "off")
    hass.config.api = Mock(port=1234, use_ssl=True)
    config = MockConfig(
        hass=hass,
        local_sdk_webhook_id="mock-webhook-id",
        local_sdk_user_id="mock-user-id",
    )
    entity = helpers.GoogleEntity(hass, config,
                                  hass.states.get("light.ceiling_lights"))

    serialized = await entity.sync_serialize(None)
    assert "otherDeviceIds" not in serialized
    assert "customData" not in serialized

    config.async_enable_local_sdk()

    serialized = await entity.sync_serialize(None)
    assert serialized["otherDeviceIds"] == [{
        "deviceId": "light.ceiling_lights"
    }]
    assert serialized["customData"] == {
        "httpPort": 1234,
        "httpSSL": True,
        "proxyDeviceId": None,
        "webhookId": "mock-webhook-id",
    }
Пример #2
0
def test_supported_features_string(caplog):
    """Test bad supported features."""
    entity = helpers.GoogleEntity(
        None, None, State("test.entity_id", "on", {"supported_features": "invalid"})
    )
    assert entity.is_supported() is False
    assert "Entity test.entity_id contains invalid supported_features value invalid"
Пример #3
0
async def test_google_entity_sync_serialize_with_local_sdk(hass):
    """Test sync serialize attributes of a GoogleEntity."""
    hass.states.async_set("light.ceiling_lights", "off")
    hass.config.api = Mock(port=1234, use_ssl=True)
    await async_process_ha_core_config(
        hass,
        {"external_url": "https://hostname:1234"},
    )

    hass.http = Mock(server_port=1234)
    config = MockConfig(
        hass=hass,
        agent_user_ids={
            "mock-user-id": {
                STORE_GOOGLE_LOCAL_WEBHOOK_ID: "mock-webhook-id",
            },
        },
    )
    entity = helpers.GoogleEntity(hass, config,
                                  hass.states.get("light.ceiling_lights"))

    serialized = await entity.sync_serialize(None)
    assert "otherDeviceIds" not in serialized
    assert "customData" not in serialized

    config.async_enable_local_sdk()

    with patch("homeassistant.helpers.instance_id.async_get",
               return_value="abcdef"):
        serialized = await entity.sync_serialize("mock-user-id")
        assert serialized["otherDeviceIds"] == [{
            "deviceId":
            "light.ceiling_lights"
        }]
        assert serialized["customData"] == {
            "httpPort": 1234,
            "httpSSL": True,
            "proxyDeviceId": "mock-user-id",
            "webhookId": "mock-webhook-id",
            "baseUrl": "https://hostname:1234",
            "uuid": "abcdef",
        }

    for device_type in NOT_EXPOSE_LOCAL:
        with patch(
                "homeassistant.components.google_assistant.helpers.get_google_type",
                return_value=device_type,
        ):
            serialized = await entity.sync_serialize(None)
            assert "otherDeviceIds" not in serialized
            assert "customData" not in serialized
Пример #4
0
async def test_google_entity_sync_serialize_with_local_sdk(hass):
    """Test sync serialize attributes of a GoogleEntity."""
    hass.states.async_set("light.ceiling_lights", "off")
    hass.config.api = Mock(port=1234,
                           use_ssl=True,
                           base_url="https://hostname:1234")
    hass.http = Mock(server_port=1234)
    config = MockConfig(
        hass=hass,
        local_sdk_webhook_id="mock-webhook-id",
        local_sdk_user_id="mock-user-id",
    )
    entity = helpers.GoogleEntity(hass, config,
                                  hass.states.get("light.ceiling_lights"))

    serialized = await entity.sync_serialize(None)
    assert "otherDeviceIds" not in serialized
    assert "customData" not in serialized

    config.async_enable_local_sdk()

    serialized = await entity.sync_serialize(None)
    assert serialized["otherDeviceIds"] == [{
        "deviceId": "light.ceiling_lights"
    }]
    assert serialized["customData"] == {
        "httpPort": 1234,
        "httpSSL": True,
        "proxyDeviceId": None,
        "webhookId": "mock-webhook-id",
        "baseUrl": "https://hostname:1234",
    }

    for device_type in NOT_EXPOSE_LOCAL:
        with patch(
                "homeassistant.components.google_assistant.helpers.get_google_type",
                return_value=device_type,
        ):
            serialized = await entity.sync_serialize(None)
            assert "otherDeviceIds" not in serialized
            assert "customData" not in serialized
Пример #5
0
 def entity(features: int):
     return helpers.GoogleEntity(
         None,
         config,
         State("test.entity_id", "on", {"supported_features": features}),
     )