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

DEPENDENCIES = ["hauslane"]

HauslaneFan = hauslane_ns.class_(
	"HauslaneFan", fan.Fan, HauslaneChild
)

CONFIG_SCHEMA = (
	fan.FAN_SCHEMA.extend({
		cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(HauslaneFan),
	})
	.extend(HAUSLANE_SCHEMA)
)

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

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