mirror of
https://github.com/esphome/esphome.git
synced 2025-09-09 23:02:23 +01:00
feat: enhance DynamicLampComponent with state management and output updates
This commit is contained in:
@@ -44,31 +44,52 @@ void DynamicLampComponent::begin() {
|
|||||||
void DynamicLampComponent::loop() {
|
void DynamicLampComponent::loop() {
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
for (i = 0; i < this->lamp_count_; i++) {
|
for (i = 0; i < this->lamp_count_; i++) {
|
||||||
if (this->active_lamps_[i].active) {
|
if (this->active_lamps_[i].active && this->active_lamps_[i].update_) {
|
||||||
uint8_t j = 0;
|
uint8_t j = 0;
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
if (this->active_lamps_[i].used_outputs[j]) {
|
if (this->active_lamps_[i].used_outputs[j]) {
|
||||||
if (this->available_outputs_[j].update_level) {
|
// Update level
|
||||||
// Update level
|
switch (this->available_outputs_[j].mode) {
|
||||||
switch (this->available_outputs_[j].mode) {
|
float new_state = this->active_lamps_[i].state_;
|
||||||
case MODE_EQUAL:
|
case MODE_EQUAL:
|
||||||
// Equal
|
// Equal
|
||||||
break;
|
if (new_state < this->available_outputs_[j].min_value) {
|
||||||
case MODE_STATIC:
|
new_state = this->available_outputs_[j].min_value;
|
||||||
// Static
|
}
|
||||||
break;
|
else if (new_state > this->available_outputs_[j].max_value) {
|
||||||
case MODE_PERCENTAGE:
|
new_state = this->available_outputs_[j].max_value;
|
||||||
// Percent
|
}
|
||||||
break;
|
break;
|
||||||
case MODE_FUNCTION:
|
case MODE_STATIC:
|
||||||
// Function
|
// Static
|
||||||
break;
|
new_state = this->available_outputs_[j].mode_value);
|
||||||
default:
|
break;
|
||||||
break;
|
case MODE_PERCENTAGE:
|
||||||
}
|
// Percent
|
||||||
|
new_state = this->active_lamps_[i].state * this->available_outputs_[j].mode_value;
|
||||||
|
if (new_state < this->available_outputs_[j].min_value) {
|
||||||
|
new_state = this->available_outputs_[j].min_value;
|
||||||
|
}
|
||||||
|
else if (new_state > this->available_outputs_[j].max_value) {
|
||||||
|
new_state = this->available_outputs_[j].max_value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MODE_FUNCTION:
|
||||||
|
// ToDo - yet to be implemented
|
||||||
|
// Function
|
||||||
|
ESP_LOGW(TAG, "Mode %d for output %s is not implemented yet, sorry", this->available_outputs_[j].mode, this->available_outputs_[j].output_id.c_str());
|
||||||
|
this->status_set_warning();
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
// Unknown
|
||||||
|
ESP_LOGW(TAG, "Unknown mode %d for output %s", this->available_outputs_[j].mode, this->available_outputs_[j].output_id.c_str());
|
||||||
|
this->status_set_warning();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
this->available_outputs_[j].output->write_state(new_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->active_lamps_[i].update_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +220,15 @@ void DynamicLampComponent::set_lamp_level(std::string lamp_name, float state) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DynamicLampComponent::write_state(uint8_t lamp_number, float state) {
|
||||||
|
if (this->active_lamps_[lamp_number].active) {
|
||||||
|
this->active_lamps_[lamp_number].state_ = state;
|
||||||
|
this->active_lamps_[lamp_number].update_ = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void DynamicLampComponent::set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value) {
|
void DynamicLampComponent::set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ struct LinkedOutput {
|
|||||||
output::FloatOutput *output;
|
output::FloatOutput *output;
|
||||||
float state;
|
float state;
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
|
float mode_value = 0;
|
||||||
optional<float> min_value;
|
optional<float> min_value;
|
||||||
optional<float> max_value;
|
optional<float> max_value;
|
||||||
bool update_level = false;
|
bool update_level = false;
|
||||||
@@ -52,9 +53,10 @@ enum DynamicLampIdx : uint8_t {
|
|||||||
|
|
||||||
struct CombinedLamp {
|
struct CombinedLamp {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
bool update_ = false;
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
uint8_t lamp_index;
|
uint8_t lamp_index;
|
||||||
float state;
|
float state_;
|
||||||
bool used_outputs[16];
|
bool used_outputs[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ namespace dynamic_lamp {
|
|||||||
static const char *const TAG = "dynamic_lamp.output";
|
static const char *const TAG = "dynamic_lamp.output";
|
||||||
|
|
||||||
void DynamicLamp::write_state(float state) {
|
void DynamicLamp::write_state(float state) {
|
||||||
|
if (this->parent_->write_state(this->lamp_, state)) {
|
||||||
this->state_ = state;
|
this->state_ = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user