Fix multiple remote_receivers with triggers (#4477)

This commit is contained in:
Jesse Hills 2023-02-23 13:38:45 +13:00
parent 069b5f81a0
commit 7f46d9e0f9
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
2 changed files with 9 additions and 4 deletions

View file

@ -79,7 +79,9 @@ def register_trigger(name, type, data_type):
validator = automation.validate_automation( validator = automation.validate_automation(
{ {
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(type), cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(type),
cv.GenerateID(CONF_RECEIVER_ID): cv.use_id(RemoteReceiverBase), cv.Optional(CONF_RECEIVER_ID): cv.invalid(
"This has been removed in ESPHome 2022.3.0 and the trigger attaches directly to the parent receiver."
),
} }
) )
registerer = TRIGGER_REGISTRY.register(f"on_{name}", validator) registerer = TRIGGER_REGISTRY.register(f"on_{name}", validator)
@ -87,7 +89,6 @@ def register_trigger(name, type, data_type):
def decorator(func): def decorator(func):
async def new_func(config): async def new_func(config):
var = cg.new_Pvariable(config[CONF_TRIGGER_ID]) var = cg.new_Pvariable(config[CONF_TRIGGER_ID])
await register_listener(var, config)
await coroutine(func)(var, config) await coroutine(func)(var, config)
await automation.build_automation(var, [(data_type, "x")], config) await automation.build_automation(var, [(data_type, "x")], config)
return var return var
@ -223,10 +224,12 @@ async def build_binary_sensor(full_config):
async def build_triggers(full_config): async def build_triggers(full_config):
triggers = []
for key in TRIGGER_REGISTRY: for key in TRIGGER_REGISTRY:
for config in full_config.get(key, []): for config in full_config.get(key, []):
func = TRIGGER_REGISTRY[key][0] func = TRIGGER_REGISTRY[key][0]
await func(config) triggers.append(await func(config))
return triggers
async def build_dumpers(config): async def build_dumpers(config):

View file

@ -56,7 +56,9 @@ async def to_code(config):
for dumper in dumpers: for dumper in dumpers:
cg.add(var.register_dumper(dumper)) cg.add(var.register_dumper(dumper))
await remote_base.build_triggers(config) triggers = await remote_base.build_triggers(config)
for trigger in triggers:
cg.add(var.register_listener(trigger))
await cg.register_component(var, config) await cg.register_component(var, config)
cg.add(var.set_tolerance(config[CONF_TOLERANCE])) cg.add(var.set_tolerance(config[CONF_TOLERANCE]))