Skip to content

Commit

Permalink
Refresh friendly_name in all location sensors after template update. #17
Browse files Browse the repository at this point in the history
  • Loading branch information
rodpayne committed Jun 4, 2024
1 parent 1426b63 commit 9b34cfe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion custom_components/person_location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DATA_ASYNC_SETUP_ENTRY,
DATA_CONFIG_ENTRY,
DATA_CONFIGURATION,
DATA_ENTITY_INFO,
DATA_UNDO_STATE_LISTENER,
DATA_UNDO_UPDATE_LISTENER,
DEFAULT_FRIENDLY_NAME_TEMPLATE,
Expand Down Expand Up @@ -88,13 +89,40 @@ async def _async_setup_entry(hass, entry):
entry.options,
)

friendly_name_template_changed = (
entry.options["friendly_name_template"] != pli.configuration["friendly_name_template"]
)
pli.configuration.update(entry.data)
pli.configuration.update(entry.options)

hass.data[DOMAIN][DATA_CONFIGURATION] = pli.configuration

await hass.async_add_executor_job(_listen_for_configured_entities)

if friendly_name_template_changed:

# Update the friendly_name for all enties that have been geocoded:

entity_info = hass.data[DOMAIN][DATA_ENTITY_INFO]

for sensor in entity_info:

if (
"geocode_count" in entity_info[sensor]
and entity_info[sensor]["geocode_count"] != 0
):

_LOGGER.debug(f"sensor to be updated = {sensor}")
service_data = {
"entity_id": sensor,
"friendly_name_template": pli.configuration[CONF_FRIENDLY_NAME_TEMPLATE],
"force_update": False,
}
await pli.hass.services.async_call(
DOMAIN, "reverse_geocode", service_data, False
)


_LOGGER.debug("[_async_setup_entry] === Return ===")
return True

Expand Down Expand Up @@ -224,7 +252,6 @@ async def async_options_update_listener(hass, entry):
async def async_unload_entry(hass, entry):
"""Unload a config entry."""

_LOGGER.debug("===== async_unload_entry")
if DATA_UNDO_UPDATE_LISTENER in hass.data[DOMAIN]:
hass.data[DOMAIN][DATA_UNDO_UPDATE_LISTENER]()

Expand Down
2 changes: 1 addition & 1 deletion custom_components/person_location/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
API_STATE_OBJECT = DOMAIN + "." + DOMAIN + "_integration"
INTEGRATION_NAME = "Person Location"
ISSUE_URL = "https://github.com/rodpayne/home-assistant_person_location/issues"
VERSION = "2024.06.01"
VERSION = "2024.06.03"

# Constants:
METERS_PER_KM = 1000
Expand Down
2 changes: 1 addition & 1 deletion custom_components/person_location/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/rodpayne/home-assistant_person_location/issues",
"requirements": [],
"version": "2024.06.01"
"version": "2024.06.03"
}

0 comments on commit 9b34cfe

Please sign in to comment.