Skip to content

Instantly share code, notes, and snippets.

@zachowj
Created November 30, 2019 23:31
Show Gist options
  • Save zachowj/141af91e0c7472e207c22f0b0430c3f8 to your computer and use it in GitHub Desktop.
Save zachowj/141af91e0c7472e207c22f0b0430c3f8 to your computer and use it in GitHub Desktop.
@callback
def handle_discovery_update(self, msg):
"""Update entity config"""
if CONF_REMOVE in msg:
# Remove entity
if msg[CONF_REMOVE] == CHANGE_ENTITY_TYPE:
# recreate entity if component type changed
@callback
def recreate_entity():
"""Create entity with new type"""
del msg[CONF_REMOVE]
async_dispatcher_send(
self.hass, NODERED_DISCOVERY.format(msg[CONF_COMPONENT]), msg
)
self.async_on_remove(recreate_entity)
self.hass.async_create_task(self.async_remove())
else:
self._config = msg[CONF_CONFIG]
self.async_write_ha_state()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment