ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
emc2101_sensor.cpp
Go to the documentation of this file.
1#include "emc2101_sensor.h"
3#include "esphome/core/log.h"
4
5namespace esphome {
6namespace emc2101 {
7
8static const char *const TAG = "EMC2101.sensor";
9
11 ESP_LOGCONFIG(TAG, "Emc2101 sensor:");
12 LOG_SENSOR(" ", "Internal temperature", this->internal_temperature_sensor_);
13 LOG_SENSOR(" ", "External temperature", this->external_temperature_sensor_);
14 LOG_SENSOR(" ", "Speed", this->speed_sensor_);
15 LOG_SENSOR(" ", "Duty cycle", this->duty_cycle_sensor_);
16}
17
19 if (this->internal_temperature_sensor_ != nullptr) {
20 float internal_temperature = this->parent_->get_internal_temperature();
21 this->internal_temperature_sensor_->publish_state(internal_temperature);
22 }
23
24 if (this->external_temperature_sensor_ != nullptr) {
25 float external_temperature = this->parent_->get_external_temperature();
26 this->external_temperature_sensor_->publish_state(external_temperature);
27 }
28
29 if (this->speed_sensor_ != nullptr) {
30 float speed = this->parent_->get_speed();
31 this->speed_sensor_->publish_state(speed);
32 }
33
34 if (this->duty_cycle_sensor_ != nullptr) {
35 float duty_cycle = this->parent_->get_duty_cycle();
36 this->duty_cycle_sensor_->publish_state(duty_cycle * 100.0f);
37 }
38}
39
40} // namespace emc2101
41} // namespace esphome
void update() override
Used by ESPHome framework.
void dump_config() override
Used by ESPHome framework.
sensor::Sensor * internal_temperature_sensor_
sensor::Sensor * external_temperature_sensor_
float get_duty_cycle()
Gets the Fan output duty cycle.
Definition emc2101.cpp:119
float get_speed()
Gets the tachometer speed sensor reading.
Definition emc2101.cpp:154
float get_internal_temperature()
Gets the internal temperature sensor reading.
Definition emc2101.cpp:129
float get_external_temperature()
Gets the external temperature sensor reading.
Definition emc2101.cpp:139
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
int speed
Definition fan.h:3
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7