mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
light: add RESTORE_AND_OFF/RESTORE_AND_ON LightRestoreMode (#3238)
This commit is contained in:
parent
ba785e29e9
commit
771162bfb1
3 changed files with 10 additions and 0 deletions
|
@ -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(
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue