mirror of
https://github.com/GrKoR/esphome_aux_ac_component.git
synced 2025-12-15 07:57:02 +03:00
Merge pull request #44 from GrKoR/GrKoR/issue39
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
// весь функционал сохранения пресетов прячу под дефайн
|
||||
@@ -1791,6 +1792,8 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
|
||||
esphome::binary_sensor::BinarySensor *sensor_display_ = nullptr;
|
||||
// бинарный сенсор состония разморозки
|
||||
esphome::binary_sensor::BinarySensor *sensor_defrost_ = nullptr;
|
||||
// текстовый сенсор, отображающий текущий режим работы сплита
|
||||
esphome::text_sensor::TextSensor *sensor_state_reporter_ = nullptr;
|
||||
|
||||
|
||||
// загружает на выполнение последовательность команд на включение/выключение табло с температурой
|
||||
@@ -1907,6 +1910,7 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
|
||||
void set_defrost_state(binary_sensor::BinarySensor *defrost_state_sensor) { sensor_defrost_ = defrost_state_sensor; }
|
||||
void set_display_sensor(binary_sensor::BinarySensor *display_sensor) { sensor_display_ = display_sensor; }
|
||||
void set_invertor_power_sensor(sensor::Sensor *invertor_power_sensor) { sensor_invertor_power_ = invertor_power_sensor; }
|
||||
void set_state_reporter_sensor(text_sensor::TextSensor *state_reporter_sensor) { sensor_state_reporter_ = state_reporter_sensor; }
|
||||
|
||||
bool get_hw_initialized(){ return _hw_initialized; };
|
||||
bool get_has_connection(){ return _has_connection; };
|
||||
@@ -2209,6 +2213,11 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
|
||||
/*********************************************************************/
|
||||
/*************************** PUBLISH STATE ***************************/
|
||||
/*********************************************************************/
|
||||
this->publish_all_states();
|
||||
}
|
||||
|
||||
// публикуем все состояния сенсоров и сплита
|
||||
void publish_all_states(){
|
||||
this->publish_state();
|
||||
// температура в комнате
|
||||
if (sensor_indoor_temperature_ != nullptr)
|
||||
@@ -2232,6 +2241,19 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
|
||||
if (sensor_defrost_ != nullptr)
|
||||
sensor_defrost_->publish_state(_current_ac_state.defrost);
|
||||
|
||||
// сенсор состояния сплита
|
||||
if (sensor_state_reporter_ != nullptr) {
|
||||
std::string state_str = "";
|
||||
if (this->preset == climate::CLIMATE_PRESET_SLEEP) {
|
||||
state_str += "SLEEP";
|
||||
} else if (this->custom_preset.has_value() && this->custom_preset.value().length() > 0) {
|
||||
state_str += this->custom_preset.value().c_str();
|
||||
} else {
|
||||
state_str += "NONE";
|
||||
}
|
||||
sensor_state_reporter_->publish_state(state_str.c_str());
|
||||
}
|
||||
|
||||
// состояние дисплея
|
||||
if (sensor_display_ != nullptr) {
|
||||
switch (_current_ac_state.display) {
|
||||
@@ -2778,7 +2800,7 @@ class AirCon : public esphome::Component, public esphome::climate::Climate {
|
||||
|
||||
if (hasCommand) {
|
||||
commandSequence(&cmd);
|
||||
this->publish_state(); // Publish updated state
|
||||
this->publish_all_states(); // Publish updated state
|
||||
|
||||
#if defined(PRESETS_SAVING)
|
||||
// флаг отправки новой команды, для процедуры сохранения пресетов, если есть настройка
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import climate, uart, sensor, binary_sensor
|
||||
from esphome.components import climate, uart, sensor, binary_sensor, text_sensor
|
||||
from esphome import automation
|
||||
from esphome.automation import maybe_simple_id
|
||||
from esphome.const import (
|
||||
@@ -37,7 +37,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CODEOWNERS = ["@GrKoR"]
|
||||
DEPENDENCIES = ["climate", "uart"]
|
||||
AUTO_LOAD = ["sensor", "binary_sensor"]
|
||||
AUTO_LOAD = ["sensor", "binary_sensor", "text_sensor"]
|
||||
|
||||
CONF_SHOW_ACTION = 'show_action'
|
||||
CONF_INDOOR_TEMPERATURE = 'indoor_temperature'
|
||||
@@ -55,6 +55,8 @@ CONF_DEFROST_STATE = 'defrost_state'
|
||||
ICON_DEFROST = "mdi:snowflake-melt"
|
||||
CONF_DISPLAY_INVERTED = 'display_inverted'
|
||||
ICON_DISPLAY = "mdi:clock-digital"
|
||||
CONF_STATE_REPORTER = "state_reporter"
|
||||
ICON_STATE_REPORTER = "mdi:format-list-group"
|
||||
|
||||
|
||||
aux_ac_ns = cg.esphome_ns.namespace("aux_ac")
|
||||
@@ -203,6 +205,14 @@ CONFIG_SCHEMA = cv.All(
|
||||
}
|
||||
),
|
||||
|
||||
cv.Optional(CONF_STATE_REPORTER): text_sensor.text_sensor_schema(
|
||||
icon=ICON_STATE_REPORTER
|
||||
).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),
|
||||
@@ -266,6 +276,11 @@ async def to_code(config):
|
||||
sens = await sensor.new_sensor(conf)
|
||||
cg.add(var.set_invertor_power_sensor(sens))
|
||||
|
||||
if CONF_STATE_REPORTER in config:
|
||||
conf = config[CONF_STATE_REPORTER]
|
||||
sens = await text_sensor.new_text_sensor(conf)
|
||||
cg.add(var.set_state_reporter_sensor(sens))
|
||||
|
||||
cg.add(var.set_period(config[CONF_PERIOD].total_milliseconds))
|
||||
cg.add(var.set_show_action(config[CONF_SHOW_ACTION]))
|
||||
cg.add(var.set_display_inverted(config[CONF_DISPLAY_INVERTED]))
|
||||
|
||||
@@ -69,9 +69,37 @@ climate:
|
||||
id: ${devicename}_indoor_temp
|
||||
internal: false
|
||||
display_state:
|
||||
name: $upper_devicename Display State
|
||||
name: ${upper_devicename} Display State
|
||||
id: ${devicename}_display_state
|
||||
internal: false
|
||||
outdoor_temperature:
|
||||
name: ${upper_devicename} Outdoor Temperature
|
||||
id: ${devicename}_outdoor_temp
|
||||
internal: false
|
||||
outbound_temperature:
|
||||
name: ${upper_devicename} Colant Outbound Temperature
|
||||
id: ${devicename}_outbound_temp
|
||||
internal: false
|
||||
inbound_temperature:
|
||||
name: ${upper_devicename} Colant Inbound Temperature
|
||||
id: ${devicename}_inbound_temp
|
||||
internal: false
|
||||
compressor_temperature:
|
||||
name: ${upper_devicename} Compressor Temperature
|
||||
id: ${devicename}_strange_temp
|
||||
internal: false
|
||||
defrost_state:
|
||||
name: ${upper_devicename} Defrost State
|
||||
id: ${devicename}_defrost_state
|
||||
internal: false
|
||||
invertor_power:
|
||||
name: ${upper_devicename} Invertor Power
|
||||
id: ${devicename}_invertor_power
|
||||
internal: false
|
||||
state_reporter:
|
||||
name: ${upper_devicename} State Reporter
|
||||
id: ${devicename}_state_reporter
|
||||
internal: false
|
||||
visual:
|
||||
min_temperature: 16
|
||||
max_temperature: 32
|
||||
@@ -89,7 +117,6 @@ climate:
|
||||
- SLEEP
|
||||
custom_presets:
|
||||
- CLEAN
|
||||
- FEEL
|
||||
- HEALTH
|
||||
- ANTIFUNGUS
|
||||
supported_swing_modes:
|
||||
@@ -109,7 +136,7 @@ sensor:
|
||||
|
||||
switch:
|
||||
- platform: template
|
||||
name: $upper_devicename Display
|
||||
name: ${upper_devicename} Display
|
||||
lambda: |-
|
||||
if (id(${devicename}_display_state).state) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user