import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import light
from esphome.const import CONF_OUTPUT_ID
from . import (
	HAUSLANE_SCHEMA,
	CONF_HAUSLANE_ID,
	HauslaneChild,
	hauslane_ns,
)

DEPENDENCIES = ["hauslane"]

HauslaneLight = hauslane_ns.class_(
	"HauslaneLight", light.LightOutput, HauslaneChild
)

CONFIG_SCHEMA = (
	light.LIGHT_SCHEMA.extend({
		cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(HauslaneLight),
	})
	.extend(HAUSLANE_SCHEMA)
)

async def to_code(config):
	var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
	await light.register_light(var,config)

	paren = await cg.get_variable(config[CONF_HAUSLANE_ID])
	cg.add(var.set_parent(paren))
	cg.add(var.setup())
