mirror of
https://github.com/esphome/esphome.git
synced 2025-10-07 20:33:47 +01:00
[lm75b] Add LM75B temperature sensor component (#10534)
This commit is contained in:
@@ -256,6 +256,7 @@ esphome/components/libretiny_pwm/* @kuba2k2
|
||||
esphome/components/light/* @esphome/core
|
||||
esphome/components/lightwaverf/* @max246
|
||||
esphome/components/lilygo_t5_47/touchscreen/* @jesserockz
|
||||
esphome/components/lm75b/* @beormund
|
||||
esphome/components/ln882x/* @lamauny
|
||||
esphome/components/lock/* @esphome/core
|
||||
esphome/components/logger/* @esphome/core
|
||||
|
0
esphome/components/lm75b/__init__.py
Normal file
0
esphome/components/lm75b/__init__.py
Normal file
39
esphome/components/lm75b/lm75b.cpp
Normal file
39
esphome/components/lm75b/lm75b.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "lm75b.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lm75b {
|
||||
|
||||
static const char *const TAG = "lm75b";
|
||||
|
||||
void LM75BComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "LM75B:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Setting up LM75B failed!");
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Temperature", this);
|
||||
}
|
||||
|
||||
void LM75BComponent::update() {
|
||||
// Create a temporary buffer
|
||||
uint8_t buff[2];
|
||||
if (this->read_register(LM75B_REG_TEMPERATURE, buff, 2) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
// Obtain combined 16-bit value
|
||||
int16_t raw_temperature = (buff[0] << 8) | buff[1];
|
||||
// Read the 11-bit raw temperature value
|
||||
raw_temperature >>= 5;
|
||||
// Publish the temperature in °C
|
||||
this->publish_state(raw_temperature * 0.125);
|
||||
if (this->status_has_warning()) {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lm75b
|
||||
} // namespace esphome
|
19
esphome/components/lm75b/lm75b.h
Normal file
19
esphome/components/lm75b/lm75b.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lm75b {
|
||||
|
||||
static const uint8_t LM75B_REG_TEMPERATURE = 0x00;
|
||||
|
||||
class LM75BComponent : public PollingComponent, public i2c::I2CDevice, public sensor::Sensor {
|
||||
public:
|
||||
void dump_config() override;
|
||||
void update() override;
|
||||
};
|
||||
|
||||
} // namespace lm75b
|
||||
} // namespace esphome
|
34
esphome/components/lm75b/sensor.py
Normal file
34
esphome/components/lm75b/sensor.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import i2c, sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@beormund"]
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
lm75b_ns = cg.esphome_ns.namespace("lm75b")
|
||||
LM75BComponent = lm75b_ns.class_(
|
||||
"LM75BComponent", cg.PollingComponent, i2c.I2CDevice, sensor.Sensor
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
sensor.sensor_schema(
|
||||
LM75BComponent,
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
accuracy_decimals=3,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(0x48))
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await sensor.new_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
9
tests/components/lm75b/common.yaml
Normal file
9
tests/components/lm75b/common.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
i2c:
|
||||
- id: i2c_lm75b
|
||||
scl: ${scl_pin}
|
||||
sda: ${sda_pin}
|
||||
|
||||
sensor:
|
||||
- platform: lm75b
|
||||
name: LM75B Temperature
|
||||
update_interval: 30s
|
5
tests/components/lm75b/test.esp32-ard.yaml
Normal file
5
tests/components/lm75b/test.esp32-ard.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO15
|
||||
sda_pin: GPIO13
|
||||
|
||||
<<: !include common.yaml
|
5
tests/components/lm75b/test.esp32-c3-ard.yaml
Normal file
5
tests/components/lm75b/test.esp32-c3-ard.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO5
|
||||
sda_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
5
tests/components/lm75b/test.esp32-c3-idf.yaml
Normal file
5
tests/components/lm75b/test.esp32-c3-idf.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO5
|
||||
sda_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
5
tests/components/lm75b/test.esp32-idf.yaml
Normal file
5
tests/components/lm75b/test.esp32-idf.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO15
|
||||
sda_pin: GPIO13
|
||||
|
||||
<<: !include common.yaml
|
5
tests/components/lm75b/test.esp8266-ard.yaml
Normal file
5
tests/components/lm75b/test.esp8266-ard.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO5
|
||||
sda_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
5
tests/components/lm75b/test.rp2040-ard.yaml
Normal file
5
tests/components/lm75b/test.rp2040-ard.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
scl_pin: GPIO5
|
||||
sda_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
Reference in New Issue
Block a user