mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
feat: add target temperature as sensor
This commit is contained in:
parent
1829e68730
commit
f526b6b07e
3 changed files with 20 additions and 4 deletions
|
@ -1,11 +1,12 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_EXTERNAL_TEMPERATURE,
|
||||
CONF_HUMIDITY,
|
||||
CONF_TEMPERATURE,
|
||||
CONF_ID,
|
||||
CONF_TARGET_TEMPERATURE,
|
||||
CONF_TEMPERATURE,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
|
@ -14,10 +15,10 @@ from esphome.const import (
|
|||
)
|
||||
|
||||
from .. import (
|
||||
uponor_smatrix_ns,
|
||||
UponorSmatrixDevice,
|
||||
UPONOR_SMATRIX_DEVICE_SCHEMA,
|
||||
UponorSmatrixDevice,
|
||||
register_uponor_smatrix_device,
|
||||
uponor_smatrix_ns,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["uponor_smatrix"]
|
||||
|
@ -50,6 +51,12 @@ CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend(
|
|||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_TARGET_TEMPERATURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
).extend(UPONOR_SMATRIX_DEVICE_SCHEMA)
|
||||
|
||||
|
@ -68,3 +75,6 @@ async def to_code(config):
|
|||
if humidity_config := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity_config)
|
||||
cg.add(var.set_humidity_sensor(sens))
|
||||
if target_temperature_config := config.get(CONF_TARGET_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(target_temperature_config)
|
||||
cg.add(var.set_target_temperature_sensor(sens))
|
||||
|
|
|
@ -12,6 +12,7 @@ void UponorSmatrixSensor::dump_config() {
|
|||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "External Temperature", this->external_temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
LOG_SENSOR(" ", "Target Temperature", this->target_temperature_sensor_);
|
||||
}
|
||||
|
||||
void UponorSmatrixSensor::on_device_data(const UponorSmatrixData *data, size_t data_len) {
|
||||
|
@ -29,6 +30,10 @@ void UponorSmatrixSensor::on_device_data(const UponorSmatrixData *data, size_t d
|
|||
if (this->humidity_sensor_ != nullptr)
|
||||
this->humidity_sensor_->publish_state(data[i].value & 0x00FF);
|
||||
break;
|
||||
case UPONOR_ID_TARGET_TEMP:
|
||||
if (this->target_temperature_sensor_ != nullptr)
|
||||
this->target_temperature_sensor_->publish_state(raw_to_celsius(data[i].value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ class UponorSmatrixSensor : public sensor::Sensor, public Component, public Upon
|
|||
SUB_SENSOR(temperature)
|
||||
SUB_SENSOR(external_temperature)
|
||||
SUB_SENSOR(humidity)
|
||||
SUB_SENSOR(target_temperature)
|
||||
|
||||
public:
|
||||
void dump_config() override;
|
||||
|
|
Loading…
Reference in a new issue