ESPHome 2025.10.0-dev
Loading...
Searching...
No Matches
binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8
9namespace esphome {
10
11namespace binary_sensor {
12
13class BinarySensor;
14void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj);
15
16#define LOG_BINARY_SENSOR(prefix, type, obj) log_binary_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
17
18#define SUB_BINARY_SENSOR(name) \
19 protected: \
20 binary_sensor::BinarySensor *name##_binary_sensor_{nullptr}; \
21\
22 public: \
23 void set_##name##_binary_sensor(binary_sensor::BinarySensor *binary_sensor) { \
24 this->name##_binary_sensor_ = binary_sensor; \
25 }
26
34 public:
35 explicit BinarySensor(){};
36
41 void publish_state(bool new_state);
42
48 void publish_initial_state(bool new_state);
49
50 void add_filter(Filter *filter);
51 void add_filters(const std::vector<Filter *> &filters);
52
53 // ========== INTERNAL METHODS ==========
54 // (In most use cases you won't need these)
55 void send_state_internal(bool new_state);
56
58 virtual bool is_status_binary_sensor() const;
59
60 // For backward compatibility, provide an accessible property
61
62 bool state{};
63
64 protected:
66};
67
69 public:
70 bool has_state() const override { return true; }
71};
72
73} // namespace binary_sensor
74} // namespace esphome
An entity that has a state.
Base class for all binary_sensor-type classes.
void add_filters(const std::vector< Filter * > &filters)
void publish_state(bool new_state)
Publish a new state to the front-end.
void publish_initial_state(bool new_state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
virtual bool is_status_binary_sensor() const
Return whether this binary sensor has outputted a state.
uint16_t type
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7