mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-02 02:58:26 +02:00
add person sensor (SEN21231) from usefulsensors (#4454)
* add person sensor (SEN21231) from usefulsensors * add person sensor (SEN21231) from usefulsensors * change file mode * fix tests * fix tests * rollback un-intended changes * Update esphome/components/sen21231/sen21231.cpp Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.cpp Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.cpp Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.cpp Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.cpp Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.h Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * remove unused import * Update esphome/components/sen21231/sen21231.h Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.h Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/sen21231/sen21231.h Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * remove unused import * Update sen21231.h * lint changes * linting * linting * Update sen21231.h * Update sen21231.cpp linting * linting fixes * fix codeowners --------- Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include "sen21231.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace sen21231_sensor {
|
||||
|
||||
static const char *const TAG = "sen21231_sensor.sensor";
|
||||
|
||||
void Sen21231Sensor::update() { this->read_data_(); }
|
||||
|
||||
void Sen21231Sensor::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "SEN21231:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with SEN21231 failed!");
|
||||
}
|
||||
ESP_LOGI(TAG, "SEN21231: %s", this->is_failed() ? "FAILED" : "OK");
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
void Sen21231Sensor::read_data_() {
|
||||
person_sensor_results_t results;
|
||||
this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results));
|
||||
ESP_LOGD(TAG, "SEN21231: %d faces detected", results.num_faces);
|
||||
this->publish_state(results.num_faces);
|
||||
if (results.num_faces == 1) {
|
||||
ESP_LOGD(TAG, "SEN21231: is facing towards camera: %d", results.faces[0].is_facing);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sen21231_sensor
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user