Ejemplo n.º 1
0
async def test_setup_yaml_old_style_unique_id(hass: HomeAssistantType) -> None:
    """Test an already converted YAML style config."""
    # This tests "Possibility 2" from async_setup_platform()
    old_unique_id = f"{TEST_HOST}:{TEST_PORT}-0"

    # Add a pre-existing registry entry.
    registry = await async_get_registry(hass)
    registry.async_get_or_create(
        domain=LIGHT_DOMAIN,
        platform=DOMAIN,
        unique_id=old_unique_id,
        suggested_object_id=TEST_YAML_NAME,
    )

    client = create_mock_client()
    await _setup_entity_yaml(hass, client=client)

    # The entity should have been created with the same entity_id.
    assert hass.states.get(TEST_YAML_ENTITY_ID) is not None

    # The unique_id should have been updated in the registry (rather than the one
    # specified above).
    assert registry.async_get(
        TEST_YAML_ENTITY_ID).unique_id == get_hyperion_unique_id(
            TEST_SYSINFO_ID, 0, TYPE_HYPERION_LIGHT)
    assert registry.async_get_entity_id(LIGHT_DOMAIN, DOMAIN,
                                        old_unique_id) is None

    # There should be a config entry with the correct server unique_id.
    entry = _get_config_entry_from_unique_id(hass, TEST_SYSINFO_ID)
    assert entry
    assert entry.options == MappingProxyType(TEST_CONFIG_ENTRY_OPTIONS)
Ejemplo n.º 2
0
async def test_setup_yaml_new_style_unique_id_wo_config(
    hass: HomeAssistantType, ) -> None:
    """Test an a new unique_id without a config entry."""
    # Note: This casde should not happen in the wild, as no released version of Home
    # Assistant should this combination, but verify correct behavior for defense in
    # depth.

    new_unique_id = get_hyperion_unique_id(TEST_SYSINFO_ID, 0,
                                           TYPE_HYPERION_LIGHT)
    entity_id_to_preserve = "light.magic_entity"

    # Add a pre-existing registry entry.
    registry = await async_get_registry(hass)
    registry.async_get_or_create(
        domain=LIGHT_DOMAIN,
        platform=DOMAIN,
        unique_id=new_unique_id,
        suggested_object_id=entity_id_to_preserve.split(".")[1],
    )

    client = create_mock_client()
    await _setup_entity_yaml(hass, client=client)

    # The entity should have been created with the same entity_id.
    assert hass.states.get(entity_id_to_preserve) is not None

    # The unique_id should have been updated in the registry (rather than the one
    # specified above).
    assert registry.async_get(entity_id_to_preserve).unique_id == new_unique_id

    # There should be a config entry with the correct server unique_id.
    entry = _get_config_entry_from_unique_id(hass, TEST_SYSINFO_ID)
    assert entry
    assert entry.options == MappingProxyType(TEST_CONFIG_ENTRY_OPTIONS)
Ejemplo n.º 3
0
def register_test_entity(
    hass: HomeAssistant, domain: str, type_name: str, entity_id: str
) -> None:
    """Register a test entity."""
    unique_id = get_hyperion_unique_id(TEST_SYSINFO_ID, TEST_INSTANCE, type_name)
    entity_id = entity_id.split(".")[1]

    entity_registry = er.async_get(hass)
    entity_registry.async_get_or_create(
        domain,
        DOMAIN,
        unique_id,
        suggested_object_id=entity_id,
        disabled_by=None,
    )
Ejemplo n.º 4
0
async def test_setup_yaml_no_registry_entity(hass: HomeAssistantType) -> None:
    """Test an already converted YAML style config."""
    # This tests "Possibility 3" from async_setup_platform()

    registry = await async_get_registry(hass)

    # Add a pre-existing config entry.
    client = create_mock_client()
    await _setup_entity_yaml(hass, client=client)

    # The entity should have been created with the same entity_id.
    assert hass.states.get(TEST_YAML_ENTITY_ID) is not None

    # The unique_id should have been updated in the registry (rather than the one
    # specified above).
    assert registry.async_get(
        TEST_YAML_ENTITY_ID).unique_id == get_hyperion_unique_id(
            TEST_SYSINFO_ID, 0, TYPE_HYPERION_LIGHT)

    # There should be a config entry with the correct server unique_id.
    entry = _get_config_entry_from_unique_id(hass, TEST_SYSINFO_ID)
    assert entry
    assert entry.options == MappingProxyType(TEST_CONFIG_ENTRY_OPTIONS)