Skip to content

Commit 47cf5d0

Browse files
n-IA-haneClaude Opus 4.6 (1M context)
andcommitted
intercom_api: add destination_is native condition, reduce lambdas
New condition intercom_api.destination_is replaces lambda for checking current call destination: intercom_api.destination_is: id: intercom destination: "Home Assistant" Applied to generic-s3-duplex-va-intercom-sm-test.yaml. update_status lambda is justified: 12-priority LED state machine with change detection (g_applied_led) has no native YAML equivalent. Globals comparison (g_va_state, g_mww_recent, g_barge_in_pending) has no native conditions in ESPHome upstream. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 37c76d2 commit 47cf5d0

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎esphome/components/intercom_api/__init__.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
IntercomIsIncomingCondition = intercom_api_ns.class_("IntercomIsIncomingCondition", automation.Condition)
6363
IntercomIsAnsweringCondition = intercom_api_ns.class_("IntercomIsAnsweringCondition", automation.Condition)
6464
IntercomIsInCallCondition = intercom_api_ns.class_("IntercomIsInCallCondition", automation.Condition)
65+
IntercomDestinationIsCondition = intercom_api_ns.class_("IntercomDestinationIsCondition", automation.Condition)
6566

6667
def _aec_schema(value):
6768
"""Validate aec_id - import esp_aec only if used."""
@@ -496,3 +497,24 @@ async def intercom_is_in_call_to_code(config, condition_id, template_arg, args):
496497
parent = await cg.get_variable(config[CONF_ID])
497498
cg.add(var.set_parent(parent))
498499
return var
500+
501+
502+
CONF_DESTINATION = "destination"
503+
504+
@automation.register_condition(
505+
"intercom_api.destination_is",
506+
IntercomDestinationIsCondition,
507+
automation.maybe_simple_id(
508+
{
509+
cv.GenerateID(): cv.use_id(IntercomApi),
510+
cv.Required(CONF_DESTINATION): cv.templatable(cv.string),
511+
}
512+
),
513+
)
514+
async def intercom_destination_is_to_code(config, condition_id, template_arg, args):
515+
var = cg.new_Pvariable(condition_id, template_arg)
516+
parent = await cg.get_variable(config[CONF_ID])
517+
cg.add(var.set_parent(parent))
518+
templ = await cg.templatable(config[CONF_DESTINATION], args, cg.std_string)
519+
cg.add(var.set_destination(templ))
520+
return var

‎esphome/components/intercom_api/intercom_api.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,15 @@ class IntercomIsInCallCondition : public Condition<Ts...>, public Parented<Inter
604604
}
605605
};
606606

607+
template<typename... Ts>
608+
class IntercomDestinationIsCondition : public Condition<Ts...>, public Parented<IntercomApi> {
609+
public:
610+
TEMPLATABLE_VALUE(std::string, destination)
611+
bool check(const Ts &...x) override {
612+
return this->parent_->get_current_destination() == this->destination_.value(x...);
613+
}
614+
};
615+
607616
} // namespace intercom_api
608617
} // namespace esphome
609618

‎generic-s3-duplex-va-intercom-sm-test.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ intercom_api:
394394
- script.execute: update_status
395395
- if:
396396
condition:
397-
lambda: 'return id(intercom).get_current_destination() == "Home Assistant";'
397+
intercom_api.destination_is:
398+
id: intercom
399+
destination: "Home Assistant"
398400
then:
399401
- homeassistant.event:
400402
event: esphome.intercom_call

0 commit comments

Comments
 (0)