Skip to content

switch: support restore_mode#114

Open
dzikus wants to merge 1 commit into
dhewg:mainfrom
dzikus:feature/restore-mode
Open

switch: support restore_mode#114
dzikus wants to merge 1 commit into
dhewg:mainfrom
dzikus:feature/restore-mode

Conversation

@dzikus

@dzikus dzikus commented Jul 1, 2026

Copy link
Copy Markdown

Add restore_mode support to the MIoT switch platform via switch.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 via get_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 with write_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_OFF on the Power switch. After a real power cut it comes back on within 1-2s. Configs without restore_mode set are unaffected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant