Browse Source

Improved config structure.

pull/56/head
Maurice Makaay 3 years ago
parent
commit
650115e7e2
5 changed files with 41 additions and 41 deletions
  1. +33
    -32
      components/xiaomi_bslamp2/__init__.py
  2. +1
    -1
      components/xiaomi_bslamp2/binary_sensor/__init__.py
  3. +2
    -4
      components/xiaomi_bslamp2/light/__init__.py
  4. +4
    -3
      components/xiaomi_bslamp2/output/__init__.py
  5. +1
    -1
      components/xiaomi_bslamp2/sensor/__init__.py

+ 33
- 32
components/xiaomi_bslamp2/__init__.py View File

@ -5,23 +5,17 @@ from esphome.components.ledc.output import LEDCOutput
from esphome.components.gpio.output import GPIOBinaryOutput from esphome.components.gpio.output import GPIOBinaryOutput
from esphome.components.i2c import I2CBus, I2CDevice from esphome.components.i2c import I2CBus, I2CDevice
from esphome.const import ( 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"] CODEOWNERS = ["@mmakaay"]
CONF_MASTER1 = "master1" CONF_MASTER1 = "master1"
CONF_MASTER2 = "master2" 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_LIGHT_HAL_ID = "light_hal_id"
CONF_FRONT_PANEL_HAL_ID = "front_panel_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") xiaomi_ns = cg.esphome_ns.namespace("xiaomi")
bslamp2_ns = xiaomi_ns.namespace("bslamp2") bslamp2_ns = xiaomi_ns.namespace("bslamp2")
@ -48,40 +42,47 @@ FRONT_PANEL_LED_OPTIONS = {
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({ CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
# RGBWW Light # 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 # 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): 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) 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): 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) 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)) 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_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): async def to_code(config):
await make_light_hal(config) await make_light_hal(config)


+ 1
- 1
components/xiaomi_bslamp2/binary_sensor/__init__.py View File

@ -8,7 +8,7 @@ from .. import (
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL
) )
AUTO_LOAD = ["xiaomi_bslamp2"]
DEPENDENCIES = ["xiaomi_bslamp2"]
CONF_PART = "part" CONF_PART = "part"


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

@ -10,17 +10,15 @@ from esphome.const import (
) )
from .. import bslamp2_ns, CODEOWNERS, CONF_LIGHT_HAL_ID, LightHAL from .. import bslamp2_ns, CODEOWNERS, CONF_LIGHT_HAL_ID, LightHAL
AUTO_LOAD = ["xiaomi_bslamp2"]
DEPENDENCIES = ["xiaomi_bslamp2"]
CONF_MASTER1 = "master1"
CONF_MASTER2 = "master2"
CONF_ON_BRIGHTNESS = "on_brightness" CONF_ON_BRIGHTNESS = "on_brightness"
CONF_PRESET_ID = "preset_id" CONF_PRESET_ID = "preset_id"
CONF_PRESETS_ID = "presets_id" CONF_PRESETS_ID = "presets_id"
CONF_PRESET = "preset"
CONF_PRESETS = "presets" CONF_PRESETS = "presets"
CONF_NEXT = "next" CONF_NEXT = "next"
CONF_GROUP = "group" CONF_GROUP = "group"
CONF_PRESET = "preset"
MIRED_MIN = 153 MIRED_MIN = 153
MIRED_MAX = 588 MIRED_MAX = 588


+ 4
- 3
components/xiaomi_bslamp2/output/__init__.py View File

@ -5,11 +5,12 @@ from esphome.const import CONF_ID, CONF_LEVEL
from esphome import automation from esphome import automation
from .. import ( from .. import (
bslamp2_ns, CODEOWNERS, bslamp2_ns, CODEOWNERS,
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL, FRONT_PANEL_LED_OPTIONS,
CONF_LEDS
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL, FRONT_PANEL_LED_OPTIONS
) )
AUTO_LOAD = ["xiaomi_bslamp2"]
CONF_LEDS = "leds"
DEPENDENCIES = ["xiaomi_bslamp2"]
XiaomiBslamp2FrontPanelOutput = bslamp2_ns.class_( XiaomiBslamp2FrontPanelOutput = bslamp2_ns.class_(
"XiaomiBslamp2FrontPanelOutput", output.FloatOutput, cg.Component) "XiaomiBslamp2FrontPanelOutput", output.FloatOutput, cg.Component)


+ 1
- 1
components/xiaomi_bslamp2/sensor/__init__.py View File

@ -7,7 +7,7 @@ from .. import (
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL
) )
AUTO_LOAD = ["xiaomi_bslamp2"]
DEPENDENCIES = ["xiaomi_bslamp2"]
XiaomiBslamp2SliderSensor = bslamp2_ns.class_( XiaomiBslamp2SliderSensor = bslamp2_ns.class_(
"XiaomiBslamp2SliderSensor", sensor.Sensor, cg.Component) "XiaomiBslamp2SliderSensor", sensor.Sensor, cg.Component)


Loading…
Cancel
Save