|
|
@ -5,23 +5,17 @@ from esphome.components.ledc.output import LEDCOutput |
|
|
|
from esphome.components.gpio.output import GPIOBinaryOutput |
|
|
|
from esphome.components.i2c import I2CBus, I2CDevice |
|
|
|
from esphome.const import ( |
|
|
|
CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, |
|
|
|
CONF_TRIGGER_PIN, CONF_SDA, CONF_SCL, CONF_ADDRESS |
|
|
|
CONF_LIGHT, CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, |
|
|
|
CONF_I2C, CONF_ADDRESS, CONF_TRIGGER_PIN, CONF_ID |
|
|
|
) |
|
|
|
|
|
|
|
# TODO subsection in config for leds and front_panel. |
|
|
|
|
|
|
|
CODEOWNERS = ["@mmakaay"] |
|
|
|
|
|
|
|
CONF_MASTER1 = "master1" |
|
|
|
CONF_MASTER2 = "master2" |
|
|
|
CONF_FP_I2C = "fp_i2c" |
|
|
|
CONF_FP_I2C_ADDRESS = "fp_i2c_address" |
|
|
|
CONF_FP_TRIGGER_PIN = "fp_trigger_pin" |
|
|
|
CONF_FRONT_PANEL = "front_panel" |
|
|
|
CONF_LIGHT_HAL_ID = "light_hal_id" |
|
|
|
CONF_FRONT_PANEL_HAL_ID = "front_panel_hal_id" |
|
|
|
CONF_ON_BRIGHTNESS = "on_brightness" |
|
|
|
CONF_LEDS = "leds" |
|
|
|
|
|
|
|
xiaomi_ns = cg.esphome_ns.namespace("xiaomi") |
|
|
|
bslamp2_ns = xiaomi_ns.namespace("bslamp2") |
|
|
@ -48,40 +42,47 @@ FRONT_PANEL_LED_OPTIONS = { |
|
|
|
|
|
|
|
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({ |
|
|
|
# RGBWW Light |
|
|
|
cv.GenerateID(CONF_LIGHT_HAL_ID): cv.declare_id(LightHAL), |
|
|
|
cv.Required(CONF_RED): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_GREEN): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_BLUE): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_WHITE): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_MASTER1): cv.use_id(GPIOBinaryOutput), |
|
|
|
cv.Required(CONF_MASTER2): cv.use_id(GPIOBinaryOutput), |
|
|
|
|
|
|
|
cv.Required(CONF_LIGHT): cv.Schema( |
|
|
|
{ |
|
|
|
cv.GenerateID(CONF_LIGHT_HAL_ID): cv.declare_id(LightHAL), |
|
|
|
cv.Required(CONF_RED): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_GREEN): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_BLUE): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_WHITE): cv.use_id(LEDCOutput), |
|
|
|
cv.Required(CONF_MASTER1): cv.use_id(GPIOBinaryOutput), |
|
|
|
cv.Required(CONF_MASTER2): cv.use_id(GPIOBinaryOutput), |
|
|
|
} |
|
|
|
), |
|
|
|
# Front panel I2C |
|
|
|
cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.declare_id(FrontPanelHAL), |
|
|
|
cv.Required(CONF_FP_I2C): cv.use_id(I2CBus), |
|
|
|
cv.Required(CONF_FP_I2C_ADDRESS): cv.i2c_address, |
|
|
|
cv.Required(CONF_FP_TRIGGER_PIN): cv.All(pins.internal_gpio_input_pin_schema) |
|
|
|
cv.Required(CONF_FRONT_PANEL): cv.Schema( |
|
|
|
{ |
|
|
|
cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.declare_id(FrontPanelHAL), |
|
|
|
cv.Required(CONF_I2C): cv.use_id(I2CBus), |
|
|
|
cv.Required(CONF_ADDRESS): cv.i2c_address, |
|
|
|
cv.Required(CONF_TRIGGER_PIN): cv.All(pins.internal_gpio_input_pin_schema) |
|
|
|
} |
|
|
|
), |
|
|
|
}) |
|
|
|
|
|
|
|
async def make_light_hal(config): |
|
|
|
light_hal = cg.new_Pvariable(config[CONF_LIGHT_HAL_ID]) |
|
|
|
light_hal = cg.new_Pvariable(config[CONF_LIGHT][CONF_LIGHT_HAL_ID]) |
|
|
|
await cg.register_component(light_hal, config) |
|
|
|
cg.add(light_hal.set_red_pin(await cg.get_variable(config[CONF_RED]))) |
|
|
|
cg.add(light_hal.set_green_pin(await cg.get_variable(config[CONF_GREEN]))) |
|
|
|
cg.add(light_hal.set_blue_pin(await cg.get_variable(config[CONF_BLUE]))) |
|
|
|
cg.add(light_hal.set_white_pin(await cg.get_variable(config[CONF_WHITE]))) |
|
|
|
cg.add(light_hal.set_master1_pin(await cg.get_variable(config[CONF_MASTER1]))) |
|
|
|
cg.add(light_hal.set_master2_pin(await cg.get_variable(config[CONF_MASTER2]))) |
|
|
|
cg.add(light_hal.set_red_pin(await cg.get_variable(config[CONF_LIGHT][CONF_RED]))) |
|
|
|
cg.add(light_hal.set_green_pin(await cg.get_variable(config[CONF_LIGHT][CONF_GREEN]))) |
|
|
|
cg.add(light_hal.set_blue_pin(await cg.get_variable(config[CONF_LIGHT][CONF_BLUE]))) |
|
|
|
cg.add(light_hal.set_white_pin(await cg.get_variable(config[CONF_LIGHT][CONF_WHITE]))) |
|
|
|
cg.add(light_hal.set_master1_pin(await cg.get_variable(config[CONF_LIGHT][CONF_MASTER1]))) |
|
|
|
cg.add(light_hal.set_master2_pin(await cg.get_variable(config[CONF_LIGHT][CONF_MASTER2]))) |
|
|
|
|
|
|
|
async def make_front_panel_hal(config): |
|
|
|
fp_hal = cg.new_Pvariable(config[CONF_FRONT_PANEL_HAL_ID]) |
|
|
|
fp_hal = cg.new_Pvariable(config[CONF_FRONT_PANEL][CONF_FRONT_PANEL_HAL_ID]) |
|
|
|
await cg.register_component(fp_hal, config) |
|
|
|
trigger_pin = await cg.gpio_pin_expression(config[CONF_FP_TRIGGER_PIN]) |
|
|
|
trigger_pin = await cg.gpio_pin_expression(config[CONF_FRONT_PANEL][CONF_TRIGGER_PIN]) |
|
|
|
cg.add(fp_hal.set_trigger_pin(trigger_pin)) |
|
|
|
|
|
|
|
fp_i2c_var = await cg.get_variable(config[CONF_FP_I2C]) |
|
|
|
fp_i2c_var = await cg.get_variable(config[CONF_FRONT_PANEL][CONF_I2C]) |
|
|
|
cg.add(fp_hal.set_i2c_bus(fp_i2c_var)) |
|
|
|
cg.add(fp_hal.set_i2c_address(config[CONF_FP_I2C_ADDRESS])) |
|
|
|
cg.add(fp_hal.set_i2c_address(config[CONF_FRONT_PANEL][CONF_ADDRESS])) |
|
|
|
|
|
|
|
async def to_code(config): |
|
|
|
await make_light_hal(config) |
|
|
|