import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import climate, remote_transmitter

CONF_TRANSMITTER_ID = "transmitter_id"

gree_ir_ns = cg.esphome_ns.namespace("gree_ir")
GreeIR = gree_ir_ns.class_("GreeIR", climate.Climate, cg.Component)

CONFIG_SCHEMA = climate.climate_schema(GreeIR).extend({
    cv.Required(CONF_TRANSMITTER_ID): cv.use_id(
        remote_transmitter.RemoteTransmitterComponent
    ),
}).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    var = await climate.new_climate(config)
    await cg.register_component(var, config)
    tx = await cg.get_variable(config[CONF_TRANSMITTER_ID])
    cg.add(var.set_transmitter(tx))
