12 static const char *
const TAG =
"mqtt.lock";
20 if (strcasecmp(payload.c_str(),
"LOCK") == 0) {
22 }
else if (strcasecmp(payload.c_str(),
"UNLOCK") == 0) {
24 }
else if (strcasecmp(payload.c_str(),
"OPEN") == 0) {
27 ESP_LOGW(TAG,
"'%s': Received unknown status payload: %s", this->
friendly_name().c_str(), payload.c_str());
35 LOG_MQTT_COMPONENT(
true,
true);
constexpr const char *const MQTT_PAYLOAD_OPEN
LockState state
The current reported state of the lock.
const char * lock_state_to_string(LockState state)
void status_momentary_warning(const std::string &name, uint32_t length=5000)
std::string component_type() const override
"lock" component type.
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
constexpr const char *const MQTT_OPTIMISTIC
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
void add_on_state_callback(std::function< void()> &&callback)
Set callback for state changes.
void lock()
Turn this lock on.
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
Simple Helper struct used for Home Assistant MQTT send_discovery().
const EntityBase * get_entity() const override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool get_assumed_state() const
MQTTLockComponent(lock::Lock *a_lock)
constexpr const char * c_str() const
void open()
Open (unlatch) this lock.
bool send_initial_state() override
virtual std::string friendly_name() const
Get the friendly name of this MQTT component.
Implementation of SPI Controller mode.
void unlock()
Turn this lock off.
void dump_config() override
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
std::string get_command_topic_() const
Get the MQTT topic for listening to commands.
bool get_supports_open() const
const StringRef & get_name() const
Base class for all locks.