Restore automation last_triggered with initial_state override#24400
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration ( This is a automatic comment generated by codeowners-mention to help ensure issues and pull requests are seen by the right people. |
balloob
left a comment
There was a problem hiding this comment.
ok to merge when comment addressed
|
❌ ci/circleci: static-check, because of a styling issue in an unrelated file:
Introduced in #24373 |
|
Rebased onto |
| state = hass.states.get('automation.hello') | ||
| assert state | ||
| assert state.state == STATE_OFF | ||
| assert state.attributes.get('last_triggered') is None |
There was a problem hiding this comment.
Are you asserting that last_triggered is not present in the dictionary or that it's present but with a value of None? This should be made tighter to verify the intended behavior... i.e. assert 'last_triggered' not in state.attributes or assert state.attributes['last_triggered'] is None.
There was a problem hiding this comment.
The last_triggered attribute is hardcoded to be returned always in the state attributes of AutomationEntity. It will always be there, by default initialized as None.
It really won't matter, secondly, this is consistent with all other tests.
Third, the test_automation_restore_state test should cover that case IMHO, which it doesn't either.
…ssistant#24400) * Restore automation last_triggered with initial_state override * Made test async/await * Fixes linter warning * Update test_init.py
Breaking Change:
When setting the startup state of automation using the
initial_statesetting, it would also mean that thelast_triggeredattribute of the automation was lost. This behavior has been solved. It can potentially break automations if you rely on it being reset on startup.Description:
Automations are restored from the state storage only when
initial_stateisn't set.However, the
last_triggeredis also restored from the state storage.The current logic, makes the
last_triggeredvanish when the user has set aninitial_state.This PR changes this behavior, by first trying to load the previous state from the state storage and later apply the
initial_stateoverride. This preserves thelast_triggeredattribute.Related issue (if applicable): fixes #12672 (old closed, never resolved).
Pull request with documentation for home-assistant.io (if applicable): n/a
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: