From ec5142f405c047dd2a79c73e4da749238ec6610f Mon Sep 17 00:00:00 2001 From: Andrew Grimberg Date: Mon, 27 Feb 2023 12:09:35 -0800 Subject: [PATCH 1/2] Fix: Add unique IDs to generated automations Issue: Fixes #155 Signed-off-by: Andrew Grimberg --- custom_components/rental_control/templates/clear_code.yaml.j2 | 1 + custom_components/rental_control/templates/set_code.yaml.j2 | 1 + custom_components/rental_control/templates/startup.yaml.j2 | 1 + custom_components/rental_control/templates/update.yaml.j2 | 1 + 4 files changed, 4 insertions(+) diff --git a/custom_components/rental_control/templates/clear_code.yaml.j2 b/custom_components/rental_control/templates/clear_code.yaml.j2 index 55dbdf7..e0a1488 100644 --- a/custom_components/rental_control/templates/clear_code.yaml.j2 +++ b/custom_components/rental_control/templates/clear_code.yaml.j2 @@ -1,5 +1,6 @@ --- automation: + id: "{{ config_entry["unique_id"] }} - {{ NAME }} - Clear code slot {{ rc_name }}" alias: "{{ NAME }} - Clear code slot {{ rc_name }}" description: "" trigger: diff --git a/custom_components/rental_control/templates/set_code.yaml.j2 b/custom_components/rental_control/templates/set_code.yaml.j2 index ce03c88..a1185a7 100644 --- a/custom_components/rental_control/templates/set_code.yaml.j2 +++ b/custom_components/rental_control/templates/set_code.yaml.j2 @@ -1,5 +1,6 @@ --- automation: + id: "{{ config_entry["unique_id"] }} - {{ NAME }} - Set code {{ rc_name }}" alias: {{ NAME }} - Set Code {{ rc_name }} description: "" mode: queued diff --git a/custom_components/rental_control/templates/startup.yaml.j2 b/custom_components/rental_control/templates/startup.yaml.j2 index 79bfce0..a5b7f9a 100644 --- a/custom_components/rental_control/templates/startup.yaml.j2 +++ b/custom_components/rental_control/templates/startup.yaml.j2 @@ -1,5 +1,6 @@ --- automation: + id: "{{ config_entry["unique_id"] }} - {{ NAME }} - Update {{ rc_name }} - startup" alias: "{{ NAME }} - Update {{ rc_name }} - startup" description: "" trigger: diff --git a/custom_components/rental_control/templates/update.yaml.j2 b/custom_components/rental_control/templates/update.yaml.j2 index 8cd48a1..7a481a8 100644 --- a/custom_components/rental_control/templates/update.yaml.j2 +++ b/custom_components/rental_control/templates/update.yaml.j2 @@ -1,5 +1,6 @@ --- automation: + id: "{{ config_entry["unique_id"] }} - {{ NAME }} - Update {{ rc_name }}" alias: "{{ NAME }} - Update {{ rc_name }}" description: "" trigger: From 386aa5acb33b44ef63316d507c2db8ddb8b4ccbc Mon Sep 17 00:00:00 2001 From: Andrew Grimberg Date: Mon, 27 Feb 2023 12:25:31 -0800 Subject: [PATCH 2/2] Fix: Keep mapping sensor properly updated Issue: Fixes #154 Signed-off-by: Andrew Grimberg --- .../rental_control/sensors/mapsensor.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/custom_components/rental_control/sensors/mapsensor.py b/custom_components/rental_control/sensors/mapsensor.py index 3f916c8..8072b02 100644 --- a/custom_components/rental_control/sensors/mapsensor.py +++ b/custom_components/rental_control/sensors/mapsensor.py @@ -65,11 +65,7 @@ def entity_category(self) -> EntityCategory: @property def extra_state_attributes(self) -> dict: """Return the mapping attributes.""" - attrib = { - **self._mapping_attributes, - } - - return attrib + return self._mapping_attributes @property def icon(self) -> str: @@ -114,15 +110,22 @@ async def async_update(self): overrides = self.rental_control.event_overrides.copy() + _LOGGER.debug("Current event_overrides: %s", overrides) + _LOGGER.debug( + "Current mapping attributes: %s", self._mapping_attributes["mapping"] + ) + for override in overrides: - if override not in self._mapping_attributes["mapping"].values(): - _LOGGER.debug("%s is not in current mapping", override) - if "Slot " not in override: - self._mapping_attributes["mapping"][ - overrides[override]["slot"] - ] = override + if "Slot " not in override: + self._mapping_attributes["mapping"][ + overrides[override]["slot"] + ] = override else: - _LOGGER.debug("%s is in current mapping", override) + self._mapping_attributes["mapping"][overrides[override]["slot"]] = None + + _LOGGER.debug( + "Updated mapping attributes: %s", self._mapping_attributes["mapping"] + ) slots = filter(lambda k: ("Slot " in k), overrides) for event in get_event_names(self.rental_control):