|
@ -2,19 +2,21 @@ import esphome.codegen as cg |
|
|
import esphome.config_validation as cv |
|
|
import esphome.config_validation as cv |
|
|
from esphome.components import output |
|
|
from esphome.components import output |
|
|
from esphome.const import CONF_ID |
|
|
from esphome.const import CONF_ID |
|
|
|
|
|
from esphome import automation |
|
|
from .. import ( |
|
|
from .. import ( |
|
|
bslamp2_ns, CODEOWNERS, |
|
|
bslamp2_ns, CODEOWNERS, |
|
|
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL |
|
|
|
|
|
|
|
|
CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL, CONF_LEDS |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
AUTO_LOAD = ["xiaomi_bslamp2"] |
|
|
AUTO_LOAD = ["xiaomi_bslamp2"] |
|
|
|
|
|
|
|
|
XiaomiBslamp2FrontPanelLight = bslamp2_ns.class_( |
|
|
|
|
|
"XiaomiBslamp2FrontPanelLight", output.FloatOutput, cg.Component) |
|
|
|
|
|
|
|
|
XiaomiBslamp2FrontPanelOutput = bslamp2_ns.class_( |
|
|
|
|
|
"XiaomiBslamp2FrontPanelOutput", output.FloatOutput, cg.Component) |
|
|
|
|
|
SetLEDsAction = bslamp2_ns.class_("SetLEDsAction", automation.Action) |
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( |
|
|
CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( |
|
|
{ |
|
|
{ |
|
|
cv.GenerateID(): cv.declare_id(XiaomiBslamp2FrontPanelLight), |
|
|
|
|
|
|
|
|
cv.GenerateID(): cv.declare_id(XiaomiBslamp2FrontPanelOutput), |
|
|
cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.use_id(FrontPanelHAL), |
|
|
cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.use_id(FrontPanelHAL), |
|
|
} |
|
|
} |
|
|
).extend(cv.COMPONENT_SCHEMA) |
|
|
).extend(cv.COMPONENT_SCHEMA) |
|
@ -26,3 +28,28 @@ def to_code(config): |
|
|
|
|
|
|
|
|
front_panel_hal_var = yield cg.get_variable(config[CONF_FRONT_PANEL_HAL_ID]) |
|
|
front_panel_hal_var = yield cg.get_variable(config[CONF_FRONT_PANEL_HAL_ID]) |
|
|
cg.add(var.set_parent(front_panel_hal_var)) |
|
|
cg.add(var.set_parent(front_panel_hal_var)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_simple_leds_value(schema): |
|
|
|
|
|
def validator(value): |
|
|
|
|
|
if isinstance(value, dict): |
|
|
|
|
|
return schema(value) |
|
|
|
|
|
return schema({ "leds": value }) |
|
|
|
|
|
return validator |
|
|
|
|
|
|
|
|
|
|
|
@automation.register_action( |
|
|
|
|
|
"output.set_leds", |
|
|
|
|
|
SetLEDsAction, |
|
|
|
|
|
cv.Schema( |
|
|
|
|
|
maybe_simple_leds_value(cv.Schema({ |
|
|
|
|
|
cv.GenerateID(CONF_ID): cv.use_id(XiaomiBslamp2FrontPanelOutput), |
|
|
|
|
|
cv.Required(CONF_LEDS): cv.templatable(cv.uint16_t), |
|
|
|
|
|
})) |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
async def set_leds_to_code(config, action_id, template_arg, args): |
|
|
|
|
|
output_var = await cg.get_variable(config[CONF_ID]) |
|
|
|
|
|
var = cg.new_Pvariable(action_id, template_arg, output_var) |
|
|
|
|
|
template_ = await cg.templatable(config[CONF_LEDS], args, cg.uint16) |
|
|
|
|
|
cg.add(var.set_leds(template_)) |
|
|
|
|
|
return var |