-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add notification automation blueprint for due tasks #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
17
commits into
main
Choose a base branch
from
copilot/feat-create-blueprint-notification-automations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f59f8bf
Initial plan
Copilot f6086a3
feat: add notification automation blueprint for due tasks
Copilot 84f6bea
Fixed README.md
gensyn 2b161fd
Merge remote-tracking branch 'origin/copilot/feat-create-blueprint-no…
gensyn c8bd7a9
fix: register blueprints programmatically via async_setup so they app…
Copilot a777137
fix: always overwrite blueprints on setup and guard against missing b…
Copilot 636fbd1
Fixed notify selector
gensyn b2349c6
Add blueprint to dependencies
gensyn e7a3976
feat: add EN/DE translations to blueprint using mui technique
Copilot b32a6eb
Add French language support to notify_due_tasks blueprint
Copilot 13835fa
Finished blueprint
gensyn 4affaab
Fix unit tests: move blueprint import inside _async_register_blueprints
Copilot d4067b4
Cleaned up imports
gensyn 0ee0ece
Potential fix for pull request finding
gensyn afc84f4
Potential fix for pull request finding
gensyn e88ffd1
Potential fix for pull request finding
gensyn b5a55d6
test: cover blueprint registration and hoist imports
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| blueprint: | ||
| name: Task Tracker - Notify about due tasks | ||
| description: >- | ||
| Send a mobile app notification for each due task at a specified time each day. | ||
| Only tasks whose overdue_by value is a multiple of their notification_interval | ||
| will trigger a notification, preventing repeated daily alerts. | ||
|
|
||
| The notify action, tags, and language can be customised via the blueprint inputs. | ||
| domain: automation | ||
| input: | ||
|
gensyn marked this conversation as resolved.
|
||
| notification_time: | ||
| name: Notification time | ||
| description: Time of day to check for due tasks and send notifications. | ||
| default: "08:00:00" | ||
| selector: | ||
| time: {} | ||
| notify_action: | ||
| name: Notify action | ||
| description: The notify action to call (e.g. notify.mobile_app_my_phone). | ||
| selector: | ||
| text: {} | ||
| tags: | ||
| name: Tags | ||
| description: The tags that must be present in a task's tags attribute for the notification to be sent. | ||
| default: tag | ||
| selector: | ||
| text: {} | ||
| language: | ||
| name: Language | ||
| description: Language used for notification messages. | ||
| default: en | ||
| selector: | ||
| language: | ||
| languages: | ||
| - en | ||
| - de | ||
| - fr | ||
|
|
||
| triggers: | ||
| - trigger: time | ||
| at: !input notification_time | ||
|
|
||
| conditions: [] | ||
|
|
||
| actions: | ||
| - variables: | ||
| language_tmp: !input language | ||
| language: > | ||
| {{ | ||
| language_tmp | ||
| if language_tmp is string and language_tmp in ["de", "fr"] | ||
| else "en" | ||
| }} | ||
| mui: | ||
| en: | ||
| due_since_today: "due today" | ||
| due_since_yesterday: "due since yesterday" | ||
| due_since_days: "due since %d days" | ||
| de: | ||
| due_since_today: "heute fällig" | ||
| due_since_yesterday: "seit gestern fällig" | ||
| due_since_days: "seit %d Tagen fällig" | ||
| fr: | ||
| due_since_today: "à faire aujourd'hui" | ||
| due_since_yesterday: "dû depuis hier" | ||
| due_since_days: "dû depuis %d jours" | ||
| tasks: |- | ||
| {%- set ns = namespace(items=[]) -%} | ||
| {%- for entity_id in integration_entities('task_tracker') -%} | ||
| {%- if entity_id.startswith('sensor.') and states[entity_id].state == "due" -%} | ||
| {%- set overdue_by = states[entity_id].attributes.overdue_by if 'overdue_by' in states[entity_id].attributes else None -%} | ||
| {%- set notification_interval = states[entity_id].attributes.notification_interval if 'notification_interval' in states[entity_id].attributes else None -%} | ||
| {%- if overdue_by is not none and notification_interval is not none and (overdue_by % notification_interval == 0) -%} | ||
| {%- set ns.items = ns.items + [entity_id] -%} | ||
| {%- endif -%} | ||
| {%- endif -%} | ||
| {%- endfor -%} | ||
| {%- for item in ns.items -%} | ||
| - {{ item }} | ||
| {%- endfor -%} | ||
| - repeat: | ||
| for_each: "{{ tasks }}" | ||
| sequence: | ||
| - alias: Notify User | ||
| if: | ||
| - condition: template | ||
| value_template: "{{ configured_tags in states[repeat.item].attributes.tags }}" | ||
| then: | ||
| - action: !input notify_action | ||
| data: | ||
| title: "{{ states[repeat.item].attributes.friendly_name }}" | ||
| message: >- | ||
| {%- set overdue_by = states[repeat.item].attributes.overdue_by -%} | ||
| {%- if overdue_by == 0 -%} | ||
| {{ mui[language].due_since_today }} | ||
| {%- elif overdue_by == 1 -%} | ||
| {{ mui[language].due_since_yesterday }} | ||
| {%- else -%} | ||
| {{ mui[language].due_since_days | replace('%d', overdue_by | string) }} | ||
| {%- endif -%} | ||
| data: | ||
| tag: "{{ repeat.item }}" | ||
| color: green | ||
| group: "{{ repeat.item }}" | ||
| notification_icon: "{{ states[repeat.item].attributes.icon }}" | ||
|
|
||
| mode: single | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
2 changes: 2 additions & 0 deletions
2
tests/unit_tests/homeassistant_mock/homeassistant/components/automation/helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def async_get_blueprints(hass): | ||
| return getattr(hass, "automation_blueprints", None) |
6 changes: 6 additions & 0 deletions
6
tests/unit_tests/homeassistant_mock/homeassistant/components/blueprint/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class Blueprint: | ||
| def __init__(self, data, expected_domain, path, schema): | ||
| self.data = data | ||
| self.expected_domain = expected_domain | ||
| self.path = path | ||
| self.schema = schema |
1 change: 1 addition & 0 deletions
1
tests/unit_tests/homeassistant_mock/homeassistant/components/blueprint/const.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| BLUEPRINT_FOLDER = "blueprints" |
2 changes: 2 additions & 0 deletions
2
tests/unit_tests/homeassistant_mock/homeassistant/util/yaml.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def load_yaml_dict(path): | ||
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please move the imports from
_async_register_blueprints(hass: HomeAssistant)to the top and instead add unit test coverage for the function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in
b5a55d6. I moved the_async_register_blueprintsimports to module top-level and added unit test coverage for_async_register_blueprintssuccess and failure paths intests/unit_tests/test_init.py.