Skip to content

Commit

Permalink
add target to notify service
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasJoKuJonas committed Jan 9, 2024
1 parent a98c475 commit fd7a696
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/webuntis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def __init__(
self.notify_entity_id = config.options["notify_entity_id"]
self.notify_list = config.options["notify_options"]
self.notify = bool(self.notify_entity_id) and bool(self.notify_list)
self.notify_data = config.options["notify_data"]
self.notify_target = config.options.get("notify_target")
self.notify_data = config.options.get("notify_data")

# pylint: disable=maybe-no-member
self.session = webuntis.Session(
Expand Down Expand Up @@ -922,6 +923,7 @@ async def update_notify(self):

for notification in notifications:
if self.notify_data:
notification["target"] = self.notify_target
notification["data"] = self.notify_data
try:
await self.async_notify(
Expand Down
8 changes: 8 additions & 0 deletions custom_components/webuntis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ async def async_step_notify(
errors = {"base": "unknown_service"}
else:
user_input["notify_entity_id"] = ""
if "notify_target" not in user_input:
user_input["notify_target"] = {}
if "notify_data" not in user_input:
user_input["notify_data"] = {}
return await self.save(user_input)
Expand All @@ -478,6 +480,12 @@ async def async_step_notify(
"suggested_value": self.config_entry.options.get("notify_entity_id")
},
): selector.TextSelector(),
vol.Optional(
"notify_target",
description={
"suggested_value": self.config_entry.options.get("notify_target")
},
): selector.ObjectSelector(),
vol.Optional(
"notify_data",
description={
Expand Down
1 change: 1 addition & 0 deletions custom_components/webuntis/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"description": "Einstellungen für Benachrichtigungen",
"data": {
"notify_entity_id": "Notify-Service-ID (Bsp: notify.discord)",
"notify_target": "Plattformspezifische Targetdaten",
"notify_data": "Plattformspezifische Benachrichtigungsdaten",
"code": "Stunden-Status ändert sich",
"rooms": "Raum ändert sich",
Expand Down
1 change: 1 addition & 0 deletions custom_components/webuntis/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"description": "Notification Settings",
"data": {
"notify_entity_id": "Notify Service ID (e.g., notify.discord)",
"notify_target": "Platform-Specific Target Data",
"notify_data": "Platform-Specific Notification Data",
"code": "Lesson status changed",
"rooms": "Room changed",
Expand Down

0 comments on commit fd7a696

Please sign in to comment.