mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-28 00:38:28 +02:00
Fix light partition (#584)
* Fix light partition Fixes https://github.com/esphome/issues/issues/365 * Lint
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
namespace esphome {
|
||||
namespace light {
|
||||
|
||||
static const char *TAG = "light.addressable";
|
||||
|
||||
const ESPColor ESPColor::BLACK = ESPColor(0, 0, 0, 0);
|
||||
const ESPColor ESPColor::WHITE = ESPColor(255, 255, 255, 255);
|
||||
|
||||
@@ -92,5 +94,24 @@ int32_t HOT interpret_index(int32_t index, int32_t size) {
|
||||
return index;
|
||||
}
|
||||
|
||||
void AddressableLight::call_setup() {
|
||||
this->setup_internal_();
|
||||
this->setup();
|
||||
|
||||
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
||||
this->set_interval(5000, [this]() {
|
||||
const char *name = this->state_parent_ == nullptr ? "" : this->state_parent_->get_name().c_str();
|
||||
ESP_LOGVV(TAG, "Addressable Light '%s' (effect_active=%s next_show=%s)", name, YESNO(this->effect_active_),
|
||||
YESNO(this->next_show_));
|
||||
for (int i = 0; i < this->size(); i++) {
|
||||
auto color = this->get(i);
|
||||
ESP_LOGVV(TAG, " [%2d] Color: R=%3u G=%3u B=%3u W=%3u", i, color.get_red_raw(), color.get_green_raw(),
|
||||
color.get_blue_raw(), color.get_white_raw());
|
||||
}
|
||||
ESP_LOGVV(TAG, "");
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace esphome
|
||||
|
||||
@@ -335,13 +335,21 @@ class ESPColorView : public ESPColorSettable {
|
||||
void darken(uint8_t delta) override { this->set(this->get().darken(delta)); }
|
||||
ESPColor get() const { return ESPColor(this->get_red(), this->get_green(), this->get_blue(), this->get_white()); }
|
||||
uint8_t get_red() const { return this->color_correction_->color_uncorrect_red(*this->red_); }
|
||||
uint8_t get_red_raw() const { return *this->red_; }
|
||||
uint8_t get_green() const { return this->color_correction_->color_uncorrect_green(*this->green_); }
|
||||
uint8_t get_green_raw() const { return *this->green_; }
|
||||
uint8_t get_blue() const { return this->color_correction_->color_uncorrect_blue(*this->blue_); }
|
||||
uint8_t get_blue_raw() const { return *this->blue_; }
|
||||
uint8_t get_white() const {
|
||||
if (this->white_ == nullptr)
|
||||
return 0;
|
||||
return this->color_correction_->color_uncorrect_white(*this->white_);
|
||||
}
|
||||
uint8_t get_white_raw() const {
|
||||
if (this->white_ == nullptr)
|
||||
return 0;
|
||||
return *this->white_;
|
||||
}
|
||||
uint8_t get_effect_data() const {
|
||||
if (this->effect_data_ == nullptr)
|
||||
return 0;
|
||||
@@ -475,7 +483,7 @@ class ESPRangeView : public ESPColorSettable {
|
||||
int32_t end_;
|
||||
};
|
||||
|
||||
class AddressableLight : public LightOutput {
|
||||
class AddressableLight : public LightOutput, public Component {
|
||||
public:
|
||||
virtual int32_t size() const = 0;
|
||||
ESPColorView operator[](int32_t index) const { return this->get_view_internal(interpret_index(index, this->size())); }
|
||||
@@ -530,13 +538,18 @@ class AddressableLight : public LightOutput {
|
||||
this->correction_.set_max_brightness(ESPColor(uint8_t(roundf(red * 255.0f)), uint8_t(roundf(green * 255.0f)),
|
||||
uint8_t(roundf(blue * 255.0f)), uint8_t(roundf(white * 255.0f))));
|
||||
}
|
||||
void setup_state(LightState *state) override { this->correction_.calculate_gamma_table(state->get_gamma_correct()); }
|
||||
void setup_state(LightState *state) override {
|
||||
this->correction_.calculate_gamma_table(state->get_gamma_correct());
|
||||
this->state_parent_ = state;
|
||||
}
|
||||
void schedule_show() { this->next_show_ = true; }
|
||||
|
||||
#ifdef USE_POWER_SUPPLY
|
||||
void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
|
||||
#endif
|
||||
|
||||
void call_setup() override;
|
||||
|
||||
protected:
|
||||
bool should_show_() const { return this->effect_active_ || this->next_show_; }
|
||||
void mark_shown_() {
|
||||
@@ -559,6 +572,7 @@ class AddressableLight : public LightOutput {
|
||||
#ifdef USE_POWER_SUPPLY
|
||||
power_supply::PowerSupplyRequester power_;
|
||||
#endif
|
||||
LightState *state_parent_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
|
||||
@@ -7,7 +7,7 @@ LightState = light_ns.class_('LightState', cg.Nameable, cg.Component)
|
||||
# Fake class for addressable lights
|
||||
AddressableLightState = light_ns.class_('LightState', LightState)
|
||||
LightOutput = light_ns.class_('LightOutput')
|
||||
AddressableLight = light_ns.class_('AddressableLight')
|
||||
AddressableLight = light_ns.class_('AddressableLight', cg.Component)
|
||||
AddressableLightRef = AddressableLight.operator('ref')
|
||||
LightColorValues = light_ns.class_('LightColorValues')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user