From cb71c55f349f498235aa9fa6b8da77112dc73ae1 Mon Sep 17 00:00:00 2001 From: Ingmar Stein <490610+IngmarStein@users.noreply.github.com> Date: Sun, 7 Jun 2026 23:09:01 +0200 Subject: [PATCH 1/2] feat: add coalesce_id support for push and text services (#830) --- .../tronbytassistant/__init__.py | 21 +++++++++++++++++-- custom_components/tronbytassistant/const.py | 1 + .../tronbytassistant/services.yaml | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/custom_components/tronbytassistant/__init__.py b/custom_components/tronbytassistant/__init__.py index 9376c1b..b77ca0c 100644 --- a/custom_components/tronbytassistant/__init__.py +++ b/custom_components/tronbytassistant/__init__.py @@ -25,6 +25,8 @@ from .const import ( ATTR_ARGS, + ATTR_BACKGROUND_COLOR, + ATTR_COALESCE_ID, ATTR_COLOR, ATTR_CONTENT, ATTR_CONTENT_ID, @@ -32,6 +34,7 @@ ATTR_CUSTOM_CONT, ATTR_DEVICENANME, ATTR_DEVICE_IDS, + ATTR_EMOJI, ATTR_FONT, ATTR_PUBLISH_TYPE, ATTR_TEXT_TYPE, @@ -43,8 +46,6 @@ CONF_VERIFY_SSL, DATA_COORDINATOR, DOMAIN, - ATTR_BACKGROUND_COLOR, - ATTR_EMOJI, ) _LOGGER = logging.getLogger(__name__) @@ -238,6 +239,13 @@ def validateid(input_value: str) -> bool: pattern = r"^[A-Za-z0-9]+$" return bool(re.match(pattern, input_value)) + def validate_coalesce_id(input_value: str) -> bool: + """Check if the coalesce ID is valid (alphanumeric, underscore, dash, max 64 chars).""" + if len(input_value) > 64: + return False + pattern = r"^[A-Za-z0-9_-]+$" + return bool(re.match(pattern, input_value)) + async def request( method: str, webhook_url: str, @@ -295,9 +303,16 @@ def _normalize_color(value: Any | None, field: str) -> str | None: async def handle_push_or_text(call: ServiceCall, is_text: bool) -> None: contentid = call.data.get(ATTR_CONTENT_ID) + coalesce_id = call.data.get(ATTR_COALESCE_ID) publishtype = call.data.get(ATTR_PUBLISH_TYPE, DEFAULT_PUBLISH_TYPE) targets = _resolve_devices(call) + if coalesce_id and not validate_coalesce_id(coalesce_id): + raise HomeAssistantError( + "Coalesce ID must be at most 64 characters and contain only " + "letters, numbers, underscores, or dashes." + ) + arguments: dict[str, Any] = {} if is_text: title = call.data.get(ATTR_TITLE_CONTENT) @@ -356,6 +371,8 @@ async def handle_push_or_text(call: ServiceCall, is_text: bool) -> None: "app_id": content, "installationID": contentid, } + if coalesce_id: + body["coalesceID"] = coalesce_id if publishtype: body["publish"] = publishtype await request("POST", api_url, body) diff --git a/custom_components/tronbytassistant/const.py b/custom_components/tronbytassistant/const.py index 43d213d..97cf455 100644 --- a/custom_components/tronbytassistant/const.py +++ b/custom_components/tronbytassistant/const.py @@ -19,4 +19,5 @@ ATTR_EMOJI = "emoji" ATTR_ARGS = "arguments" ATTR_PUBLISH_TYPE = "publishtype" +ATTR_COALESCE_ID = "coalesce_id" DATA_COORDINATOR = "coordinator" diff --git a/custom_components/tronbytassistant/services.yaml b/custom_components/tronbytassistant/services.yaml index cec2b8b..410e5d4 100644 --- a/custom_components/tronbytassistant/services.yaml +++ b/custom_components/tronbytassistant/services.yaml @@ -84,6 +84,11 @@ push: description: The Content ID you set when publishing your app. Specifying this adds the app to the rotation. selector: text: {} + coalesce_id: &coalesce_id + name: Coalesce ID + description: An optional identifier to deduplicate anonymous pushes. When set, only the most recent push with this ID is kept — older pushes are replaced. Max 64 chars, alphanumeric, underscores, and dashes only. + selector: + text: {} publishtype: &publishtype name: Publish Type description: How you want content published. Background publishes without replacing the current app and Foreground will publish and also show you the app instantly. @@ -197,6 +202,7 @@ text: - label: Title & Text value: title contentid: *contentid + coalesce_id: *coalesce_id publishtype: *publishtype delete: name: Delete From 3940ed4314289e943a9ee202d0bd2b19d771d05a Mon Sep 17 00:00:00 2001 From: Ingmar Stein <490610+IngmarStein@users.noreply.github.com> Date: Sun, 7 Jun 2026 23:11:55 +0200 Subject: [PATCH 2/2] fix: coerce coalesce_id to string before validation --- custom_components/tronbytassistant/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/custom_components/tronbytassistant/__init__.py b/custom_components/tronbytassistant/__init__.py index b77ca0c..8e4961e 100644 --- a/custom_components/tronbytassistant/__init__.py +++ b/custom_components/tronbytassistant/__init__.py @@ -307,11 +307,13 @@ async def handle_push_or_text(call: ServiceCall, is_text: bool) -> None: publishtype = call.data.get(ATTR_PUBLISH_TYPE, DEFAULT_PUBLISH_TYPE) targets = _resolve_devices(call) - if coalesce_id and not validate_coalesce_id(coalesce_id): - raise HomeAssistantError( - "Coalesce ID must be at most 64 characters and contain only " - "letters, numbers, underscores, or dashes." - ) + if coalesce_id: + coalesce_id = str(coalesce_id) + if not validate_coalesce_id(coalesce_id): + raise HomeAssistantError( + "Coalesce ID must be at most 64 characters and contain only " + "letters, numbers, underscores, or dashes." + ) arguments: dict[str, Any] = {} if is_text: