1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 23:32:23 +01:00

add save_mode optional config, defaulting to 0

This commit is contained in:
Oliver Kleinecke
2025-02-14 12:28:26 +01:00
parent c841ae4fcc
commit b382e77d3c
4 changed files with 12 additions and 62 deletions

View File

@@ -5,10 +5,14 @@ from esphome.const import CONF_ID
dynamic_lamp_ns = cg.esphome_ns.namespace('dynamic_lamp')
DynamicLamp = dynamic_lamp_ns.class_('DynamicLamp', cg.Component)
CONF_SAVE_MODE = 'save_mode'
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(DynamicLamp)
cv.GenerateID(): cv.declare_id(DynamicLamp),
cv.Optional(CONF_SAVE_MODE, default=0): cv.int_range(0, 1),
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
await cg.register_component(var, config)
cg.add(var.set_save_mode(config[CONF_SAVE_MODE]))

View File

@@ -9,8 +9,6 @@ static const char *TAG = "dynamic_lamp";
void DynamicLamp::setup() {
uint8_t i = 0;
bool valid = true;
this->save_mode_ = SAVE_MODE_NONE; //Currently only none & fram supported
if(this->save_mode_ == 0) {
for (i=0; i < 16; i++) {
this->active_lamps_[i].active = false;
@@ -40,6 +38,10 @@ void DynamicLamp::dump_config(){
}
}
void DynamicLamp::set_save_mode(uint8_t save_mode) {
this->save_mode_ = save_mode;
}
void DynamicLamp::set_lamp_count(uint8_t lamp_count) {
}

View File

@@ -1,57 +0,0 @@
#include "esphome/core/log.h"
#include "dynamic_lamp.h"
namespace esphome {
namespace dynamic_lamp {
static const char *TAG = "dynamic_lamp";
void DynamicLamp::setup() {
uint8_t i = 0;
bool valid = true;
this->save_mode_ = SAVE_MODE_NONE; //Currently only none & fram supported
if(this->save_mode_ == 0) {
for (i=0; i < 16; i++) {
this->active_lamps_[i].active = false;
}
} else {
while(i < 16) {
this->restore_lamp_values_(i);
}
}
}
void DynamicLamp::loop() {
}
void DynamicLamp::dump_config(){
ESP_LOGCONFIG(TAG, "Dynamic Lamp feature loaded");
switch(this->save_mode_) {
case SAVE_MODE_NONE:
ESP_LOGCONFIG(TAG, "Save mode set to NONE");
case SAVE_MODE_FRAM:
ESP_LOGCONFIG(TAG, "Save mode set to FRAM");
break;
default:
ESP_LOGCONFIG(TAG, "Currently only NONE(0) && FRAM(1) save modes supported, ignoring value %" PRIu8 " and defaulting to NONE!", this->save_mode_);
this->save_mode_ = 0;
}
}
void DynamicLamp::set_lamp_count(uint8_t lamp_count) {
}
void DynamicLamp::set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value) {
}
void DynamicLamp::restore_lamp_values_(uint8_t lamp_number) {
switch(this->save_mode_)
this->active_lamps_[lamp_number].active = false;
}
} // namespace dynamic_lamp
} // namespace esphome

View File

@@ -36,6 +36,7 @@ class DynamicLamp : public Component {
void loop() override;
void dump_config() override;
void set_lamp_count(uint8_t lamp_count);
void set_save_mode(uint8_t save_mode);
protected:
void restore_lamp_values_(uint8_t lamp_number);