Skip to content

Commit

Permalink
minor cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
azogue committed Apr 22, 2020
1 parent cfd85f9 commit 837fa15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions custom_components/eventsensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,18 @@ async def async_setup_entry(
async_add_entities([EventSensor(config_entry.data)], False)

# add an update listener to enable edition by OptionsFlow
if config_entry.entry_id not in hass.data[DOMAIN_DATA]:
hass.data[DOMAIN_DATA][
config_entry.entry_id
] = config_entry.add_update_listener(update_listener)
else:
_LOGGER.warning("Already has a listener, is an update??")
hass.data[DOMAIN_DATA][config_entry.entry_id] = config_entry.add_update_listener(
update_listener
)


async def update_listener(hass: HomeAssistantType, entry: ConfigEntry):
"""Update when config_entry options update."""
changes = len(entry.options) > 1 and entry.data != entry.options
if changes:
# update entry replacing data with new options, and updating unique_id and title
_LOGGER.critical(
f"ON UPDATE IN PLATFORM: {entry.data} VS {entry.options}\n"
f"* data id={make_unique_id(entry.data)}\n"
f"* opts id={make_unique_id(entry.options)}"
_LOGGER.debug(
f"Config entry update with {entry.options} and unique_id:{entry.unique_id}"
)
hass.config_entries.async_update_entry(
entry,
Expand Down Expand Up @@ -198,15 +193,15 @@ def async_update_sensor(event: Event):
self._event, async_update_sensor
)
_LOGGER.debug(
"%s: Added sensor listening to '%s' with unique_id:%s",
"%s: Added sensor listening to '%s' with event data: %s",
self.entity_id,
self._event,
self.unique_id,
self._event_data,
)

async def async_will_remove_from_hass(self):
"""Remove listeners when removing entity from Home Assistant."""
if self._event_listener is not None:
self._event_listener()
self._event_listener = None
_LOGGER.debug("%s: Removing event listener", self.entity_id)
_LOGGER.debug("%s: Removed event listener", self.entity_id)
Binary file modified rsc/options_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 837fa15

Please sign in to comment.