Now properly sends light state back to HA

This commit is contained in:
2024-04-29 13:49:12 +02:00
parent ef7144ebc1
commit 26341e075a
5 changed files with 214 additions and 100 deletions

View File

@ -1,18 +1,22 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import output
from esphome.components import output, light
from esphome.const import CONF_ID
hoermann_cover_ns = cg.esphome_ns.namespace('hoermann_door')
HoermannCoverLight = hoermann_cover_ns.class_('NbsLightOutput', output.BinaryOutput, cg.Component)
CONF_STATE_CALLBACK = "state_callback"
CONFIG_SCHEMA = output.BINARY_OUTPUT_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(HoermannCoverLight)
cv.GenerateID(CONF_ID): cv.declare_id(HoermannCoverLight),
cv.Required(CONF_STATE_CALLBACK): cv.use_id(light.LightState)
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield output.register_output(var, config)
yield output.register_output(var, config)
callback = yield cg.get_variable(config[CONF_STATE_CALLBACK])
cg.add(var.set_state_callback(callback))