Add better pause behaviour to Portainer#167453
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Portainer integration to treat paused containers as “on” so entity state and coordinator behavior better match Docker/Portainer semantics.
Changes:
- Add
pausedtoContainerState. - Update the container switch “on” logic to consider both running and paused containers as on.
- Include paused containers when selecting which containers to fetch stats for.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/portainer/switch.py |
Treat paused containers as is_on for the container switch. |
homeassistant/components/portainer/coordinator.py |
Fetch container stats for paused containers in addition to running ones. |
homeassistant/components/portainer/const.py |
Add PAUSED to ContainerState. |
jtjart
left a comment
There was a problem hiding this comment.
The PR got closed before I finished the review. But I thought those comments could improve the code in the future, so I will simply post them. 😄
| @@ -216,7 +216,8 @@ async def _async_update_data(self) -> dict[int, PortainerCoordinatorData]: | |||
| running_containers = [ | |||
There was a problem hiding this comment.
The name could be misleading as there are not just running containers. Maybe renaming it to active_containers would be better.
There was a problem hiding this comment.
I agree. With the current state it's probably a better definition.
| RUNNING = "running" | ||
| PAUSED = "paused" |
There was a problem hiding this comment.
As you are also the owner of the API, you could add an enum to the API, which represents all possible states according to the API's documentation.
There was a problem hiding this comment.
Yup, I'll add this on a bit later. :)
Breaking change
Proposed change
Adds better pause behaviour to Portainer. Meaning the power on/of switch can still be used once paused, as well as getting stats whilst paused. For instance, the memory isn't cleared in a paused state.
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: