From 36370fe99ea466b9c71459027754b519c645cd37 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Sun, 15 Aug 2021 22:01:17 +0200 Subject: [PATCH] Removed backward compatibility code for v1.20.x (because there were too many other changes that broke the build, and for which creating a work-around was not feasible). --- CHANGELOG.md | 9 +++------ components/xiaomi_bslamp2/light/__init__.py | 2 -- .../xiaomi_bslamp2/light/color_handler_chain.h | 13 ++++++------- .../light/color_handler_color_temperature.h | 6 ------ .../light/color_handler_night_light.h | 4 ---- .../xiaomi_bslamp2/light/color_handler_rgb.h | 6 ------ components/xiaomi_bslamp2/light/light_output.h | 14 ++------------ components/xiaomi_bslamp2/light_hal.h | 8 +++++++- 8 files changed, 18 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ff06d..c66ba61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,19 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.2.0-RC1] **Note**: This release requires ESPHome v1.21.0 and Home Assistant 2021.8.0 or newer. -The code will compile with ESPHome v1.20.0, but the lamp will not be controllable -through the Home Assistant GUI when using Home Assistant 2021.8.0 or newer. -Only turn on/off and brightness will be available, not the RGB and Color Temperature -tabs.. ### Added - Preset identifiers (`group` and `preset`) for the `preset.activate` action are now validated at compile time. This prevents us from building a firmware with incorrect preset identifiers. Before this change, using an invalid preset name would only - result in a warning message in the device log. + result in a warning message in the device log, which is only moderately useful. ### Changed -- The code has been made compatible with the new color mode support in Home Assistant. +- The code has been made compatible with the new color mode support in Home Assistant + and ESPHome. ## [1.1.0] diff --git a/components/xiaomi_bslamp2/light/__init__.py b/components/xiaomi_bslamp2/light/__init__.py index 43927c0..d57e6d6 100644 --- a/components/xiaomi_bslamp2/light/__init__.py +++ b/components/xiaomi_bslamp2/light/__init__.py @@ -225,8 +225,6 @@ def light_output_to_code(config): yield light.register_light(light_output_var, config) light_hal_var = yield cg.get_variable(config[CONF_LIGHT_HAL_ID]) cg.add(light_output_var.set_parent(light_hal_var)) - if hasattr(light, "types") and hasattr(light.types, "COLOR_MODES"): - cg.add_define('HAS_COLOR_MODES') @coroutine def on_brightness_to_code(config): diff --git a/components/xiaomi_bslamp2/light/color_handler_chain.h b/components/xiaomi_bslamp2/light/color_handler_chain.h index a0ac4ed..243e28a 100644 --- a/components/xiaomi_bslamp2/light/color_handler_chain.h +++ b/components/xiaomi_bslamp2/light/color_handler_chain.h @@ -15,9 +15,8 @@ namespace xiaomi { namespace bslamp2 { /** - * This class translates LightColorValues into GPIO duty cycles that - * can be used for representing a requested light color on the - * physical device. + * This class translates LightColorValues into GPIO duty cycles that can be + * used for representing a requested light color on the physical device. * * The code handles all known light modes for the device: * @@ -29,10 +28,10 @@ namespace bslamp2 { class ColorHandlerChain : public ColorHandler { public: bool set_light_color_values(light::LightColorValues v) { - // The actual implementation of the various light modes is in - // separated targeted classes. These classes are called here - // in a chain of command-like pattern, to let the first one - // that can handle the light settings do the honours. + // The actual implementation of the various light modes is in separate + // targeted classes. These classes are called here in a chain of + // command-like pattern, to let the first one that can handle the light + // settings do the honours. if (off_light_->set_light_color_values(v)) off_light_->copy_to(this); else if (night_light_->set_light_color_values(v)) diff --git a/components/xiaomi_bslamp2/light/color_handler_color_temperature.h b/components/xiaomi_bslamp2/light/color_handler_color_temperature.h index ce53aaa..f27b206 100644 --- a/components/xiaomi_bslamp2/light/color_handler_color_temperature.h +++ b/components/xiaomi_bslamp2/light/color_handler_color_temperature.h @@ -80,15 +80,9 @@ class ColorHandlerColorTemperature : public ColorHandler { bool set_light_color_values(light::LightColorValues v) { light_mode = LIGHT_MODE_WHITE; -#ifdef HAS_COLOR_MODES if (v.get_color_mode() != light::ColorMode::COLOR_TEMPERATURE) { return false; } -#else - if (v.get_white() == 0.0f) { - return false; - } -#endif auto temperature = clamp_temperature_(v.get_color_temperature()); auto brightness = clamp_brightness_(v.get_brightness()); diff --git a/components/xiaomi_bslamp2/light/color_handler_night_light.h b/components/xiaomi_bslamp2/light/color_handler_night_light.h index 47c7632..026f13f 100644 --- a/components/xiaomi_bslamp2/light/color_handler_night_light.h +++ b/components/xiaomi_bslamp2/light/color_handler_night_light.h @@ -36,11 +36,7 @@ class ColorHandlerNightLight : public ColorHandler { // This night light mode is activated when white light is selected. // Based on measurements using the original device firmware, so it // matches the night light of the original firmware. -#ifdef HAS_COLOR_MODES if (v.get_color_mode() == light::ColorMode::COLOR_TEMPERATURE) { -#else - if (v.get_white() > 0.0f) { -#endif red = 0.968f; green = 0.968f; blue = 0.972f; diff --git a/components/xiaomi_bslamp2/light/color_handler_rgb.h b/components/xiaomi_bslamp2/light/color_handler_rgb.h index 04e0ac6..7d2896c 100644 --- a/components/xiaomi_bslamp2/light/color_handler_rgb.h +++ b/components/xiaomi_bslamp2/light/color_handler_rgb.h @@ -252,15 +252,9 @@ class ColorHandlerRGB : public ColorHandler { bool set_light_color_values(light::LightColorValues v) { light_mode = LIGHT_MODE_RGB; -#ifdef HAS_COLOR_MODES if (v.get_color_mode() != light::ColorMode::RGB) { return false; } -#else - if (v.get_white() > 0.0f) { - return false; - } -#endif // Determine the ring level for the color. This is a value between 0 // and 7, determining in what ring of the RGB circle the requested diff --git a/components/xiaomi_bslamp2/light/light_output.h b/components/xiaomi_bslamp2/light/light_output.h index edfb54d..7d14e79 100644 --- a/components/xiaomi_bslamp2/light/light_output.h +++ b/components/xiaomi_bslamp2/light/light_output.h @@ -29,15 +29,7 @@ class XiaomiBslamp2LightOutput : public Component, public light::LightOutput { */ light::LightTraits get_traits() override { auto traits = light::LightTraits(); -#ifdef HAS_COLOR_MODES traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLOR_TEMPERATURE}); -#else - traits.set_supports_rgb(true); - traits.set_supports_color_temperature(true); - traits.set_supports_brightness(true); - traits.set_supports_rgb_white_value(false); - traits.set_supports_color_interlock(true); -#endif traits.set_min_mireds(MIRED_MIN); traits.set_max_mireds(MIRED_MAX); return traits; @@ -73,10 +65,8 @@ class XiaomiBslamp2LightOutput : public Component, public light::LightOutput { if (values.get_state() != 0) light_->turn_on(); - // Apply the current GPIO output levels from the selected handler. - light_->set_rgbw( - color_handler_chain->red, color_handler_chain->green, color_handler_chain->blue, - color_handler_chain->white); + // Apply the GPIO output levels as defined by the color handler. + light_->set_state(color_handler_chain); if (values.get_state() == 0) light_->turn_off(); diff --git a/components/xiaomi_bslamp2/light_hal.h b/components/xiaomi_bslamp2/light_hal.h index 96803d4..dfeff8c 100644 --- a/components/xiaomi_bslamp2/light_hal.h +++ b/components/xiaomi_bslamp2/light_hal.h @@ -45,11 +45,17 @@ class LightHAL : Component, public GPIOOutputValues { void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1_pin_ = pin; } void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2_pin_ = pin; } + /** + * Turn on the master switch for the LEDs. + */ void turn_on() { master1_pin_->turn_on(); master2_pin_->turn_on(); } - + + /** + * Turn off the master switch for the LEDs. + */ void turn_off() { master1_pin_->turn_off(); master2_pin_->turn_off();