switch: support restore_mode#114
Open
dzikus wants to merge 1 commit into
Open
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.
Add
restore_modesupport to the MIoTswitchplatform viaswitch.switch_schema(MiotSwitch, default_restore_mode="DISABLED"). Opt-in, default DISABLED, so existing configs are unaffected.Some MIoT devices don't persist power state across a power cut. For example, the Mi Smart Standing Fan 2 (dmaker.fan.p18) remembers Mode and Oscillation on its MCU but Power always comes back off, with no way to restore it.
setup()reads the restored value viaget_initial_state_with_restore_mode(). On the first property report from the MCU after boot, if it differs from the restored value, we re-assert the restored state withwrite_state(); otherwise we just publish the reported value. After that, reports are handled as before, so the MCU stays the source of truth. Since this reacts to the first MCU report instead of polling, restore happens within ~1-2s of boot.Tested on dmaker.fan.p18 (ESP8266) with
restore_mode: RESTORE_DEFAULT_OFFon the Power switch. After a real power cut it comes back on within 1-2s. Configs withoutrestore_modeset are unaffected.