Fix service lifecycle and action refresh handling#174
Open
ghislaingaillot wants to merge 1 commit intoad-ha:mainfrom
Open
Fix service lifecycle and action refresh handling#174ghislaingaillot wants to merge 1 commit intoad-ha:mainfrom
ghislaingaillot wants to merge 1 commit intoad-ha:mainfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Review Fixes - 2026-03-21
This note documents the fixes applied after the repository review and explains
why each change was made.
1. Non-blocking action refresh scheduling
Files:
custom_components/mg_saic/coordinator.pyWhat changed:
schedule_action_refresh()implementation with abackground task.
Why:
sleep()calls directly insideservice/entity actions. A lock, climate or charging command could therefore
remain pending for minutes before returning control to Home Assistant.
keeps only one active action-refresh sequence per coordinator and cancels it
safely when the entry is unloaded.
2. Correct multi-VIN service routing
Files:
custom_components/mg_saic/__init__.pycustom_components/mg_saic/services.pyWhat changed:
clients_by_vinalongsidecoordinators_by_vin.the VIN provided in the service call.
Why:
client/coordinator of that entry. With multiple vehicles, the global service
handlers could operate on the wrong coordinator and refresh the wrong VIN.
3. Proper unload and resource cleanup
Files:
custom_components/mg_saic/__init__.pycustom_components/mg_saic/coordinator.pycustom_components/mg_saic/api.pyWhat changed:
refresh callbacks.
close()tolerate an uninitializedsession.
Why:
service registry alive even when the integration had no remaining entries.
stale references.
4. Heated seats service and switch fixes
Files:
custom_components/mg_saic/services.pycustom_components/mg_saic/services.yamlcustom_components/mg_saic/switch.pyWhat changed:
left_levelandright_levelfields.vehicle payload.
Why:
the branch that sends the command, while also reading the wrong status field.
5. Sunroof service compatibility
Files:
custom_components/mg_saic/api.pycustom_components/mg_saic/services.pyWhat changed:
control_sunroof()accept either a boolean or an"open"/"close"string and normalize both forms internally.
Why:
which could invert behavior and always resolve to closing the sunroof.
6. Preserve the configured default polling interval
Files:
custom_components/mg_saic/coordinator.pyWhat changed:
default_update_interval.state.
Why:
UPDATE_INTERVAL, which meant auser-defined polling interval was silently lost after state transitions.
7. API errors now propagate to callers
Files:
custom_components/mg_saic/api.pyWhat changed:
lock_vehicle(),unlock_vehicle()andopen_tailgate().Why:
because those methods swallowed the exception after logging it once.
Validation performed
python3 -m compileall custom_components/mg_saicpython3 -m unittest discover -s tests -p "test_*.py"8. Lightweight automated tests
Files:
custom_components/mg_saic/logic.pytests/test_logic.py.github/workflows/python-tests.yamlWhat changed:
selection.
Why:
two regression-prone code paths without requiring a full Home Assistant test
harness.
Remaining gap
config flow, entity lifecycle and service registration. The most critical
pure logic now has automated coverage, but runtime HA integration coverage is
still a future improvement.