mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 13:22:19 +01:00
fix: enhance dynamic_lamp to include output ID in available outputs and update mode naming
This commit is contained in:
@@ -19,6 +19,7 @@ async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
for outputPointer in config.get(CONF_AVAILABLE_OUTPUTS, []):
|
||||
idstr_ = str(outputPointer)
|
||||
output_ = await cg.get_variable(outputPointer)
|
||||
cg.add(var.add_available_output(output_))
|
||||
cg.add(var.add_available_output(output_, idstr_))
|
||||
cg.add(var.set_save_mode(config[CONF_SAVE_MODE]))
|
||||
|
@@ -53,7 +53,7 @@ void DynamicLamp::loop() {
|
||||
case MODE_STATIC:
|
||||
// Static
|
||||
break;
|
||||
case MODE_PERCENT:
|
||||
case MODE_PERCENTAGE:
|
||||
// Percent
|
||||
break;
|
||||
case MODE_FUNCTION:
|
||||
@@ -84,8 +84,7 @@ void DynamicLamp::dump_config() {
|
||||
}
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
if (this->available_outputs_[i].active) {
|
||||
ESP_LOGCONFIG(TAG, "Using output with id .. as output number %" PRIu8 "", i);
|
||||
this->available_outputs_[i].output->set_level(0.256f);
|
||||
ESP_LOGCONFIG(TAG, "Using output with id %s as output number %" PRIu8 "", this->available_outputs_[i].output_id.c_str(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,15 +93,16 @@ void DynamicLamp::set_save_mode(uint8_t save_mode) {
|
||||
this->save_mode_ = save_mode;
|
||||
}
|
||||
|
||||
void DynamicLamp::add_available_output(output::FloatOutput * output) {
|
||||
void DynamicLamp::add_available_output(output::FloatOutput * output, std::string output_id) {
|
||||
uint8_t counter = 0;
|
||||
while (this->available_outputs_[counter].active) {
|
||||
counter++;
|
||||
}
|
||||
this->available_outputs_[counter] = LinkedOutput{
|
||||
true,
|
||||
output,
|
||||
output_id,
|
||||
counter,
|
||||
output,
|
||||
0, 0, 1.0, false
|
||||
};
|
||||
counter++;
|
||||
|
@@ -14,14 +14,16 @@ enum SupportedSaveModes : uint8_t {
|
||||
enum LinkedOutputModeIdx : uint8_t {
|
||||
MODE_EQUAL = 0,
|
||||
MODE_STATIC = 1,
|
||||
MODE_PERCENT = 2,
|
||||
MODE_PERCENTAGE = 2,
|
||||
MODE_FUNCTION = 3
|
||||
};
|
||||
|
||||
struct LinkedOutput {
|
||||
bool active = false;
|
||||
output::FloatOutput *output;
|
||||
std::string output_id;
|
||||
uint8_t output_index;
|
||||
output::FloatOutput *output;
|
||||
float state;
|
||||
uint8_t mode = 0;
|
||||
optional<float> min_value;
|
||||
optional<float> max_value;
|
||||
@@ -38,7 +40,7 @@ class DynamicLamp : public Component {
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
void add_available_output(output::FloatOutput * output);
|
||||
void add_available_output(output::FloatOutput * output, std::string output_id);
|
||||
void set_save_mode(uint8_t save_mode);
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user