8#ifdef USE_ALARM_CONTROL_PANEL
17PROGMEM_STRING_TABLE(AlarmMqttStateStrings,
"disarmed",
"armed_home",
"armed_away",
"armed_night",
"armed_vacation",
18 "armed_custom_bypass",
"pending",
"arming",
"disarming",
"triggered",
"unknown");
21 return AlarmMqttStateStrings::get_progmem_str(
static_cast<uint8_t
>(
state), AlarmMqttStateStrings::LAST_INDEX);
25 : alarm_control_panel_(alarm_control_panel) {}
28 if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"ARM_AWAY")) == 0) {
30 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"ARM_HOME")) == 0) {
32 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"ARM_NIGHT")) == 0) {
34 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"ARM_VACATION")) == 0) {
36 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"ARM_CUSTOM_BYPASS")) == 0) {
38 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"DISARM")) == 0) {
40 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"PENDING")) == 0) {
42 }
else if (ESPHOME_strcasecmp_P(
state, ESPHOME_PSTR(
"TRIGGERED")) == 0) {
55 if (!payload.empty() && payload[0] ==
'{') {
58 JsonObject root = doc.as<JsonObject>();
60 const char *
state = root[ESPHOME_F(
"state")];
61 if (
state ==
nullptr) {
62 ESP_LOGW(TAG,
"'%s': JSON payload missing 'state' key", LOG_STR_ARG(this->
log_name_()));
64 ESP_LOGW(TAG,
"'%s': Received unknown state in JSON payload: %s", LOG_STR_ARG(this->
log_name_()), state);
66 const char *code = root[ESPHOME_F(
"code")];
67 if (code !=
nullptr) {
72 }
else if (!apply_command(
call, payload.c_str())) {
73 ESP_LOGW(TAG,
"'%s': Received unknown command payload %s", LOG_STR_ARG(this->
log_name_()), payload.c_str());
80 LOG_MQTT_COMPONENT(
true,
true);
82 " Supported Features: %" PRIu32
"\n"
83 " Requires Code to Disarm: %s\n"
84 " Requires Code To Arm: %s",
92 JsonArray supported_features = root[MQTT_SUPPORTED_FEATURES].to<JsonArray>();
95 supported_features.add(ESPHOME_F(
"arm_away"));
98 supported_features.add(ESPHOME_F(
"arm_home"));
101 supported_features.add(ESPHOME_F(
"arm_night"));
104 supported_features.add(ESPHOME_F(
"arm_vacation"));
107 supported_features.add(ESPHOME_F(
"arm_custom_bypass"));
110 supported_features.add(ESPHOME_F(
"trigger"));
121 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
AlarmControlPanelCall & triggered()
AlarmControlPanelCall & arm_night()
AlarmControlPanelCall & disarm()
AlarmControlPanelCall & arm_custom_bypass()
AlarmControlPanelCall & arm_away()
AlarmControlPanelCall & pending()
AlarmControlPanelCall & arm_home()
AlarmControlPanelCall & arm_vacation()
void add_on_state_callback(F &&callback)
Add a callback for when the state of the alarm_control_panel changes.
virtual uint32_t get_supported_features() const =0
A numeric representation of the supported features as per HomeAssistant.
AlarmControlPanelState get_state() const
Get the state.
virtual bool get_requires_code_to_arm() const =0
Returns if the alarm_control_panel requires a code to arm.
virtual bool get_requires_code() const =0
Returns if the alarm_control_panel has a code.
AlarmControlPanelCall make_call()
Make a AlarmControlPanelCall.
MQTTAlarmControlPanelComponent(alarm_control_panel::AlarmControlPanel *alarm_control_panel)
bool send_initial_state() override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
alarm_control_panel::AlarmControlPanel * alarm_control_panel_
void dump_config() override
const LogString * log_name_() const
Entity name for a "%s" log argument.
void subscribe(T &&topic, F &&callback, uint8_t qos=0)
Subscribe to a MQTT topic.
MQTTTopicSource command_topic_source_() const
The command topic as a subscription source. A lambda topic is read once and copied,...
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
StringRef get_state_topic_to_(std::span< char, MQTT_DEFAULT_TOPIC_MAX_LEN > buf) const
Get the MQTT state topic into a buffer (no heap allocation for non-lambda custom topics).
PROGMEM_STRING_TABLE(AlarmControlPanelStateStrings, "DISARMED", "ARMED_HOME", "ARMED_AWAY", "ARMED_NIGHT", "ARMED_VACATION", "ARMED_CUSTOM_BYPASS", "PENDING", "ARMING", "DISARMING", "TRIGGERED", "UNKNOWN")
@ ACP_FEAT_ARM_CUSTOM_BYPASS
ESPHOME_LOG_TAG(TAG, "alarm_control_panel")
bool parse_json(const std::string &data, const json_parse_t &f)
Parse a JSON string and run the provided json parse function if it's valid.
MQTT_COMPONENT_TYPE(MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
const __FlashStringHelper * ProgmemStr
Simple Helper struct used for Home Assistant MQTT send_discovery().