ESPHome  2024.11.1
emc2101_sensor.cpp
Go to the documentation of this file.
1 #include "emc2101_sensor.h"
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace emc2101 {
7 
8 static const char *const TAG = "EMC2101.sensor";
9 
11 
13  ESP_LOGCONFIG(TAG, "Emc2101 sensor:");
14  LOG_SENSOR(" ", "Internal temperature", this->internal_temperature_sensor_);
15  LOG_SENSOR(" ", "External temperature", this->external_temperature_sensor_);
16  LOG_SENSOR(" ", "Speed", this->speed_sensor_);
17  LOG_SENSOR(" ", "Duty cycle", this->duty_cycle_sensor_);
18 }
19 
21  if (this->internal_temperature_sensor_ != nullptr) {
22  float internal_temperature = this->parent_->get_internal_temperature();
23  this->internal_temperature_sensor_->publish_state(internal_temperature);
24  }
25 
26  if (this->external_temperature_sensor_ != nullptr) {
27  float external_temperature = this->parent_->get_external_temperature();
28  this->external_temperature_sensor_->publish_state(external_temperature);
29  }
30 
31  if (this->speed_sensor_ != nullptr) {
32  float speed = this->parent_->get_speed();
33  this->speed_sensor_->publish_state(speed);
34  }
35 
36  if (this->duty_cycle_sensor_ != nullptr) {
37  float duty_cycle = this->parent_->get_duty_cycle();
38  this->duty_cycle_sensor_->publish_state(duty_cycle * 100.0f);
39  }
40 }
41 
42 } // namespace emc2101
43 } // namespace esphome
void update() override
Used by ESPHome framework.
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
sensor::Sensor * external_temperature_sensor_
int speed
Definition: fan.h:35
void dump_config() override
Used by ESPHome framework.
sensor::Sensor * internal_temperature_sensor_
float get_setup_priority() const override
Used by ESPHome framework.
float get_internal_temperature()
Gets the internal temperature sensor reading.
Definition: emc2101.cpp:129
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
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_external_temperature()
Gets the external temperature sensor reading.
Definition: emc2101.cpp:139
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
sensor::Sensor * duty_cycle_sensor_