Add support for FRITZ! Smarthome routines#158947
Conversation
|
Hey there @flabbamann, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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
FritzboxTriggerswitch 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 |
| LOGGER.debug("enable smarthome templates: %s", self.has_templates) | ||
|
|
||
| self.has_triggers = await self.hass.async_add_executor_job( | ||
| self.fritz.has_triggers |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
| ] + [FritzboxTrigger(coordinator, ain) for ain in triggers] | |
| ] | |
| entities.extend(FritzboxTrigger(coordinator, ain) for ain in triggers) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
I find that a bit hard to read, can we make a list with * unpack instead
There was a problem hiding this comment.
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
]|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
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
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: