From 6c5c6ca5cc745b509b067918c204b2aba7bf2571 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Wed, 24 Mar 2021 13:45:17 +0100 Subject: [PATCH] Moved to a proper ESPHome component structure. --- .gitignore | 3 + README.md | 29 +++++++- __init__.py | 0 doc/example.yaml | 53 ++++++++++++++ ... on front panel - KF8TS2716 Data Sheet.pdf | Bin .../Component KL3 diode.webp | Bin ...htness LED driver with internal switch.pdf | Bin ...BA4338 Dual P-channel mosfet datasheet.pdf | Bin .../ESP32 pinout.xcf | Bin .../I2C protocol/i2c_commands.txt | 0 .../button on - button off - button on.txt | 0 .../button on hold a while - release.txt | 0 .../traces/color button hold - release.txt | 0 .../color button touch - release 3x.txt | 0 .../I2C protocol/traces/remote 1% to 100%.txt | 0 .../traces/remote 100% to 80%.txt | 0 .../I2C protocol/traces/remote 20% to 1%.txt | 0 .../I2C protocol/traces/remote 40% to 20%.txt | 0 .../I2C protocol/traces/remote 60% to 40%.txt | 0 .../I2C protocol/traces/remote 80% to 60%.txt | 0 .../I2C protocol/traces/remote off.txt | 0 .../I2C protocol/traces/remote on.txt | 0 .../traces/slider slide 1% to 100%.txt | 0 .../slider touch - release at about 30%.txt | 0 ...uch increasing brightnesses 0 - 100 7x.txt | 0 .../IC connected to I2C on GPIO 17+18.xcf | Bin .../Original firmware boot messages.txt | 0 .../PulseView setup for RGB tests.pvs | 0 doc/{ => reverse_engineering}/RGB_mapping.py | 0 .../Reboot crashes on ESPHome.txt | 0 .../Trace bottom left.xcf | Bin .../Trace bottom right.xcf | Bin ... for IC connected to I2C on GPIO 17+18.xcf | Bin .../Trace front panel connector.xcf | Bin .../Trace top left.xcf | Bin .../Trace top right.xcf | Bin .../Yeelight GPIO measurements.xlsx | Bin example-device.yaml | 29 -------- library.json | 23 ------ light.py | 41 +++++++++++ yeelight_bs2.yaml | 69 ------------------ ...ghtOutput.h => yeelight_bs2_light_output.h | 35 +++++---- 42 files changed, 143 insertions(+), 139 deletions(-) create mode 100644 __init__.py create mode 100644 doc/example.yaml rename doc/{ => reverse_engineering}/Component Chip on front panel - KF8TS2716 Data Sheet.pdf (100%) rename doc/{ => reverse_engineering}/Component KL3 diode.webp (100%) rename doc/{ => reverse_engineering}/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf (100%) rename doc/{ => reverse_engineering}/Component VBA4338 Dual P-channel mosfet datasheet.pdf (100%) rename doc/{ => reverse_engineering}/ESP32 pinout.xcf (100%) rename doc/{ => reverse_engineering}/I2C protocol/i2c_commands.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/button on - button off - button on.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/button on hold a while - release.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/color button hold - release.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/color button touch - release 3x.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 1% to 100%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 100% to 80%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 20% to 1%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 40% to 20%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 60% to 40%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote 80% to 60%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote off.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/remote on.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/slider slide 1% to 100%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/slider touch - release at about 30%.txt (100%) rename doc/{ => reverse_engineering}/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt (100%) rename doc/{ => reverse_engineering}/IC connected to I2C on GPIO 17+18.xcf (100%) rename doc/{ => reverse_engineering}/Original firmware boot messages.txt (100%) rename doc/{ => reverse_engineering}/PulseView setup for RGB tests.pvs (100%) rename doc/{ => reverse_engineering}/RGB_mapping.py (100%) rename doc/{ => reverse_engineering}/Reboot crashes on ESPHome.txt (100%) rename doc/{ => reverse_engineering}/Trace bottom left.xcf (100%) rename doc/{ => reverse_engineering}/Trace bottom right.xcf (100%) rename doc/{ => reverse_engineering}/Trace for IC connected to I2C on GPIO 17+18.xcf (100%) rename doc/{ => reverse_engineering}/Trace front panel connector.xcf (100%) rename doc/{ => reverse_engineering}/Trace top left.xcf (100%) rename doc/{ => reverse_engineering}/Trace top right.xcf (100%) rename doc/{ => reverse_engineering}/Yeelight GPIO measurements.xlsx (100%) delete mode 100644 example-device.yaml delete mode 100644 library.json create mode 100644 light.py delete mode 100644 yeelight_bs2.yaml rename src/YeelightBedsideLampV2LightOutput.h => yeelight_bs2_light_output.h (91%) diff --git a/.gitignore b/.gitignore index a674637..e9a4b6f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ tags # OpenOffice temp files **/.~* + +# Python cache files +__pycache__ diff --git a/README.md b/README.md index b9ce24d..64d6f5b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ # esphome-yeelight_bs2 -# References +## Installation + +Create a folder named `custom_components` in the folder where your +device's yaml configuration file is stored. Then clone the the Github +repo into that folder. For example on the command line: + +``` +# mkdir custom_components +# cd custom_compnents +# git clone https://github.com/mmakaay/esphome-yeelight_bs2 +``` + +Your folder structure should now look like: +``` +config +├── yourdevice.yaml +├── custom_components/ +│ ├── esphome-yeelight_bs2/ +│ . ├── README.md +. . ├── yeelight_bs2_light_output.h +. . + . +``` + +Then add the required configuration to your device's yaml configuration file. +For an example file, taks a look at `doc/example.yaml` in this repository. -* Inspiration for some ESPHome settings: - https://www.reddit.com/r/Esphome/comments/j11ayw/working_configuration_for_xiaomi_mi_desk_lamp_1s/ diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/doc/example.yaml b/doc/example.yaml new file mode 100644 index 0000000..3d2e204 --- /dev/null +++ b/doc/example.yaml @@ -0,0 +1,53 @@ +i2c: + - id: eeprom_i2c + sda: 17 + scl: 18 + scan: True + - id: front_panel_i2c + sda: 21 + scl: 19 + scan: True + +output: + - platform: gpio + id: master1 + pin: GPIO33 + - platform: gpio + id: master2 + pin: GPIO4 + - platform: ledc + id: led_r + pin: GPIO13 + frequency: "3000Hz" + - platform: ledc + id: led_g + pin: GPIO14 + frequency: "3000Hz" + - platform: ledc + id: led_b + pin: GPIO5 + frequency: "3000Hz" + - platform: ledc + id: led_w + pin: GPIO12 + frequency: "3000Hz" + +light: + - platform: yeelight_bs2 + name: ${friendly_name} Custom Light + red: led_r + green: led_g + blue: led_b + white: led_w + master1: master1 + master2: master2 + default_transition_length: 1s + effects: + - random: + name: "Slow Random" + transition_length: 30s + update_interval: 30s + - random: + name: "Fast Random" + transition_length: 3s + update_interval: 4s diff --git a/doc/Component Chip on front panel - KF8TS2716 Data Sheet.pdf b/doc/reverse_engineering/Component Chip on front panel - KF8TS2716 Data Sheet.pdf similarity index 100% rename from doc/Component Chip on front panel - KF8TS2716 Data Sheet.pdf rename to doc/reverse_engineering/Component Chip on front panel - KF8TS2716 Data Sheet.pdf diff --git a/doc/Component KL3 diode.webp b/doc/reverse_engineering/Component KL3 diode.webp similarity index 100% rename from doc/Component KL3 diode.webp rename to doc/reverse_engineering/Component KL3 diode.webp diff --git a/doc/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf b/doc/reverse_engineering/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf similarity index 100% rename from doc/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf rename to doc/reverse_engineering/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf diff --git a/doc/Component VBA4338 Dual P-channel mosfet datasheet.pdf b/doc/reverse_engineering/Component VBA4338 Dual P-channel mosfet datasheet.pdf similarity index 100% rename from doc/Component VBA4338 Dual P-channel mosfet datasheet.pdf rename to doc/reverse_engineering/Component VBA4338 Dual P-channel mosfet datasheet.pdf diff --git a/doc/ESP32 pinout.xcf b/doc/reverse_engineering/ESP32 pinout.xcf similarity index 100% rename from doc/ESP32 pinout.xcf rename to doc/reverse_engineering/ESP32 pinout.xcf diff --git a/doc/I2C protocol/i2c_commands.txt b/doc/reverse_engineering/I2C protocol/i2c_commands.txt similarity index 100% rename from doc/I2C protocol/i2c_commands.txt rename to doc/reverse_engineering/I2C protocol/i2c_commands.txt diff --git a/doc/I2C protocol/traces/button on - button off - button on.txt b/doc/reverse_engineering/I2C protocol/traces/button on - button off - button on.txt similarity index 100% rename from doc/I2C protocol/traces/button on - button off - button on.txt rename to doc/reverse_engineering/I2C protocol/traces/button on - button off - button on.txt diff --git a/doc/I2C protocol/traces/button on hold a while - release.txt b/doc/reverse_engineering/I2C protocol/traces/button on hold a while - release.txt similarity index 100% rename from doc/I2C protocol/traces/button on hold a while - release.txt rename to doc/reverse_engineering/I2C protocol/traces/button on hold a while - release.txt diff --git a/doc/I2C protocol/traces/color button hold - release.txt b/doc/reverse_engineering/I2C protocol/traces/color button hold - release.txt similarity index 100% rename from doc/I2C protocol/traces/color button hold - release.txt rename to doc/reverse_engineering/I2C protocol/traces/color button hold - release.txt diff --git a/doc/I2C protocol/traces/color button touch - release 3x.txt b/doc/reverse_engineering/I2C protocol/traces/color button touch - release 3x.txt similarity index 100% rename from doc/I2C protocol/traces/color button touch - release 3x.txt rename to doc/reverse_engineering/I2C protocol/traces/color button touch - release 3x.txt diff --git a/doc/I2C protocol/traces/remote 1% to 100%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 1% to 100%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 1% to 100%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 1% to 100%.txt diff --git a/doc/I2C protocol/traces/remote 100% to 80%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 100% to 80%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 100% to 80%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 100% to 80%.txt diff --git a/doc/I2C protocol/traces/remote 20% to 1%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 20% to 1%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 20% to 1%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 20% to 1%.txt diff --git a/doc/I2C protocol/traces/remote 40% to 20%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 40% to 20%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 40% to 20%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 40% to 20%.txt diff --git a/doc/I2C protocol/traces/remote 60% to 40%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 60% to 40%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 60% to 40%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 60% to 40%.txt diff --git a/doc/I2C protocol/traces/remote 80% to 60%.txt b/doc/reverse_engineering/I2C protocol/traces/remote 80% to 60%.txt similarity index 100% rename from doc/I2C protocol/traces/remote 80% to 60%.txt rename to doc/reverse_engineering/I2C protocol/traces/remote 80% to 60%.txt diff --git a/doc/I2C protocol/traces/remote off.txt b/doc/reverse_engineering/I2C protocol/traces/remote off.txt similarity index 100% rename from doc/I2C protocol/traces/remote off.txt rename to doc/reverse_engineering/I2C protocol/traces/remote off.txt diff --git a/doc/I2C protocol/traces/remote on.txt b/doc/reverse_engineering/I2C protocol/traces/remote on.txt similarity index 100% rename from doc/I2C protocol/traces/remote on.txt rename to doc/reverse_engineering/I2C protocol/traces/remote on.txt diff --git a/doc/I2C protocol/traces/slider slide 1% to 100%.txt b/doc/reverse_engineering/I2C protocol/traces/slider slide 1% to 100%.txt similarity index 100% rename from doc/I2C protocol/traces/slider slide 1% to 100%.txt rename to doc/reverse_engineering/I2C protocol/traces/slider slide 1% to 100%.txt diff --git a/doc/I2C protocol/traces/slider touch - release at about 30%.txt b/doc/reverse_engineering/I2C protocol/traces/slider touch - release at about 30%.txt similarity index 100% rename from doc/I2C protocol/traces/slider touch - release at about 30%.txt rename to doc/reverse_engineering/I2C protocol/traces/slider touch - release at about 30%.txt diff --git a/doc/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt b/doc/reverse_engineering/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt similarity index 100% rename from doc/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt rename to doc/reverse_engineering/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt diff --git a/doc/IC connected to I2C on GPIO 17+18.xcf b/doc/reverse_engineering/IC connected to I2C on GPIO 17+18.xcf similarity index 100% rename from doc/IC connected to I2C on GPIO 17+18.xcf rename to doc/reverse_engineering/IC connected to I2C on GPIO 17+18.xcf diff --git a/doc/Original firmware boot messages.txt b/doc/reverse_engineering/Original firmware boot messages.txt similarity index 100% rename from doc/Original firmware boot messages.txt rename to doc/reverse_engineering/Original firmware boot messages.txt diff --git a/doc/PulseView setup for RGB tests.pvs b/doc/reverse_engineering/PulseView setup for RGB tests.pvs similarity index 100% rename from doc/PulseView setup for RGB tests.pvs rename to doc/reverse_engineering/PulseView setup for RGB tests.pvs diff --git a/doc/RGB_mapping.py b/doc/reverse_engineering/RGB_mapping.py similarity index 100% rename from doc/RGB_mapping.py rename to doc/reverse_engineering/RGB_mapping.py diff --git a/doc/Reboot crashes on ESPHome.txt b/doc/reverse_engineering/Reboot crashes on ESPHome.txt similarity index 100% rename from doc/Reboot crashes on ESPHome.txt rename to doc/reverse_engineering/Reboot crashes on ESPHome.txt diff --git a/doc/Trace bottom left.xcf b/doc/reverse_engineering/Trace bottom left.xcf similarity index 100% rename from doc/Trace bottom left.xcf rename to doc/reverse_engineering/Trace bottom left.xcf diff --git a/doc/Trace bottom right.xcf b/doc/reverse_engineering/Trace bottom right.xcf similarity index 100% rename from doc/Trace bottom right.xcf rename to doc/reverse_engineering/Trace bottom right.xcf diff --git a/doc/Trace for IC connected to I2C on GPIO 17+18.xcf b/doc/reverse_engineering/Trace for IC connected to I2C on GPIO 17+18.xcf similarity index 100% rename from doc/Trace for IC connected to I2C on GPIO 17+18.xcf rename to doc/reverse_engineering/Trace for IC connected to I2C on GPIO 17+18.xcf diff --git a/doc/Trace front panel connector.xcf b/doc/reverse_engineering/Trace front panel connector.xcf similarity index 100% rename from doc/Trace front panel connector.xcf rename to doc/reverse_engineering/Trace front panel connector.xcf diff --git a/doc/Trace top left.xcf b/doc/reverse_engineering/Trace top left.xcf similarity index 100% rename from doc/Trace top left.xcf rename to doc/reverse_engineering/Trace top left.xcf diff --git a/doc/Trace top right.xcf b/doc/reverse_engineering/Trace top right.xcf similarity index 100% rename from doc/Trace top right.xcf rename to doc/reverse_engineering/Trace top right.xcf diff --git a/doc/Yeelight GPIO measurements.xlsx b/doc/reverse_engineering/Yeelight GPIO measurements.xlsx similarity index 100% rename from doc/Yeelight GPIO measurements.xlsx rename to doc/reverse_engineering/Yeelight GPIO measurements.xlsx diff --git a/example-device.yaml b/example-device.yaml deleted file mode 100644 index 864f255..0000000 --- a/example-device.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# Some substitutions as used by the included yaml file. - -substitutions: - name: bedside_lamp_office - friendly_name: Bedside Lamp Office - -# Configuration options to connect the device to the network. -# The api is used for allowing connections from Home Assistant. -# The ota is used for over the air updates after the first deployment. - -wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password - - ap: - ssid: ${friendly_name} - password: !secret wifi_ap_fallback_password - -captive_portal: - -api: - password: !secret api_password - -ota: - password: !secret ota_password - -# The rest of the configuration is included. - -<<: !include esphome-yeelight_bs2/yeelight_bs2.yaml diff --git a/library.json b/library.json deleted file mode 100644 index 4982d49..0000000 --- a/library.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "esphome-YeelightBS2", - "version": "0.0.2", - "description": "ESPHome components to fully control a Yeelight Bedside Lamp v2 device.", - "keywords": "esphome, yeelight, bedside", - "repository": - { - "type": "git", - "url": "https://github.com/mmakaay/esphome-yeelight_bs2.git" - }, - "authors": - [ - { - "name": "Maurice Makaay", - "email": "account-github-yeelight_bs2@makaay.nl", - "maintainer": true - } - ], - "license": "LGPL-3.0", - "frameworks": "arduino", - "platforms": "espressif32", - "homepage": "https://github.com/mmakaay/esphome-yeelight_bs2.git" -} diff --git a/light.py b/light.py new file mode 100644 index 0000000..08fff07 --- /dev/null +++ b/light.py @@ -0,0 +1,41 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import light, output, gpio +from esphome.const import CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_OUTPUT_ID + + +CONF_MASTER1 = "master1" +CONF_MASTER2 = "master2" + +rgbww_ns = cg.esphome_ns.namespace("rgbww") +YeelightBS2LightOutput = rgbww_ns.class_("YeelightBS2LightOutput", light.LightOutput) + +CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend( + { + cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(YeelightBS2LightOutput), + cv.Required(CONF_RED): cv.use_id(output.FloatOutput), + cv.Required(CONF_GREEN): cv.use_id(output.FloatOutput), + cv.Required(CONF_BLUE): cv.use_id(output.FloatOutput), + cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput), + cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput), + cv.Required(CONF_MASTER1): cv.use_id(gpio.output.GPIOBinaryOutput), + cv.Required(CONF_MASTER2): cv.use_id(gpio.output.GPIOBinaryOutput), + } +) + +def to_code(config): + var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) + yield light.register_light(var, config) + + red = yield cg.get_variable(config[CONF_RED]) + cg.add(var.set_red(red)) + green = yield cg.get_variable(config[CONF_GREEN]) + cg.add(var.set_green(green)) + blue = yield cg.get_variable(config[CONF_BLUE]) + cg.add(var.set_blue(blue)) + white = yield cg.get_variable(config[CONF_WHITE]) + cg.add(var.set_white(white)) + master1 = yield cg.get_variable(config[CONF_MASTER1]) + cg.add(var.set_master1(master1)) + master2 = yield cg.get_variable(config[CONF_MASTER2]) + cg.add(var.set_master2(master2)) diff --git a/yeelight_bs2.yaml b/yeelight_bs2.yaml deleted file mode 100644 index e8467c4..0000000 --- a/yeelight_bs2.yaml +++ /dev/null @@ -1,69 +0,0 @@ -esphome: - name: $name - platform: ESP32 - board: esp32doit-devkit-v1 - platformio_options: - platform: espressif32@1.11.0 - platform_packages: |-4 - framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.4 - includes: - - esphome-yeelight_bs2/yeelight_bs2.h - -# Enable logging -logger: - -# The front panel of the device uses I2C for communication -# with the ESP32 main board. The panel uses address 0x2C. -# There are two I2C busses attached to the ESP32: -# SDA 17/SCL 18 and SDA 21/SCL 19. The latter is the -# correct one for the front panel. The former is probably -# an EEPROM of some sorts. -i2c: - - id: eeprom_i2c - sda: 17 - scl: 18 - scan: True - - id: front_panel_i2c - sda: 21 - scl: 19 - scan: True - -output: - - platform: gpio - id: master1 - pin: GPIO33 - - platform: gpio - id: master2 - pin: GPIO4 - - platform: ledc - id: led_r - pin: GPIO13 - - platform: ledc - id: led_g - pin: GPIO14 - - platform: ledc - id: led_b - pin: GPIO5 - - platform: ledc - id: led_w - pin: GPIO12 - -light: - - platform: custom - lambda: |- - auto bs2light = new esphome::rgbww::YeelightBedsideLampV2LightOutput( - led_r, led_g, led_b, led_w, master1, master2); - App.register_component(bs2light); - return {bs2light}; - lights: - - name: ${friendly_name} RGBW Light - default_transition_length: 0s - effects: - - random: - name: "Slow Random" - transition_length: 30s - update_interval: 30s - - random: - name: "Fast Random" - transition_length: 3s - update_interval: 4s diff --git a/src/YeelightBedsideLampV2LightOutput.h b/yeelight_bs2_light_output.h similarity index 91% rename from src/YeelightBedsideLampV2LightOutput.h rename to yeelight_bs2_light_output.h index 40cdd47..e4df994 100644 --- a/src/YeelightBedsideLampV2LightOutput.h +++ b/yeelight_bs2_light_output.h @@ -1,6 +1,9 @@ #pragma once -#include "esphome.h" +#include "esphome/core/component.h" +#include "esphome/components/output/float_output.h" +#include "esphome/components/light/light_output.h" +#include "esphome/components/gpio/output/gpio_binary_output.h" #define CONSTANT_BRIGHTNESS true @@ -22,17 +25,19 @@ namespace esphome { namespace rgbww { - - class YeelightBedsideLampV2LightOutput : public Component, public LightOutput + class YeelightBS2LightOutput : public Component, public light::LightOutput { public: - YeelightBedsideLampV2LightOutput( - FloatOutput *r, FloatOutput *g, FloatOutput *b, FloatOutput *w, - esphome::gpio::GPIOBinaryOutput *m1, esphome::gpio::GPIOBinaryOutput *m2) : red_(r), green_(g), blue_(b), white_(w), master1_(m1), master2_(m2) {} - - LightTraits get_traits() override + void set_red(output::FloatOutput *red) { red_ = red; } + void set_green(output::FloatOutput *green) { green_ = green; } + void set_blue(output::FloatOutput *blue) { blue_ = blue; } + void set_white(output::FloatOutput *white) { white_ = white; } + void set_master1(gpio::GPIOBinaryOutput *master1) { master1_ = master1; } + void set_master2(gpio::GPIOBinaryOutput *master2) { master2_ = master2; } + + light::LightTraits get_traits() override { - auto traits = LightTraits(); + auto traits = light::LightTraits(); traits.set_supports_rgb(true); traits.set_supports_color_temperature(true); traits.set_supports_brightness(true); @@ -43,7 +48,7 @@ namespace esphome return traits; } - void write_state(LightState *state) override + void write_state(light::LightState *state) override { auto values = state->current_values; @@ -103,11 +108,11 @@ namespace esphome } } - private: - FloatOutput *red_; - FloatOutput *green_; - FloatOutput *blue_; - FloatOutput *white_; + protected: + output::FloatOutput *red_; + output::FloatOutput *green_; + output::FloatOutput *blue_; + output::FloatOutput *white_; esphome::gpio::GPIOBinaryOutput *master1_; esphome::gpio::GPIOBinaryOutput *master2_; // Used for a bug hack.