From 8f583dc6e3e79a32792a00e0596a5a867a4541a2 Mon Sep 17 00:00:00 2001 From: kongo09 Date: Fri, 6 Mar 2026 23:12:42 +0000 Subject: [PATCH] Deduplicate remote cleanup logic and fix "Remote Buttons" casing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract shared entity/device cleanup into _cleanup_remote_entities() and call it from both _handle_removed_remote and _async_options_updated, eliminating duplicated code. Also fix "Remote buttons" → "Remote Buttons" in manifest.json, hacs.json, and config_flow.py for consistent branding. Co-Authored-By: Claude Opus 4.6 --- custom_components/remote_buttons/__init__.py | 36 +------------------ .../remote_buttons/config_flow.py | 2 +- .../remote_buttons/manifest.json | 2 +- hacs.json | 2 +- 4 files changed, 4 insertions(+), 38 deletions(-) diff --git a/custom_components/remote_buttons/__init__.py b/custom_components/remote_buttons/__init__.py index 62af661..7e14592 100644 --- a/custom_components/remote_buttons/__init__.py +++ b/custom_components/remote_buttons/__init__.py @@ -205,41 +205,7 @@ def _handle_removed_remote( _LOGGER.info("Watched remote removed: %s — cleaning up", entity_id) - data = entry.runtime_data - known = data.known_commands - - # Find all commands belonging to this remote. - to_remove = {(r, s, c) for r, s, c in known if r == entity_id} - - # Remove button entities and collect affected subdevices. - entity_reg = er.async_get(hass) - subdevices: set[str] = set() - for _remote, subdevice, cmd_name in to_remove: - subdevices.add(subdevice) - uid = f"remote_buttons_{entity_id}_{subdevice}_{cmd_name}" - ent_id = entity_reg.async_get_entity_id(Platform.BUTTON, DOMAIN, uid) - if ent_id: - entity_reg.async_remove(ent_id) - - # Remove IR number entities for affected subdevices. - ir_numbers = data.ir_numbers - ir_subdevices = data.ir_subdevices - for subdevice in subdevices: - _remove_ir_numbers(entity_reg, entity_id, subdevice, ir_numbers, ir_subdevices) - - # Remove subdevice device entries that have no remaining entities. - device_reg = dr.async_get(hass) - for subdevice in subdevices: - dev_identifier = (DOMAIN, f"{entity_id}_{subdevice}") - device_entry = device_reg.async_get_device(identifiers={dev_identifier}) - if device_entry: - # Check if any entities still reference this device. - remaining = er.async_entries_for_device(entity_reg, device_entry.id) - if not remaining: - device_reg.async_remove_device(device_entry.id) - - # Update known commands. - data.known_commands = known - to_remove + _cleanup_remote_entities(hass, entry, entity_id) # Remove this remote from the watched list. watched.remove(entity_id) diff --git a/custom_components/remote_buttons/config_flow.py b/custom_components/remote_buttons/config_flow.py index 4903bd6..8e9dc52 100644 --- a/custom_components/remote_buttons/config_flow.py +++ b/custom_components/remote_buttons/config_flow.py @@ -32,7 +32,7 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Con if user_input is not None: return self.async_create_entry( - title="Remote buttons", + title="Remote Buttons", data={CONF_REMOTE_ENTITIES: user_input[CONF_REMOTE_ENTITIES]}, ) diff --git a/custom_components/remote_buttons/manifest.json b/custom_components/remote_buttons/manifest.json index 485b55f..a57d2f5 100644 --- a/custom_components/remote_buttons/manifest.json +++ b/custom_components/remote_buttons/manifest.json @@ -1,6 +1,6 @@ { "domain": "remote_buttons", - "name": "Remote buttons", + "name": "Remote Buttons", "after_dependencies": ["broadlink", "tuya_local"], "codeowners": ["@kongo09"], "config_flow": true, diff --git a/hacs.json b/hacs.json index 78209e5..edb2d55 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { - "name": "Remote buttons", + "name": "Remote Buttons", "homeassistant": "2026.3.0", "render_readme": true }