Repository: home-assistant/core
File: tests/components/home_connect/test_number.py (Python)

Code before:
                            level="info",
                            handling="auto",
                            value=None,
                        )
                    ]
                ),
            )
        ]
    )
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert state
    assert state.state != STATE_UNAVAILABLE


@pytest.mark.parametrize("appliance", ["Oven"], indirect=True)
async def test_restore_option_entity(
    hass: HomeAssistant,
    entity_registry: er.EntityRegistry,
    client: MagicMock,
    config_entry: MockConfigEntry,
    integration_setup: Callable[[MagicMock], Awaitable[bool]],
    appliance: HomeAppliance,
) -> None:
    """Test that option entities are restored if the available program does not include them but they existed once."""
    entity_id = "number.oven_setpoint_temperature"
    client.get_available_program = AsyncMock(
        return_value=ProgramDefinition(
            ProgramKey.UNKNOWN,
            options=[],
        )
    )

    entity_registry.async_get_or_create(
        Platform.NUMBER,
        DOMAIN,
        f"{appliance.ha_id}-{OptionKey.COOKING_OVEN_SETPOINT_TEMPERATURE}",
        suggested_object_id="oven_setpoint_temperature",
    )

    assert await integration_setup(client)
    assert config_entry.state is ConfigEntryState.LOADED

    assert hass.states.is_state(entity_id, STATE_UNAVAILABLE)


Review comment (suggestion):
Please follow PEP8 for docstrings. Lines should be shorter than 72 characters. The first line is a header. The header should be a single sentence and fit on the first line. After the header an optional body may follow, separated from the header by a blank line. The body may be multiple sentences and lines.

Code after:
                    [
                        Event(
                            event_key,
                            event_key.value,
                            0,
                            level="info",
                            handling="auto",
                            value=None,
                        )
                    ]
                ),
            )
        ]
    )
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert state
    assert state.state != STATE_UNAVAILABLE


@pytest.mark.parametrize("appliance", ["Oven"], indirect=True)
async def test_restore_option_entity(
    hass: HomeAssistant,
    entity_registry: er.EntityRegistry,
    client: MagicMock,
    config_entry: MockConfigEntry,
    integration_setup: Callable[[MagicMock], Awaitable[bool]],
    appliance: HomeAppliance,
) -> None:
    """Test restoration of option entities when program options are missing.

    This test ensures that number entities representing options are restored
    to the entity registry and set to unavailable if the current available
    program does not include them, but they existed previously.
    """
    entity_id = "number.oven_setpoint_temperature"
    client.get_available_program = AsyncMock(
        return_value=ProgramDefinition(
            ProgramKey.UNKNOWN,
            options=[],
        )
    )

    entity_registry.async_get_or_create(
        Platform.NUMBER,
        DOMAIN,
        f"{appliance.ha_id}-{OptionKey.COOKING_OVEN_SETPOINT_TEMPERATURE}",
        suggested_object_id="oven_setpoint_temperature",
    )