Lovelace not able to update input_select when created from states.set

I’m developing a component which creates input_selects on the fly.
so I have

def setup(hass: HomeAssistantType, config: ConfigType) -> bool:
    entity_id = 'input_select.test'
    attributes = {'options': ['one', 'two', 'three', 'four']}
    current_option = 'two'
    hass.states.set(entity_id, current_option, attributes)
    logger.debug(f"Created '{entity_id}' with option '{current_option}'")
    current_state = hass.states.get(entity_id)
    logger.debug(f"{current_state.entity_id} ({current_state.name}) state after creation is '{current_state.state}'")
    def handle_state_changed(event):
        nonlocal entity_id
        if event.data['entity_id'] != entity_id:
            return
        logger.debug(f"'{entity_id}' changed from {event.data['old_state'].state} to {event.data['new_state'].state}")
        return
    hass.bus.listen(EVENT_STATE_CHANGED, handle_state_changed)
    logger.debug("setup finished")
    return True

This works fine in creating the input_select and I can change (and detect) changes in state in Developer Tools->States.

When I use Lovelace to change the state it appears to work (in Lovelace’s ui) but the log shows

2020-11-11 10:02:11 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities input_select.test

and no EVENT_STATE_CHANGED is fired.
If I refresh the Lovelace page it reverts to the original value (confirming there was no change)
input_select.test does exist as it shows in the list of entities (with the correct integration ‘Input Select’)
What am I doing wrong?

Thanks

I don’t know how, but as far as I know, you need to register the input select in the entity register, otherwise you get the error you posted. I think you also need to do this in order to make your inout selects survive a restart.

Thanks @Burningstone I think you’re on to it.
I had a look in homeassistant.helpers.service.py and it seems the input_select platform entities does not contain my newly created input_select.

Maybe it’s something to do with not having a unique_id…

I’ll have to delve to see how I add my newly created input_select entity to the input_select platform…

Stuck now with chicken and egg
My new input_select entity is not in the entry registry as seen by

entity_registry.async_get_registry(hass)

Using

hass.states.get(entity_id)

returns a state object not an entity

So how do I get my newly created entity in order to add it to the registry?
Also curious how the ui Configuration->Entities shows it - where is it looking?