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