1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-11 15:52:20 +01:00

add initial test of dynamic lamp component

This commit is contained in:
Oliver Kleinecke
2025-02-14 11:43:47 +01:00
parent bbdc9c52ba
commit c841ae4fcc
4 changed files with 178 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
dynamic_lamp_ns = cg.esphome_ns.namespace('dynamic_lamp')
DynamicLamp = dynamic_lamp_ns.class_('DynamicLamp', cg.Component)
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(DynamicLamp)
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)

View File

@@ -0,0 +1,56 @@
#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) {
this->active_lamps_[lamp_number].active = false;
}
} // namespace dynamic_lamp
} // namespace esphome

View File

@@ -0,0 +1,57 @@
#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

@@ -0,0 +1,51 @@
#pragma once
#include "esphome/core/component.h"
namespace esphome {
namespace dynamic_lamp {
enum SupportedSaveModes : uint8_t {
SAVE_MODE_NONE = 0,
SAVE_MODE_FRAM = 1
};
enum LinkedOutputModeIdx : uint8_t {
MODE_EQUAL = 0,
MODE_STATIC = 1,
MODE_PERCENT = 2,
MODE_FUNCTION = 3
};
struct LinkedOutput {
bool active = false;
uint8_t mode = 0;
optional<float> min_value;
optional<float> max_value;
bool update_level = false;
};
struct CombinedLamp {
bool active = false;
LinkedOutput used_outputs[16];
};
class DynamicLamp : public Component {
public:
void setup() override;
void loop() override;
void dump_config() override;
void set_lamp_count(uint8_t lamp_count);
protected:
void restore_lamp_values_(uint8_t lamp_number);
void set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value);
CombinedLamp active_lamps_[16];
uint8_t lamp_count_;
uint8_t save_mode_;
};
} // namespace dynamic_lamp
} // namespace esphome