display state sensor was added; Idea HVAC was tested

This commit is contained in:
GrKoR
2022-04-18 00:04:24 +03:00
parent dc91e7b19e
commit 1a9a91ef93
5 changed files with 79 additions and 10 deletions

View File

@@ -11,6 +11,7 @@
#include "esphome/components/climate/climate.h"
#include "esphome/components/uart/uart.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/core/helpers.h"
namespace esphome {
@@ -1575,6 +1576,9 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
// TODO: если расшифруем формулу для уличной температуры, то можно будет вернуть
//esphome::sensor::Sensor *sensor_outdoor_temperature = new esphome::sensor::Sensor();
// бинарный сенсор, отображающий состояние дисплея
esphome::binary_sensor::BinarySensor *sensor_display_ = nullptr;
public:
// инициализация объекта
void initAC(esphome::uart::UARTComponent *parent = nullptr){
@@ -1600,6 +1604,7 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
float get_setup_priority() const override { return esphome::setup_priority::DATA; }
void set_indoor_temperature_sensor(sensor::Sensor *temperature_sensor) { sensor_indoor_temperature_ = temperature_sensor; }
void set_display_sensor(binary_sensor::BinarySensor *display_sensor) { sensor_display_ = display_sensor; }
bool get_hw_initialized(){ return _hw_initialized; };
bool get_has_connection(){ return _has_connection; };
@@ -1848,6 +1853,22 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
// температура уличного блока
// TODO: если расшифруем формулу для уличной температуры, то можно будет вернуть
//sensor_outdoor_temperature->publish_state(_current_ac_state.temp_outdoor);
// состояние дисплея
if (sensor_display_ != nullptr)
switch (_current_ac_state.display) {
case AC_DISPLAY_ON:
sensor_display_->publish_state(true);
break;
case AC_DISPLAY_OFF:
sensor_display_->publish_state(false);
break;
default:
// могут быть и другие состояния, поэтому так
break;
}
}
// вывод в дебаг текущей конфигурации компонента
@@ -1874,6 +1895,18 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
ESP_LOGV(Constants::TAG, "%s Force Update: YES", " ");
}
}
if ((this->sensor_display_) != nullptr) {
ESP_LOGCONFIG(Constants::TAG, "%s%s '%s'", " ", LOG_STR_LITERAL("Display"), (this->sensor_display_)->get_name().c_str());
if (!(this->sensor_display_)->get_device_class().empty()) {
ESP_LOGCONFIG(Constants::TAG, "%s Device Class: '%s'", " ", (this->sensor_display_)->get_device_class().c_str());
}
if (!(this->sensor_display_)->get_icon().empty()) {
ESP_LOGCONFIG(Constants::TAG, "%s Icon: '%s'", " ", (this->sensor_display_)->get_icon().c_str());
}
if (!(this->sensor_display_)->get_object_id().empty()) {
ESP_LOGV(Constants::TAG, "%s Object ID: '%s'", " ", (this->sensor_display_)->get_object_id().c_str());
}
}
this->dump_traits_(Constants::TAG);
}

View File

@@ -1,7 +1,7 @@
import logging
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.components import climate, uart, sensor
from esphome.components import climate, uart, sensor, binary_sensor
from esphome import automation
from esphome.automation import maybe_simple_id
from esphome.const import (
@@ -15,6 +15,7 @@ from esphome.const import (
ICON_THERMOMETER,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
DEVICE_CLASS_EMPTY,
)
from esphome.components.climate import (
ClimateMode,
@@ -26,13 +27,16 @@ _LOGGER = logging.getLogger(__name__)
CODEOWNERS = ["@GrKoR"]
DEPENDENCIES = ["climate", "uart"]
AUTO_LOAD = ["sensor"]
AUTO_LOAD = ["sensor", "binary_sensor"]
CONF_SUPPORTED_MODES = 'supported_modes'
CONF_SUPPORTED_SWING_MODES = 'supported_swing_modes'
CONF_SUPPORTED_PRESETS = 'supported_presets'
CONF_SHOW_ACTION = 'show_action'
CONF_INDOOR_TEMPERATURE = 'indoor_temperature'
CONF_DISPLAY_STATE = 'display_state'
ICON_DISPLAY = "mdi:numeric"
aux_ac_ns = cg.esphome_ns.namespace("aux_ac")
AirCon = aux_ac_ns.class_("AirCon", climate.Climate, cg.Component)
@@ -97,6 +101,14 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_INTERNAL, default="true"): cv.boolean,
}
),
cv.Optional(CONF_DISPLAY_STATE): binary_sensor.binary_sensor_schema(
icon=ICON_DISPLAY,
device_class=DEVICE_CLASS_EMPTY,
).extend(
{
cv.Optional(CONF_INTERNAL, default="true"): cv.boolean,
}
),
cv.Optional(CONF_SUPPORTED_MODES): cv.ensure_list(validate_modes),
cv.Optional(CONF_SUPPORTED_SWING_MODES): cv.ensure_list(validate_swing_modes),
cv.Optional(CONF_SUPPORTED_PRESETS): cv.ensure_list(validate_presets),
@@ -124,6 +136,11 @@ async def to_code(config):
sens = await sensor.new_sensor(conf)
cg.add(var.set_indoor_temperature_sensor(sens))
if CONF_DISPLAY_STATE in config:
conf = config[CONF_DISPLAY_STATE]
sens = await binary_sensor.new_binary_sensor(conf)
cg.add(var.set_display_sensor(sens))
cg.add(var.set_period(config[CONF_PERIOD].total_milliseconds))
cg.add(var.set_show_action(config[CONF_SHOW_ACTION]))
if CONF_SUPPORTED_MODES in config: