Skip to content
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

Telegram support #18

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Telegram support #18

wants to merge 6 commits into from

Conversation

edwardtfn
Copy link
Owner

@edwardtfn edwardtfn commented Jan 17, 2025

Resolves #11
Resolves #15
Resolves #17

Summary by CodeRabbit

  • New Features

    • Enhanced Home Assistant auto-update blueprint with more granular update controls.
    • Added new input fields for update scheduling and entity selection, including schedule_monthday_last, update_inclusion_mode, update_inclusion_entity_list, and update_inclusion_entity_searchfilter.
    • Introduced advanced backup and timeout configuration options, including backup_location and update_timeout.
    • Implemented detailed Telegram notifications for various stages of the update process.
  • Improvements

    • Refined update logic and scheduling mechanisms.
    • Enhanced user control over update inclusion and timing.
    • Improved backup and update process checks.
  • Version

    • Updated to v2025.1.0.

Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request modifies the Home Assistant auto-update scheduled blueprint, introducing significant enhancements to update automation. The changes include new input fields for more granular control over update scheduling, backup processes, and entity selection. The blueprint now supports more flexible update windows, allows specific entity inclusion modes, and provides improved logging and notification mechanisms. The version has been updated to reflect these substantial modifications.

Changes

File Change Summary
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml - Updated version to v2025.1.0
- Added new input fields: schedule_monthday_last, update_inclusion_mode, update_inclusion_entity_list, update_inclusion_entity_searchfilter, backup_location, update_process_started_entity, update_timeout
- Renamed fields: schedule_monthdayschedule_monthday_earliest, backup_wait_timebackup_timeout
- Enhanced Telegram notifications for update stages
- Improved backup and update logic with more robust conditions
- Added timeout settings and checks for existing backups

Assessment against linked issues

Objective Addressed Explanation
Inform about 1h delay after backup [#11]
Resolve 'pending_update_list' undefined error [#15] Requires further testing to confirm complete resolution
Limit updates to specific entities [#17] New update_inclusion_mode and related fields provide granular control

Poem

🐰 Updating Home Assistant, oh what a delight!
With blueprints so smart, everything's just right
Schedules and backups, now crystal clear
No more update chaos, success is here!
Hop, hop, hooray for automation's might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (4)

391-400: Add validation for Telegram target ID.

The Telegram target ID input should include validation to ensure it's a valid numeric value. Consider adding a pattern validator.

          selector:
            text:
+             pattern: "^-?\\d+$"
+             type: number

283-294: Consider reducing the maximum backup timeout.

The maximum backup timeout of 600 minutes (10 hours) seems excessive and could lead to very long automation runs. Consider reducing this to a more reasonable value, such as 180 minutes (3 hours).

              max: 600
+             max: 180
              unit_of_measurement: minutes

573-582: Simplify the monthday scheduling logic.

The monthday scheduling logic is complex and could be simplified for better maintainability. Consider extracting the template into a reusable macro.

    value_template: >
+     {%- macro is_valid_update_day() -%}
      {{
        (now().day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0) and
        (
          now().day <= input_schedule_monthday_last or
          input_schedule_monthday_last == 0 or
          input_schedule_monthday_last < input_schedule_monthday_earliest
        )
      }}
+     {%- endmacro -%}
+     {{ is_valid_update_day() }}

842-855: Improve Telegram message formatting.

The Telegram messages could be better formatted using Markdown for improved readability.

                data:
                  title: '{{ telegram_title }}'
                  target: "{{ input_notification_telegram_target_id }}"
                  disable_notification: '{{ input_notification_telegram_disable_notification }}'
+                 parse_mode: "MarkdownV2"
+                 message: '*{{ telegram_title }}*\n\n{{ log_message | replace(".", "\\.") | replace("-", "\\-") | replace("_", "\\_") }}'
-                 message: '{{ log_message }}'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0920fd6 and 0f84503.

📒 Files selected for processing (1)
  • blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (13 hunks)
🔇 Additional comments (2)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (2)

Line range hint 1-1526: Great implementation of Telegram notifications!

The overall implementation of Telegram notifications is well-structured and comprehensive. The code:

  • Provides flexible configuration options
  • Allows selective notification of different update stages
  • Includes proper error handling
  • Maintains good separation of concerns

34-34: Version number indicates a future date.

The version number v2025.1.0 appears to use a future date. Consider using the current year (2024) for the version number.

Comment on lines 514 to 537
update_timeout:
name: Update Timeout
description: |
Maximum time to wait for each update to complete.

This protects the automation of waiting forever for an update that fails.

Usually updates don't take that very long,
so feel free to ajust this time to something that fits better your environment.

The default is 600 seconds (10 minutes).
You can select any value between 10 seconds and 7200 seconds (2 hours).

If an update times out:
- The automation will log an error message
- The automation will continue with the next update
- The timed-out update may still complete in the background
default: 600
selector:
number:
min: 10
max: 7200
step: 10
unit_of_measurement: seconds
Copy link

@coderabbitai coderabbitai bot Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Increase the default update timeout.

The default update timeout of 600 seconds (10 minutes) might be too short for some updates, especially for core updates or large addons. Consider increasing the default to 20 minutes while keeping the range configurable.

          default: 600
+         default: 1200
          selector:
            number:
              min: 10
              max: 7200
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
update_timeout:
name: Update Timeout
description: |
Maximum time to wait for each update to complete.
This protects the automation of waiting forever for an update that fails.
Usually updates don't take that very long,
so feel free to ajust this time to something that fits better your environment.
The default is 600 seconds (10 minutes).
You can select any value between 10 seconds and 7200 seconds (2 hours).
If an update times out:
- The automation will log an error message
- The automation will continue with the next update
- The timed-out update may still complete in the background
default: 600
selector:
number:
min: 10
max: 7200
step: 10
unit_of_measurement: seconds
update_timeout:
name: Update Timeout
description: |
Maximum time to wait for each update to complete.
This protects the automation of waiting forever for an update that fails.
Usually updates don't take that very long,
so feel free to ajust this time to something that fits better your environment.
The default is 600 seconds (10 minutes).
You can select any value between 10 seconds and 7200 seconds (2 hours).
If an update times out:
- The automation will log an error message
- The automation will continue with the next update
- The timed-out update may still complete in the background
default: 1200
selector:
number:
min: 10
max: 7200
step: 10
unit_of_measurement: seconds

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented this locally and it will be included in the next commit.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edwardtfn Thanks for implementing the change! Looking forward to seeing it in the next commit.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Comment on lines 1037 to 1182
value_template: >
{{ ( states.update
| selectattr('state', 'eq', 'on')
| selectattr('entity_id', 'in', pending_update_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| selectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Core - Logbook - Updating"
continue_on_error: true
action: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Updating {{pending_update_list[0]}} of {{pending_update_list}} ..."
- alias: "Update - Core - Install"
continue_on_error: true
action: update.install
data: {}
target:
entity_id: '{{ pending_update_list[0] }}'
- alias: "Update - Core - Wait"
continue_on_error: true
wait_template: "{{ is_state(pending_update_list[0], 'off') }}"
continue_on_timeout: true
timeout: '3600'

########## Update OS ##########
- *recalc_update_list
- *logbook-variables
- alias: "Update - OS"
continue_on_error: true
repeat:
while:
- "{{ input_core_os_update_mode in ['patches', 'major_and_minor', 'all'] }}"
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: template
value_template: >
{{ ( states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', pending_updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| selectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
sequence:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - OS - Logbook - Starting"
continue_on_error: true
action: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Starting sequence of OS update..."
- variables:
pending_update_list: >
{{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', pending_updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| selectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list
sequence:
- variables:
log_message: "Starting sequence of Devices firmware update"
- *logbook_update
- if: '{{ "update_progress" in input_notification_telegram_select_notifications }}'
then:
- *send_telegram_message

- variables:
pending_update_list: >
{{ states.update
| selectattr('state', 'eq', 'on')
| selectattr('entity_id', 'in', pending_update_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| selectattr('entity_id', 'in', firmware_update_entities)
| map(attribute='entity_id')
| list
}}

- *log_updating
- *update_install
- *update_wait

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add retry mechanism for failed updates.

The update process doesn't handle transient failures well. Consider adding a retry mechanism with exponential backoff for failed updates.

  - alias: Update generic
    if:
      - '{{ is_there_anything_to_update }}'
      - condition: state
        entity_id: !input schedule_entity
        state: 'on'
    then:
      - *recalc_update_list
+     - variables:
+         max_retries: 3
+         retry_delay: 30
      - variables:
          log_message: "Update generic items"
      - *logbook_update
      - alias: "Update - Generic"
        continue_on_error: true
        repeat:
          while:
            - "{{ input_general_update_mode in ['patches', 'major_and_minor', 'all'] }}"
            - condition: state
              entity_id: !input schedule_entity
              state: "on"
+           - condition: template
+             value_template: "{{ max_retries > 0 }}"

Committable suggestion skipped: line range outside the PR's diff.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (3)

34-34: Adjust version number to match current date.

The version number v2025.1.0 uses a future date. Consider using the current year and month (v2024.1.0) to maintain consistency with semantic versioning practices.

-    ## v2025.1.0
+    ## v2024.1.0

283-294: Consider reducing the default backup timeout.

The default backup timeout of 60 minutes might be excessive for most installations. Consider reducing it to 30 minutes while keeping the range configurable. This would help prevent unnecessarily long waits when backups complete faster.

-          default: 60
+          default: 30
           selector:
             number:
               mode: box
               min: 1
               max: 180
               unit_of_measurement: minutes

Line range hint 1-1504: Well-structured implementation with room for improvement.

The blueprint successfully implements Telegram support with comprehensive notification options. The code is well-documented and includes proper error handling. However, consider addressing the following architectural points:

  1. Add proper synchronization between update and restart processes
  2. Implement stronger backup verification
  3. Add input validation for critical fields
  4. Adjust timeouts for better user experience
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f84503 and 676c1e0.

📒 Files selected for processing (1)
  • blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (13 hunks)
🔇 Additional comments (2)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (2)

1277-1322: ⚠️ Potential issue

Potential race condition in update process.

The "Update - Remaining" sequence might conflict with the restart process if updates complete right after the check but before the restart. Consider adding a small delay or implementing a proper synchronization mechanism.


950-987: Enhance backup verification process.

The backup verification only checks the backup state and age but doesn't verify the backup's integrity or accessibility. Consider adding additional checks:

  1. Verify backup file exists at the specified location
  2. Check backup file size is non-zero
  3. Validate backup file format

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (1)

995-1024: Enhance backup error handling.

The backup process could benefit from additional error handling:

  1. The backup service call is marked with continue_on_error: true but there's no explicit error capture
  2. The automation relies solely on a timeout to determine if the backup completed

Consider adding:

  1. Error state checking after the backup service call
  2. Backup size verification
  3. Backup integrity check if available through the API

Example enhancement:

 - alias: "Call backup service"
   action: hassio.backup_full
   data:
     compressed: true
   continue_on_error: true
+  response_variable: backup_result
+
+- if: "{{ backup_result is defined and backup_result.success }}"
+  then:
+    - variables:
+        log_message: "Backup completed successfully"
+  else:
+    - variables:
+        log_message: "Backup failed or status unknown"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 676c1e0 and 1acda2f.

📒 Files selected for processing (1)
  • blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (13 hunks)
🧰 Additional context used
📓 Learnings (1)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (1)
Learnt from: edwardtfn
PR: edwardtfn/HomeAssistant-Config#18
File: blueprints/automation/EdwardTFN/auto_update_scheduled.yaml:391-402
Timestamp: 2025-01-21T10:50:12.444Z
Learning: Home Assistant YAML selectors do not support the `pattern` attribute for text input validation.
🪛 yamllint (1.35.1)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml

[error] 784-784: trailing spaces

(trailing-spaces)


[error] 797-797: trailing spaces

(trailing-spaces)


[error] 801-801: trailing spaces

(trailing-spaces)


[error] 802-802: trailing spaces

(trailing-spaces)

🪛 GitHub Check: Validate YAML
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml

[failure] 784-784:
784:78 [trailing-spaces] trailing spaces


[failure] 797-797:
797:1 [trailing-spaces] trailing spaces


[failure] 801-801:
801:43 [trailing-spaces] trailing spaces


[failure] 802-802:
802:56 [trailing-spaces] trailing spaces

🪛 GitHub Actions: Validate Blueprint YAML
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml

[error] 784-784: Trailing spaces detected at position 78

🔇 Additional comments (4)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (4)

Line range hint 1-54: Well-documented header with comprehensive information!

The documentation clearly outlines the purpose, risks, and security considerations of auto-updates. The inclusion of community discussion links and support channels is particularly helpful.


391-402: Consider adding input validation for Telegram chat ID.

The Telegram chat ID input field could benefit from validation to ensure it matches the expected format (negative numbers for groups, positive for users).

Note: This suggestion was previously made and the user clarified that Home Assistant YAML selectors do not support the pattern attribute for text input validation.


516-541: Consider increasing the default update timeout.

While the current default of 1200 seconds (20 minutes) is reasonable for most updates, some updates (especially core updates or large addons) might need more time. Consider increasing the default while keeping the range configurable.

Note: This suggestion was previously made and the user confirmed it will be implemented in the next commit.


1025-1167: Consider implementing retry mechanism for failed updates.

The update process doesn't handle transient failures well. Consider adding a retry mechanism with exponential backoff for failed updates.

Note: This suggestion was previously made in a past review.

{% endif %}
combined_list: >-
{% set entities = namespace(list=[]) %}
{%- for entity in [firmware_update_entities, general_update_entities,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove trailing spaces.

There are trailing spaces in the following lines that should be removed to maintain consistent formatting:

  • Line 784: After the comma in the list comprehension
  • Line 797: Empty line with spaces
  • Lines 801-802: After conditions in the if statement
-                          core_update_entity, os_update_entity, supervisor_update_entity] %}
+                          core_update_entity, os_update_entity, supervisor_update_entity] %}
-      
+
-          {%- if (entity.state == "on" and 
-                  entity.entity_id in combined_list and 
+          {%- if (entity.state == "on" and
+                  entity.entity_id in combined_list and

Also applies to: 797-797, 801-802

🧰 Tools
🪛 yamllint (1.35.1)

[error] 784-784: trailing spaces

(trailing-spaces)

🪛 GitHub Check: Validate YAML

[failure] 784-784:
784:78 [trailing-spaces] trailing spaces

🪛 GitHub Actions: Validate Blueprint YAML

[error] 784-784: Trailing spaces detected at position 78

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (4)

14-17: Enhance security warnings section.

Consider adding these important security considerations:

  • Risk of breaking changes in major version updates
  • Importance of testing updates in a development environment first
  • Network connectivity requirements during updates
 ##### - SECURITY WARNING:                                                                      #####
 #####   - Ensure you have reliable backups before enabling automatic updates                   #####
 #####   - Auto-updates in production environments may lead to system instability               #####
 #####   - Updates may affect connected devices and integrations                                #####
+#####   - Major version updates may contain breaking changes                                   #####
+#####   - Test updates in a development environment when possible                              #####
+#####   - Ensure stable network connectivity during updates                                    #####

204-235: Add descriptions for update mode implications.

The update inclusion mode selector would benefit from additional descriptions about the implications of each mode, particularly regarding system stability and performance.

           description: >-
             Please select the entity inclusion mode.
             * All:
-              Just build the update entity list from all available update.* entities, which are in state 'on'.
+              Just build the update entity list from all available update.* entities, which are in state 'on'.
+              Note: This mode may impact system performance if many updates are available simultaneously.
             * Specified/Specified-Single:
               Build the update entity list from the specified entity list, filtering for entities in 'on' state.
               - Specified: Updates all matching entities
               - Specified-Single: Updates only the first matching entity
+              Note: Recommended for controlled, selective updates of critical components.

590-599: Optimize trigger template for better readability.

The trigger template for new day validation could be simplified for better maintainability.

-      {{
-        (now().day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0) and
-        (
-          now().day <= input_schedule_monthday_last or
-          input_schedule_monthday_last == 0 or
-          input_schedule_monthday_last < input_schedule_monthday_earliest
-        )
-      }}
+      {% set current_day = now().day %}
+      {% set is_after_earliest = current_day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0 %}
+      {% set is_before_last = current_day <= input_schedule_monthday_last or input_schedule_monthday_last == 0 %}
+      {% set is_valid_range = input_schedule_monthday_last < input_schedule_monthday_earliest %}
+      {{ is_after_earliest and (is_before_last or is_valid_range) }}

509-513: Add monitoring capabilities for update statistics.

Consider adding input options for monitoring update success rates and timing statistics.

       verbose_logging_bool:
         name: Log addon progress with verbosity to the logbook? (optional)
         default: false
         selector:
           boolean: {}
+      update_statistics_sensor:
+        name: Statistics Helper Sensor (optional)
+        description: >
+          Select a helper sensor to store update statistics like success rates,
+          average update duration, and failure counts.
+        default: []
+        selector:
+          entity:
+            domain: sensor
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1acda2f and e6374df.

📒 Files selected for processing (1)
  • blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (13 hunks)
🧰 Additional context used
📓 Learnings (1)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (1)
Learnt from: edwardtfn
PR: edwardtfn/HomeAssistant-Config#18
File: blueprints/automation/EdwardTFN/auto_update_scheduled.yaml:391-402
Timestamp: 2025-01-21T10:50:12.444Z
Learning: Home Assistant YAML selectors do not support the `pattern` attribute for text input validation.
🔇 Additional comments (2)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (2)

1101-1108: 🛠️ Refactor suggestion

Add retry mechanism for failed updates.

The update installation sequence should include a retry mechanism for transient failures.

       alias: "Update - Install"
       continue_on_error: true
+      variables:
+        max_retries: 3
+        retry_delay: 30
+        current_try: 1
+      repeat:
+        sequence:
+          - if: "{{ current_try > 1 }}"
+            then:
+              - delay:
+                  seconds: "{{ retry_delay * (current_try - 1) }}"
+          - service: update.install
+            data: {}
+            target:
+              entity_id: '{{ current_update_entity }}'
+        until: "{{ is_state(current_update_entity, 'off') or current_try > max_retries }}"
+        repeat:
+          variable: current_try
+          in: "{{ range(1, max_retries + 1) | list }}"
-      action: update.install
-      data: {}
-      target:
-        entity_id: '{{ current_update_entity }}'

Likely invalid or redundant comment.


283-294: Validate backup timeout against system resources.

The backup timeout should consider system resources and backup size. The current maximum of 180 minutes might be insufficient for large systems.

Comment on lines +847 to +860
- &send_telegram_message
alias: Send telegram message
if:
- condition: template
value_template: '{{ input_notification_telegram_enable }}'
alias: Check if telegram notifications are enabled
then:
- alias: Telegram bot - Send message
action: telegram_bot.send_message
data:
title: '{{ telegram_title }}'
target: '{{ input_notification_telegram_target_id }}'
disable_notification: '{{ input_notification_telegram_disable_notification }}'
message: '{{ log_message }}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for Telegram notifications.

The Telegram message sending sequence should include error handling and retry logic.

       alias: Send telegram message
       if:
         - condition: template
           value_template: '{{ input_notification_telegram_enable }}'
           alias: Check if telegram notifications are enabled
       then:
+        - variables:
+            max_retries: 3
+            retry_delay: 5
+        - repeat:
+            sequence:
               - alias: Telegram bot - Send message
                 action: telegram_bot.send_message
+                continue_on_error: true
                 data:
                   title: '{{ telegram_title }}'
                   target: '{{ input_notification_telegram_target_id }}'
                   disable_notification: '{{ input_notification_telegram_disable_notification }}'
                   message: '{{ log_message }}'
+            until: "{{ repeat.index >= max_retries or not repeat.failed }}"
+            delay:
+              seconds: "{{ retry_delay }}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- &send_telegram_message
alias: Send telegram message
if:
- condition: template
value_template: '{{ input_notification_telegram_enable }}'
alias: Check if telegram notifications are enabled
then:
- alias: Telegram bot - Send message
action: telegram_bot.send_message
data:
title: '{{ telegram_title }}'
target: '{{ input_notification_telegram_target_id }}'
disable_notification: '{{ input_notification_telegram_disable_notification }}'
message: '{{ log_message }}'
- &send_telegram_message
alias: Send telegram message
if:
- condition: template
value_template: '{{ input_notification_telegram_enable }}'
alias: Check if telegram notifications are enabled
then:
- variables:
max_retries: 3
retry_delay: 5
- repeat:
sequence:
- alias: Telegram bot - Send message
action: telegram_bot.send_message
continue_on_error: true
data:
title: '{{ telegram_title }}'
target: '{{ input_notification_telegram_target_id }}'
disable_notification: '{{ input_notification_telegram_disable_notification }}'
message: '{{ log_message }}'
until: "{{ repeat.index >= max_retries or not repeat.failed }}"
delay:
seconds: "{{ retry_delay }}"

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (3)

34-34: Consider adding a changelog section.

Adding a changelog section would help users track changes between versions and understand what's new in v2025.1.0.

    ## v2025.1.0
+
+   ### Changelog
+   - Added Telegram notification support
+   - Enhanced backup functionality with timeout controls
+   - Added entity inclusion modes for more granular update control
+   - Improved update scheduling with earliest/latest day settings

283-294: Consider increasing the default backup timeout.

The default backup timeout of 60 minutes might not be sufficient for systems with large amounts of data or slow storage. Consider increasing the default value to 120 minutes while keeping the range configurable.

-          default: 60
+          default: 120

531-555: Add a warning about core update timeouts.

The update timeout description should include a warning that core updates might take longer than other updates, especially on slower systems or during major version upgrades.

            The default is 1200 seconds (20 minutes).
            You can select any value between 10 seconds and 7200 seconds (2 hours).

+           Note: Core updates might take longer than other updates, especially during major version upgrades.
+           Consider using a higher timeout value if you experience timeout issues with core updates.
+
            If an update times out:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6374df and d7d9fbd.

📒 Files selected for processing (1)
  • blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (13 hunks)
🧰 Additional context used
📓 Learnings (1)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (1)
Learnt from: edwardtfn
PR: edwardtfn/HomeAssistant-Config#18
File: blueprints/automation/EdwardTFN/auto_update_scheduled.yaml:391-402
Timestamp: 2025-01-21T10:50:12.444Z
Learning: Home Assistant YAML selectors do not support the `pattern` attribute for text input validation.
🔇 Additional comments (3)
blueprints/automation/EdwardTFN/auto_update_scheduled.yaml (3)

1102-1109: 🛠️ Refactor suggestion

Add retry mechanism for failed updates.

The update installation process doesn't handle transient failures. Consider adding a retry mechanism with exponential backoff.

       alias: "Update - Install"
       continue_on_error: true
+      variables:
+        max_retries: 3
+        retry_delay: 30
+      repeat:
+        sequence:
           action: update.install
           data: {}
           target:
             entity_id: '{{ current_update_entity }}'
+        until: "{{ repeat.index >= max_retries or not repeat.failed }}"
+        delay:
+          seconds: "{{ retry_delay * (2 ^ (repeat.index - 1)) }}"

Likely invalid or redundant comment.


847-860: 🛠️ Refactor suggestion

Enhance Telegram notification error handling.

The Telegram message sending sequence should include error handling and retry logic to handle temporary network issues.

       alias: Send telegram message
       if:
         - condition: template
           value_template: '{{ input_notification_telegram_enable }}'
           alias: Check if telegram notifications are enabled
       then:
+        - variables:
+            max_retries: 3
+            retry_delay: 5
+        - repeat:
+            sequence:
               - alias: Telegram bot - Send message
                 action: telegram_bot.send_message
+                continue_on_error: true
                 data:
                   title: '{{ telegram_title }}'
                   target: '{{ input_notification_telegram_target_id }}'
                   disable_notification: '{{ input_notification_telegram_disable_notification }}'
                   message: '{{ log_message }}'
+            until: "{{ repeat.index >= max_retries or not repeat.failed }}"
+            delay:
+              seconds: "{{ retry_delay }}"

Likely invalid or redundant comment.


314-323: Add validation for backup location.

The backup location input should validate that the path exists and is writable before starting the backup process.

Comment on lines +590 to +599
platform: template
value_template: >
{{
(now().day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0) and
(
now().day <= input_schedule_monthday_last or
input_schedule_monthday_last == 0 or
input_schedule_monthday_last < input_schedule_monthday_earliest
)
}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify the day comparison logic.

The day comparison logic is complex and could be simplified. Also, there's a potential issue with month boundaries where the logic might not work correctly when the earliest day is near the end of one month and the latest day is in the beginning of the next month.

-      {{
-        (now().day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0) and
-        (
-          now().day <= input_schedule_monthday_last or
-          input_schedule_monthday_last == 0 or
-          input_schedule_monthday_last < input_schedule_monthday_earliest
-        )
-      }}
+      {% set current_day = now().day %}
+      {% set earliest = input_schedule_monthday_earliest | int(0) %}
+      {% set latest = input_schedule_monthday_last | int(0) %}
+      {{
+        (earliest == 0 or current_day >= earliest) and
+        (latest == 0 or current_day <= latest or latest < earliest)
+      }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
platform: template
value_template: >
{{
(now().day >= input_schedule_monthday_earliest or input_schedule_monthday_earliest == 0) and
(
now().day <= input_schedule_monthday_last or
input_schedule_monthday_last == 0 or
input_schedule_monthday_last < input_schedule_monthday_earliest
)
}}
platform: template
value_template: >
{% set current_day = now().day %}
{% set earliest = input_schedule_monthday_earliest | int(0) %}
{% set latest = input_schedule_monthday_last | int(0) %}
{{
(earliest == 0 or current_day >= earliest) and
(latest == 0 or current_day <= latest or latest < earliest)
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant