Skip to content

Add support for FRITZ! Smarthome routines#158947

Merged
zweckj merged 7 commits into
devfrom
fritzbox/add-support-for-routines
Dec 18, 2025
Merged

Add support for FRITZ! Smarthome routines#158947
zweckj merged 7 commits into
devfrom
fritzbox/add-support-for-routines

Conversation

@mib1185
Copy link
Copy Markdown
Member

@mib1185 mib1185 commented Dec 13, 2025

Proposed change

This adds switch entities for so called FRITZ! smarthome routines (technically called triggers) to allow the activation and deactivation of those.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @flabbamann, mind taking a look at this pull request as it has been labeled with an integration (fritzbox) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of fritzbox can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign fritzbox Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@mib1185 mib1185 marked this pull request as ready for review December 14, 2025 10:28
Copilot AI review requested due to automatic review settings December 14, 2025 10:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for FRITZ! Smarthome routines (called "triggers" internally) to the FritzBox integration. The feature enables users to activate and deactivate these routines through Home Assistant switch entities.

Key changes:

  • Adds a new FritzboxTrigger switch entity class to control FRITZ! Smarthome routines
  • Updates the coordinator to fetch, track, and manage trigger data alongside existing devices and templates
  • Implements test coverage for trigger activation and deactivation operations

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
homeassistant/components/fritzbox/switch.py Adds FritzboxTrigger entity class with turn_on/turn_off methods and device_info for routine switches
homeassistant/components/fritzbox/coordinator.py Extends coordinator data model to include triggers, adds trigger fetching and update logic, includes triggers in device cleanup
tests/components/fritzbox/__init__.py Adds trigger parameter to setup_config_entry helper function for test mocking
tests/components/fritzbox/test_switch.py Adds tests for trigger activation/deactivation and updates test_setup to include trigger entity
tests/components/fritzbox/snapshots/test_switch.ambr Adds snapshot assertions for trigger entity registry and state

Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py
Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py Outdated
Comment thread tests/components/fritzbox/test_switch.py Outdated
@mib1185 mib1185 marked this pull request as draft December 14, 2025 10:43
@mib1185 mib1185 requested a review from Copilot December 14, 2025 11:15
@mib1185 mib1185 marked this pull request as ready for review December 14, 2025 11:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/fritzbox/switch.py
Comment thread tests/components/fritzbox/test_switch.py
LOGGER.debug("enable smarthome templates: %s", self.has_templates)

self.has_triggers = await self.hass.async_add_executor_job(
self.fritz.has_triggers
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

side note, not related to this PR: IMHO it's a bit weird that has_triggers is a function that's doing IO (or why does it need an exector_job?), that rather sounds like a property, if it's a function it should be called something like calculate_triggers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the underlying lib implement these as "real time checks" by calling a specific API endpoint (same for the has_templates check some lines above)

for ain in devices
if coordinator.data.devices[ain].has_switch
)
] + [FritzboxTrigger(coordinator, ain) for ain in triggers]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
] + [FritzboxTrigger(coordinator, ain) for ain in triggers]
]
entities.extend(FritzboxTrigger(coordinator, ain) for ain in triggers)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This produces error: Generator has incompatible item type "FritzboxTrigger"; expected "FritzboxSwitch" when not add type hints to entities: list[FritzBoxEntity | FritzboxTrigger].
so is this more a question of preference or does list.extend() have any other advantages?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's mainly preference (and consistency with the rest of the codebase) and yes, you'd need the type hint, that's true. But if Joost is fine with it let's keep it.

available_main_ains = [
ain
for ain, dev in data.devices.items() | data.templates.items()
for ain, dev in data.devices.items()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find that a bit hard to read, can we make a list with * unpack instead

Copy link
Copy Markdown
Member Author

@mib1185 mib1185 Dec 15, 2025

Choose a reason for hiding this comment

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

what do think about this one?

        available_main_ains = [
            ain
            for ain, dev in (data.devices | data.templates | data.triggers).items()
            if dev.device_and_unit_id[1] is None
        ]

@home-assistant home-assistant Bot marked this pull request as draft December 15, 2025 09:37
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@mib1185 mib1185 marked this pull request as ready for review December 17, 2025 20:34
@home-assistant home-assistant Bot requested a review from zweckj December 17, 2025 20:35
@zweckj zweckj merged commit 3d71b6d into dev Dec 18, 2025
36 checks passed
@zweckj zweckj deleted the fritzbox/add-support-for-routines branch December 18, 2025 12:09
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants