Browse Source

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).

pull/50/head
Maurice Makaay 3 years ago
parent
commit
36370fe99e
8 changed files with 18 additions and 44 deletions
  1. +3
    -6
      CHANGELOG.md
  2. +0
    -2
      components/xiaomi_bslamp2/light/__init__.py
  3. +6
    -7
      components/xiaomi_bslamp2/light/color_handler_chain.h
  4. +0
    -6
      components/xiaomi_bslamp2/light/color_handler_color_temperature.h
  5. +0
    -4
      components/xiaomi_bslamp2/light/color_handler_night_light.h
  6. +0
    -6
      components/xiaomi_bslamp2/light/color_handler_rgb.h
  7. +2
    -12
      components/xiaomi_bslamp2/light/light_output.h
  8. +7
    -1
      components/xiaomi_bslamp2/light_hal.h

+ 3
- 6
CHANGELOG.md View File

@ -7,19 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.2.0-RC1] ## [1.2.0-RC1]
**Note**: This release requires ESPHome v1.21.0 and Home Assistant 2021.8.0 or newer. **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 ### Added
- Preset identifiers (`group` and `preset`) for the `preset.activate` action are now - 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 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 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 ### 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] ## [1.1.0]


+ 0
- 2
components/xiaomi_bslamp2/light/__init__.py View File

@ -225,8 +225,6 @@ def light_output_to_code(config):
yield light.register_light(light_output_var, config) yield light.register_light(light_output_var, config)
light_hal_var = yield cg.get_variable(config[CONF_LIGHT_HAL_ID]) light_hal_var = yield cg.get_variable(config[CONF_LIGHT_HAL_ID])
cg.add(light_output_var.set_parent(light_hal_var)) 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 @coroutine
def on_brightness_to_code(config): def on_brightness_to_code(config):


+ 6
- 7
components/xiaomi_bslamp2/light/color_handler_chain.h View File

@ -15,9 +15,8 @@ namespace xiaomi {
namespace bslamp2 { 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: * The code handles all known light modes for the device:
* *
@ -29,10 +28,10 @@ namespace bslamp2 {
class ColorHandlerChain : public ColorHandler { class ColorHandlerChain : public ColorHandler {
public: public:
bool set_light_color_values(light::LightColorValues v) { 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)) if (off_light_->set_light_color_values(v))
off_light_->copy_to(this); off_light_->copy_to(this);
else if (night_light_->set_light_color_values(v)) else if (night_light_->set_light_color_values(v))


+ 0
- 6
components/xiaomi_bslamp2/light/color_handler_color_temperature.h View File

@ -80,15 +80,9 @@ class ColorHandlerColorTemperature : public ColorHandler {
bool set_light_color_values(light::LightColorValues v) { bool set_light_color_values(light::LightColorValues v) {
light_mode = LIGHT_MODE_WHITE; light_mode = LIGHT_MODE_WHITE;
#ifdef HAS_COLOR_MODES
if (v.get_color_mode() != light::ColorMode::COLOR_TEMPERATURE) { if (v.get_color_mode() != light::ColorMode::COLOR_TEMPERATURE) {
return false; return false;
} }
#else
if (v.get_white() == 0.0f) {
return false;
}
#endif
auto temperature = clamp_temperature_(v.get_color_temperature()); auto temperature = clamp_temperature_(v.get_color_temperature());
auto brightness = clamp_brightness_(v.get_brightness()); auto brightness = clamp_brightness_(v.get_brightness());


+ 0
- 4
components/xiaomi_bslamp2/light/color_handler_night_light.h View File

@ -36,11 +36,7 @@ class ColorHandlerNightLight : public ColorHandler {
// This night light mode is activated when white light is selected. // This night light mode is activated when white light is selected.
// Based on measurements using the original device firmware, so it // Based on measurements using the original device firmware, so it
// matches the night light of the original firmware. // matches the night light of the original firmware.
#ifdef HAS_COLOR_MODES
if (v.get_color_mode() == light::ColorMode::COLOR_TEMPERATURE) { if (v.get_color_mode() == light::ColorMode::COLOR_TEMPERATURE) {
#else
if (v.get_white() > 0.0f) {
#endif
red = 0.968f; red = 0.968f;
green = 0.968f; green = 0.968f;
blue = 0.972f; blue = 0.972f;


+ 0
- 6
components/xiaomi_bslamp2/light/color_handler_rgb.h View File

@ -252,15 +252,9 @@ class ColorHandlerRGB : public ColorHandler {
bool set_light_color_values(light::LightColorValues v) { bool set_light_color_values(light::LightColorValues v) {
light_mode = LIGHT_MODE_RGB; light_mode = LIGHT_MODE_RGB;
#ifdef HAS_COLOR_MODES
if (v.get_color_mode() != light::ColorMode::RGB) { if (v.get_color_mode() != light::ColorMode::RGB) {
return false; 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 // 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 // and 7, determining in what ring of the RGB circle the requested


+ 2
- 12
components/xiaomi_bslamp2/light/light_output.h View File

@ -29,15 +29,7 @@ class XiaomiBslamp2LightOutput : public Component, public light::LightOutput {
*/ */
light::LightTraits get_traits() override { light::LightTraits get_traits() override {
auto traits = light::LightTraits(); auto traits = light::LightTraits();
#ifdef HAS_COLOR_MODES
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLOR_TEMPERATURE}); 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_min_mireds(MIRED_MIN);
traits.set_max_mireds(MIRED_MAX); traits.set_max_mireds(MIRED_MAX);
return traits; return traits;
@ -73,10 +65,8 @@ class XiaomiBslamp2LightOutput : public Component, public light::LightOutput {
if (values.get_state() != 0) if (values.get_state() != 0)
light_->turn_on(); 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) if (values.get_state() == 0)
light_->turn_off(); light_->turn_off();


+ 7
- 1
components/xiaomi_bslamp2/light_hal.h View File

@ -45,11 +45,17 @@ class LightHAL : Component, public GPIOOutputValues {
void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1_pin_ = pin; } void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1_pin_ = pin; }
void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2_pin_ = pin; } void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2_pin_ = pin; }
/**
* Turn on the master switch for the LEDs.
*/
void turn_on() { void turn_on() {
master1_pin_->turn_on(); master1_pin_->turn_on();
master2_pin_->turn_on(); master2_pin_->turn_on();
} }
/**
* Turn off the master switch for the LEDs.
*/
void turn_off() { void turn_off() {
master1_pin_->turn_off(); master1_pin_->turn_off();
master2_pin_->turn_off(); master2_pin_->turn_off();


Loading…
Cancel
Save