ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
matrix_keypad_binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
5
7
9 public:
10 MatrixKeypadBinarySensor(uint8_t key) : has_key_(true), key_(key){};
11 MatrixKeypadBinarySensor(const char *key) : has_key_(true), key_((uint8_t) key[0]){};
12 MatrixKeypadBinarySensor(int row, int col) : has_key_(false), row_(row), col_(col){};
13
14 void key_pressed(uint8_t key) override {
15 if (!this->has_key_)
16 return;
17 if (key == this->key_)
18 this->publish_state(true);
19 }
20
21 void key_released(uint8_t key) override {
22 if (!this->has_key_)
23 return;
24 if (key == this->key_)
25 this->publish_state(false);
26 }
27
28 void button_pressed(int row, int col) override {
29 if (this->has_key_)
30 return;
31 if ((row == this->row_) && (col == this->col_))
32 this->publish_state(true);
33 }
34
35 void button_released(int row, int col) override {
36 if (this->has_key_)
37 return;
38 if ((row == this->row_) && (col == this->col_))
39 this->publish_state(false);
40 }
41
42 protected:
44 uint8_t key_;
45 int row_;
46 int col_;
47};
48
49} // namespace esphome::matrix_keypad
void publish_state(bool new_state)
Publish a new state to the front-end.