Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions custom_components/tronbytassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@

from .const import (
ATTR_ARGS,
ATTR_BACKGROUND_COLOR,
ATTR_COALESCE_ID,
ATTR_COLOR,
ATTR_CONTENT,
ATTR_CONTENT_ID,
ATTR_CONT_TYPE,
ATTR_CUSTOM_CONT,
ATTR_DEVICENANME,
ATTR_DEVICE_IDS,
ATTR_EMOJI,
ATTR_FONT,
ATTR_PUBLISH_TYPE,
ATTR_TEXT_TYPE,
Expand All @@ -43,8 +46,6 @@
CONF_VERIFY_SSL,
DATA_COORDINATOR,
DOMAIN,
ATTR_BACKGROUND_COLOR,
ATTR_EMOJI,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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."
)
Comment thread
IngmarStein marked this conversation as resolved.
Resolved

arguments: dict[str, Any] = {}
if is_text:
title = call.data.get(ATTR_TITLE_CONTENT)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions custom_components/tronbytassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
ATTR_EMOJI = "emoji"
ATTR_ARGS = "arguments"
ATTR_PUBLISH_TYPE = "publishtype"
ATTR_COALESCE_ID = "coalesce_id"
DATA_COORDINATOR = "coordinator"
6 changes: 6 additions & 0 deletions custom_components/tronbytassistant/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -197,6 +202,7 @@ text:
- label: Title & Text
value: title
contentid: *contentid
coalesce_id: *coalesce_id
publishtype: *publishtype
delete:
name: Delete
Expand Down
Loading