Skip to content

Commit

Permalink
Revert "revert to original"
Browse files Browse the repository at this point in the history
This reverts commit c1273fe.
  • Loading branch information
wichers committed Mar 11, 2024
1 parent c1273fe commit c60671f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 37 deletions.
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# [Choice] Ubuntu version: bionic, focal
ARG VARIANT=focal
FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
19 changes: 19 additions & 0 deletions .devcontainer/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Update the VARIANT arg in devcontainer.json to pick an Ubuntu version: focal, bionic
ARG VARIANT="focal"
FROM buildpack-deps:${VARIANT}-curl

# Options for setup script
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="true"
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
RUN yes | unminimize 2>&1 \
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Ubuntu version: focal, bionic
"args": { "VARIANT": "focal" }
},
"customizations": {"vscode":{
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools",
"ms-python.python",
"ms-azuretools.vscode-docker"
]
}},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash ./.devcontainer/install.sh",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
6 changes: 6 additions & 0 deletions .devcontainer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo apt update & sudo apt install -y pip
sudo pip3 install setuptools
git clone https://github.com/esphome/esphome.git
cd esphome
pip3 install -r ./requirements_optional.txt
sudo python3 setup.py install
86 changes: 49 additions & 37 deletions components/comfoair/comfoair.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@

namespace esphome {
namespace comfoair {
class ComfoAirComponent : public climate::Climate, public PollingComponent, public uart::UARTDevice {
public:

// Poll every 600ms
ComfoAirComponent() :
Climate(),
PollingComponent(600),
UARTDevice() { }
// Base class
class ComfoAirComponentBase {
public:
virtual void set_level(int level) = 0;
virtual void set_comfort_temperature(float temperature) = 0;
};

class ComfoAirClimate : public climate::Climate {
public:

ComfoAirClimate(ComfoAirComponentBase *comfoair) : Climate(), comfoair_(comfoair) {
this->set_name("comfoair");
}

/// Return the traits of this controller.
climate::ClimateTraits traits() override {
Expand All @@ -29,19 +35,18 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
traits.set_supports_two_point_target_temperature(false);
traits.set_supported_presets({
climate::CLIMATE_PRESET_HOME,
});
});
traits.set_supports_action(false);
traits.set_visual_min_temperature(12);
traits.set_visual_max_temperature(29);
//traits.set_visual_tXComfoAirComponentemperature_step(1);
traits.set_visual_temperature_step(1);
traits.set_supported_fan_modes({
climate::CLIMATE_FAN_FOCUS,
climate::CLIMATE_FAN_AUTO,
climate::CLIMATE_FAN_LOW,
climate::CLIMATE_FAN_MEDIUM,
climate::CLIMATE_FAN_HIGH,
climate::CLIMATE_FAN_OFF,
});
});
return traits;
}

Expand All @@ -52,10 +57,6 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ

this->fan_mode = *call.get_fan_mode();
switch (this->fan_mode.value()) {
case climate::CLIMATE_FAN_FOCUS:
level = 0x05;
break;

case climate::CLIMATE_FAN_HIGH:
level = 0x04;
break;
Expand All @@ -80,18 +81,28 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
}

if (level >= 0) {
set_level_(level);
this->comfoair_->set_level(level);
}

}
if (call.get_target_temperature().has_value()) {
this->target_temperature = *call.get_target_temperature();
set_comfort_temperature_(this->target_temperature);
this->comfoair_->set_comfort_temperature(this->target_temperature);
}

this->publish_state();
}

protected:
ComfoAirComponentBase *comfoair_;
};

class ComfoAirComponent : public ComfoAirComponentBase, PollingComponent, uart::UARTDevice {
public:

// Poll every 600ms
ComfoAirComponent(UARTComponent *parent) : PollingComponent(600), UARTDevice(parent) {}

void dump_config() override {
uint8_t *p;
ESP_LOGCONFIG(TAG, "ComfoAir:");
Expand All @@ -112,7 +123,7 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
this->check_uart_settings(9600);
}

void update() {
void update() override {
switch(update_counter_) {
case -3:
this->write_command_(COMFOAIR_GET_BOOTLOADER_VERSION_REQUEST, nullptr, 0);
Expand Down Expand Up @@ -183,9 +194,7 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
void set_name(const char* value) {this->name = value;}
void set_uart_component(uart::UARTComponent *parent) {this->set_uart_parent(parent);}

protected:

void set_level_(int level) {
void set_level(int level) override {
if (level < 0 || level > 5) {
ESP_LOGI(TAG, "Ignoring invalid level request: %i", level);
return;
Expand All @@ -198,7 +207,7 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
}
}

void set_comfort_temperature_(float temperature) {
void set_comfort_temperature(float temperature) override {
if (temperature < 12.0f || temperature > 29.0f) {
ESP_LOGI(TAG, "Ignoring invalid temperature request: %i", temperature);
return;
Expand All @@ -211,6 +220,8 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
}
}

protected:

void write_command_(const uint8_t command, const uint8_t *command_data, uint8_t command_data_length) {
this->write_byte(COMFOAIR_MSG_PREFIX);
this->write_byte(COMFOAIR_MSG_HEAD);
Expand Down Expand Up @@ -390,28 +401,28 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
// Fan Speed
switch(msg[8]) {
case 0x00:
this->fan_mode = climate::CLIMATE_FAN_AUTO;
this->mode = climate::CLIMATE_MODE_AUTO;
this->comfoair_climate->fan_mode = climate::CLIMATE_FAN_AUTO;
this->comfoair_climate->mode = climate::CLIMATE_MODE_AUTO;
break;
case 0x01:
this->fan_mode = climate::CLIMATE_FAN_OFF;
this->mode = climate::CLIMATE_MODE_OFF;
this->comfoair_climate->fan_mode = climate::CLIMATE_FAN_OFF;
this->comfoair_climate->mode = climate::CLIMATE_MODE_OFF;
break;
case 0x02:
this->fan_mode = climate::CLIMATE_FAN_LOW;
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
this->comfoair_climate->fan_mode = climate::CLIMATE_FAN_LOW;
this->comfoair_climate->mode = climate::CLIMATE_MODE_FAN_ONLY;
break;
case 0x03:
this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
this->comfoair_climate->fan_mode = climate::CLIMATE_FAN_MEDIUM;
this->comfoair_climate->mode = climate::CLIMATE_MODE_FAN_ONLY;
break;
case 0x04:
this->fan_mode = climate::CLIMATE_FAN_HIGH;
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
this->comfoair_climate->fan_mode = climate::CLIMATE_FAN_HIGH;
this->comfoair_climate->mode = climate::CLIMATE_MODE_FAN_ONLY;
break;
}

this->publish_state();
this->comfoair_climate->publish_state();

// Supply air fan active (1 = active / 0 = inactive)
if (this->is_supply_fan_active != nullptr) {
Expand All @@ -428,8 +439,9 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
case COMFOAIR_GET_TEMPERATURES_RESPONSE: {

// comfort temperature
this->target_temperature = (float) msg[0] / 2.0f - 20.0f;
this->publish_state();
this->comfoair_climate->target_temperature = (float) msg[0] / 2.0f - 20.0f;
this->comfoair_climate->current_temperature = (float) msg[2] / 2.0f - 20.0f;
this->comfoair_climate->publish_state();

// T1 / outside air
if (this->outside_air_temperature != nullptr && msg[5] & 0x01) {
Expand All @@ -442,7 +454,6 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
// T3 / exhaust air
if (this->return_air_temperature != nullptr && msg[5] & 0x04) {
this->return_air_temperature->publish_state((float) msg[3] / 2.0f - 20.0f);
this->current_temperature = (float) msg[3] / 2.0f - 20.0f;
}
// T4 / continued air
if (this->exhaust_air_temperature != nullptr && msg[5] & 0x08) {
Expand Down Expand Up @@ -545,7 +556,8 @@ class ComfoAirComponent : public climate::Climate, public PollingComponent, publ
uint8_t connector_board_version_[14]{0};
const char* name{0};

public:
public:
ComfoAirClimate *comfoair_climate = new ComfoAirClimate(this);
sensor::Sensor *fan_supply_air_percentage{nullptr};
sensor::Sensor *fan_exhaust_air_percentage{nullptr};
sensor::Sensor *fan_speed_supply{nullptr};
Expand Down

0 comments on commit c60671f

Please sign in to comment.