mirror of
https://github.com/esphome/esphome.git
synced 2025-09-11 15:52:20 +01:00
add required option for available outputs
This commit is contained in:
@@ -6,8 +6,10 @@ dynamic_lamp_ns = cg.esphome_ns.namespace('dynamic_lamp')
|
|||||||
DynamicLamp = dynamic_lamp_ns.class_('DynamicLamp', cg.Component)
|
DynamicLamp = dynamic_lamp_ns.class_('DynamicLamp', cg.Component)
|
||||||
|
|
||||||
CONF_SAVE_MODE = 'save_mode'
|
CONF_SAVE_MODE = 'save_mode'
|
||||||
|
CONF_AVAILABLE_OUTPUTS = 'available_outputs'
|
||||||
CONFIG_SCHEMA = cv.Schema({
|
CONFIG_SCHEMA = cv.Schema({
|
||||||
cv.GenerateID(): cv.declare_id(DynamicLamp),
|
cv.GenerateID(): cv.declare_id(DynamicLamp),
|
||||||
|
cv.Required(CONF_AVAILABLE_OUTPUTS): cv.ensure_list(cv.string),
|
||||||
cv.Optional(CONF_SAVE_MODE, default=0): cv.int_range(0, 1),
|
cv.Optional(CONF_SAVE_MODE, default=0): cv.int_range(0, 1),
|
||||||
}).extend(cv.COMPONENT_SCHEMA)
|
}).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
@@ -15,4 +17,5 @@ CONFIG_SCHEMA = cv.Schema({
|
|||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
cg.add(var.set_available_outputs(config[CONF_AVAILABLE_OUTPUTS]))
|
||||||
cg.add(var.set_save_mode(config[CONF_SAVE_MODE]))
|
cg.add(var.set_save_mode(config[CONF_SAVE_MODE]))
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "dynamic_lamp.h"
|
#include "dynamic_lamp.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -21,10 +22,38 @@ void DynamicLamp::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLamp::loop() {
|
void DynamicLamp::loop() {
|
||||||
|
uint8_t i = 0;
|
||||||
|
for (i = 0; i < this->lamp_count_; i++) {
|
||||||
|
if (this->active_lamps_[i].active) {
|
||||||
|
uint8_t j = 0;
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
if (this->active_lamps_[i].used_outputs[j].active) {
|
||||||
|
if (this->active_lamps_[i].used_outputs[j].update_level) {
|
||||||
|
// Update level
|
||||||
|
switch (this->active_lamps_[i].used_outputs[j].mode) {
|
||||||
|
case MODE_EQUAL:
|
||||||
|
// Equal
|
||||||
|
break;
|
||||||
|
case MODE_STATIC:
|
||||||
|
// Static
|
||||||
|
break;
|
||||||
|
case MODE_PERCENT:
|
||||||
|
// Percent
|
||||||
|
break;
|
||||||
|
case MODE_FUNCTION:
|
||||||
|
// Function
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLamp::dump_config(){
|
void DynamicLamp::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "Dynamic Lamp feature loaded");
|
ESP_LOGCONFIG(TAG, "Dynamic Lamp feature loaded");
|
||||||
switch(this->save_mode_) {
|
switch(this->save_mode_) {
|
||||||
case SAVE_MODE_NONE:
|
case SAVE_MODE_NONE:
|
||||||
@@ -37,12 +66,25 @@ void DynamicLamp::dump_config(){
|
|||||||
ESP_LOGCONFIG(TAG, "Currently only NONE(0) && FRAM(1) save modes supported, ignoring value %" PRIu8 " and defaulting to NONE!", this->save_mode_);
|
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;
|
this->save_mode_ = 0;
|
||||||
}
|
}
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
if (this->available_outputs_[i] != "") {
|
||||||
|
ESP_LOGCONFIG(TAG, "Using output with id %s as output number %" PRIu8 "", &this->available_outputs_[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLamp::set_save_mode(uint8_t save_mode) {
|
void DynamicLamp::set_save_mode(uint8_t save_mode) {
|
||||||
this->save_mode_ = save_mode;
|
this->save_mode_ = save_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicLamp::set_available_outputs(std::list<std::string> output_list) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
for (std::list<std::string>::iterator it = output_list.begin(); it != output_list.end(); ++it) {
|
||||||
|
this->available_outputs_[i] = *it;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void DynamicLamp::set_lamp_count(uint8_t lamp_count) {
|
void DynamicLamp::set_lamp_count(uint8_t lamp_count) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ enum LinkedOutputModeIdx : uint8_t {
|
|||||||
|
|
||||||
struct LinkedOutput {
|
struct LinkedOutput {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
char* output_id = "";
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
optional<float> min_value;
|
optional<float> min_value;
|
||||||
optional<float> max_value;
|
optional<float> max_value;
|
||||||
@@ -36,6 +37,7 @@ class DynamicLamp : public Component {
|
|||||||
void loop() override;
|
void loop() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_lamp_count(uint8_t lamp_count);
|
void set_lamp_count(uint8_t lamp_count);
|
||||||
|
void set_available_outputs(std::list<std::string> output_list);
|
||||||
void set_save_mode(uint8_t save_mode);
|
void set_save_mode(uint8_t save_mode);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -43,6 +45,7 @@ class DynamicLamp : public Component {
|
|||||||
void set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value);
|
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];
|
CombinedLamp active_lamps_[16];
|
||||||
|
std::string available_outputs_[16] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
|
||||||
uint8_t lamp_count_;
|
uint8_t lamp_count_;
|
||||||
uint8_t save_mode_;
|
uint8_t save_mode_;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user