Restore manual alarm-control-panel state using async_get_last_state#17521
Restore manual alarm-control-panel state using async_get_last_state#17521balloob merged 7 commits intohome-assistant:devfrom
Conversation
This is to address issue home-assistant#10793
|
This fix will restore the last state logged that was logged by the logger component whenever hass restarts. This would solve the related issue but I'm just wondering if the right thing might not be to also add an initial state configuration option that would overwrite this behaviour. I could add this as well but I honestly can't think of a use case where restoring the last state would not be what you want. As is, this fix is definitely better than the current implementation where the state is hard-coded to be initialised to Disarmed. As a personal sufferer of this issue, I would certainly be happy with this fix as is. What do you guys think? |
|
Makes sense. please add a test |
I've added two tests, one for restoring armed state and one for restoring disarmed state |
| self.assertEqual(STATE_ALARM_TRIGGERED, state.state) | ||
|
|
||
|
|
||
| @asyncio.coroutine |
There was a problem hiding this comment.
We've migrated to async/await syntax. Please drop this decorator and prefix async methods with async like async def test_restore_armed_state . Replace any yield from with await.
There was a problem hiding this comment.
I've change the syntax as requested. I based my tests on the tests i found in the input variable components, those are still using the asyncio decorator.
There was a problem hiding this comment.
I know. Those need to be updated too. For now we just make sure we don't add new ones.
|
Looks good. I just resolved a merge conflict that sneaked in . Will merge when tests pass. |
|
Congratulations on your first PR, great job ! 👍 |
Thanks balloob! It feels good to be able to give back to this fantastic project, albeit such a tiny contribution. I will certainly be contributing more now that i know the process a bit better. |
|
@liaanvdm I know this has been merged but I am wondering if this would be the same fix for when you use alarm control panel with IFTTT. Upon a restart, the state shows "unknown" until you set it again. See docs. https://www.home-assistant.io/components/alarm_control_panel.ifttt/ I don't know async so I am not sure. |
|
@edif30 I'm afraid this fix only applies to the manual alarm control panel. The issue you described will have to be addressed separately. You'll have to log an issue unless one exists already. |
Description:
This small change restores the manual alarm control panel component's state should homeassistant be restarted for whatever reason. The change uses async_get_last_state as used by components like input-boolean etc.
Related issue (if applicable): fixes #10793
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#N/A
Example entry for
configuration.yaml(if applicable):N/A - No change to configuration required
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:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: