light: add RESTORE_AND_OFF/RESTORE_AND_ON LightRestoreMode (#3238)

This commit is contained in:
Niorix 2022-02-21 06:52:14 +07:00 committed by GitHub
parent ba785e29e9
commit 771162bfb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View file

@ -52,6 +52,8 @@ RESTORE_MODES = {
"ALWAYS_ON": LightRestoreMode.LIGHT_ALWAYS_ON, "ALWAYS_ON": LightRestoreMode.LIGHT_ALWAYS_ON,
"RESTORE_INVERTED_DEFAULT_OFF": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_OFF, "RESTORE_INVERTED_DEFAULT_OFF": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_OFF,
"RESTORE_INVERTED_DEFAULT_ON": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_ON, "RESTORE_INVERTED_DEFAULT_ON": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_ON,
"RESTORE_AND_OFF": LightRestoreMode.LIGHT_RESTORE_AND_OFF,
"RESTORE_AND_ON": LightRestoreMode.LIGHT_RESTORE_AND_ON,
} }
LIGHT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend( LIGHT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend(

View file

@ -68,6 +68,12 @@ void LightState::setup() {
recovered.state = !recovered.state; recovered.state = !recovered.state;
} }
break; break;
case LIGHT_RESTORE_AND_OFF:
case LIGHT_RESTORE_AND_ON:
this->rtc_ = global_preferences->make_preference<LightStateRTCState>(this->get_object_id_hash());
this->rtc_.load(&recovered);
recovered.state = (this->restore_mode_ == LIGHT_RESTORE_AND_ON);
break;
case LIGHT_ALWAYS_OFF: case LIGHT_ALWAYS_OFF:
recovered.state = false; recovered.state = false;
break; break;

View file

@ -22,6 +22,8 @@ enum LightRestoreMode {
LIGHT_ALWAYS_ON, LIGHT_ALWAYS_ON,
LIGHT_RESTORE_INVERTED_DEFAULT_OFF, LIGHT_RESTORE_INVERTED_DEFAULT_OFF,
LIGHT_RESTORE_INVERTED_DEFAULT_ON, LIGHT_RESTORE_INVERTED_DEFAULT_ON,
LIGHT_RESTORE_AND_OFF,
LIGHT_RESTORE_AND_ON,
}; };
/** This class represents the communication layer between the front-end MQTT layer and the /** This class represents the communication layer between the front-end MQTT layer and the