From f526b6b07eee1ed9e98c9ad2f05e6381128459a4 Mon Sep 17 00:00:00 2001 From: janschroeter <5852313+janschroeter@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:39:55 +0100 Subject: [PATCH] feat: add target temperature as sensor --- .../uponor_smatrix/sensor/__init__.py | 18 ++++++++++++++---- .../sensor/uponor_smatrix_sensor.cpp | 5 +++++ .../sensor/uponor_smatrix_sensor.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/esphome/components/uponor_smatrix/sensor/__init__.py b/esphome/components/uponor_smatrix/sensor/__init__.py index 89097aef18..f2b34538ba 100644 --- a/esphome/components/uponor_smatrix/sensor/__init__.py +++ b/esphome/components/uponor_smatrix/sensor/__init__.py @@ -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)) diff --git a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp index 2fd2a36efc..47ff3a17f5 100644 --- a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +++ b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp @@ -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; } } } diff --git a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h index 5e38117a21..97d0d21838 100644 --- a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +++ b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h @@ -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;