Skip to content

Commit 0cd12ee

Browse files
committed
Move C++ headers to components
1 parent df73d79 commit 0cd12ee

27 files changed

Lines changed: 250 additions & 260 deletions

‎components/custom/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎components/custom/climate/__init__.py‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎components/custom/climate/custom_climate.h‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎components/custom_component/__init__.py‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎components/custom_component/custom_component.h‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎components/wp_climate/__init__.py‎

Whitespace-only changes.

‎components/wp_climate/climate.py‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import esphome.codegen as cg
2+
import esphome.config_validation as cv
3+
from esphome.components import climate, sensor, binary_sensor
4+
from esphome.const import CONF_ID, CONF_TYPE
5+
6+
DEPENDENCIES = ["wp_core"]
7+
8+
wp_climate_ns = cg.esphome_ns.namespace("wp_climate")
9+
Heating = wp_climate_ns.class_("Heating", climate.Climate, cg.Component)
10+
HotWater = wp_climate_ns.class_("HotWater", climate.Climate, cg.Component)
11+
12+
CONF_CURRENT_TEMP = "current_temp"
13+
CONF_TARGET_TEMP = "target_temp"
14+
CONF_HEATING = "heating"
15+
CONF_COOLING = "cooling"
16+
CONF_FAN = "fan"
17+
CONF_TARGET_PROPERTY = "target_property"
18+
CONF_COOL_PROPERTY = "cool_property"
19+
20+
HEATING_SCHEMA = climate.climate_schema(Heating).extend({
21+
cv.Required(CONF_CURRENT_TEMP): cv.use_id(sensor.Sensor),
22+
cv.Required(CONF_TARGET_TEMP): cv.use_id(sensor.Sensor),
23+
cv.Required(CONF_HEATING): cv.use_id(binary_sensor.BinarySensor),
24+
cv.Optional(CONF_COOLING): cv.use_id(binary_sensor.BinarySensor),
25+
cv.Optional(CONF_FAN): cv.use_id(binary_sensor.BinarySensor),
26+
cv.Required(CONF_TARGET_PROPERTY): cv.string,
27+
cv.Optional(CONF_COOL_PROPERTY): cv.string,
28+
}).extend(cv.COMPONENT_SCHEMA)
29+
30+
HOT_WATER_SCHEMA = climate.climate_schema(HotWater).extend({
31+
cv.Required(CONF_CURRENT_TEMP): cv.use_id(sensor.Sensor),
32+
cv.Required(CONF_TARGET_TEMP): cv.use_id(sensor.Sensor),
33+
cv.Required(CONF_HEATING): cv.use_id(binary_sensor.BinarySensor),
34+
cv.Required(CONF_TARGET_PROPERTY): cv.string,
35+
}).extend(cv.COMPONENT_SCHEMA)
36+
37+
CONFIG_SCHEMA = cv.typed_schema({
38+
"heating": HEATING_SCHEMA,
39+
"hot_water": HOT_WATER_SCHEMA,
40+
})
41+
42+
async def to_code(config):
43+
current_temp = await cg.get_variable(config[CONF_CURRENT_TEMP])
44+
target_temp = await cg.get_variable(config[CONF_TARGET_TEMP])
45+
heating_sens = await cg.get_variable(config[CONF_HEATING])
46+
target_prop = cg.RawExpression(f"Property::{config[CONF_TARGET_PROPERTY]}")
47+
48+
if config[CONF_TYPE] == "heating":
49+
has_cool = CONF_COOLING in config
50+
has_fan = CONF_FAN in config
51+
52+
if has_cool and has_fan and CONF_COOL_PROPERTY in config:
53+
cool_sens = await cg.get_variable(config[CONF_COOLING])
54+
fan_sens = await cg.get_variable(config[CONF_FAN])
55+
cool_prop = cg.RawExpression(f"Property::{config[CONF_COOL_PROPERTY]}")
56+
var = cg.new_Pvariable(config[CONF_ID], current_temp, target_temp, heating_sens, cool_sens, fan_sens, target_prop, cool_prop)
57+
elif has_fan and not has_cool:
58+
fan_sens = await cg.get_variable(config[CONF_FAN])
59+
var = cg.new_Pvariable(config[CONF_ID], current_temp, target_temp, heating_sens, fan_sens, target_prop)
60+
else:
61+
var = cg.new_Pvariable(config[CONF_ID], current_temp, target_temp, heating_sens, target_prop)
62+
else:
63+
var = cg.new_Pvariable(config[CONF_ID], current_temp, target_temp, heating_sens, target_prop)
64+
65+
await cg.register_component(var, config)
66+
await climate.register_climate(var, config)
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
#pragma once
2+
13
#include "esphome.h"
2-
#include "property.h"
4+
#include "esphome/components/climate/climate.h"
5+
#include "esphome/components/wp_core/communication.h"
6+
#include "esphome/components/wp_core/property.h"
7+
8+
namespace esphome {
9+
namespace wp_climate {
310

4-
class CustomClimate : public Component, public Climate {
11+
class CustomClimate : public Component, public climate::Climate {
512
public:
613
CustomClimate(esphome::climate::ClimateModeMask modes, esphome::climate::ClimatePresetMask presets,
714
const std::vector<std::pair<const CanMember, const Property>> targetTemperatureProperties)
@@ -79,25 +86,20 @@ class CustomClimate : public Component, public Climate {
7986
this->publish_state();
8087
}
8188

82-
void control(const ClimateCall& call) override {
83-
// only handle the temp adjustment, since there seems to be no way to explicitly set the
84-
// heat pump to cooling or heating, other than setting the temperature.
89+
void control(const climate::ClimateCall& call) override {
8590
if (call.get_target_temperature().has_value()) {
86-
// User requested target temperature change
8791
float temp = *call.get_target_temperature();
8892
this->target_temperature = temp;
8993

90-
// Send target temp to climate
9194
for (const auto& targetTemperatureProperty : targetTemperatureProperties_) {
9295
queueTransmission(targetTemperatureProperty.first, targetTemperatureProperty.second,
9396
static_cast<std::uint16_t>(temp * 10.0f));
9497
}
9598
}
96-
// Publish updated state
9799
this->publish_state();
98100
}
99101

100-
ClimateTraits traits() override { return traits_; }
102+
climate::ClimateTraits traits() override { return traits_; }
101103

102104
protected:
103105
climate::ClimateTraits traits_{};
@@ -111,9 +113,7 @@ class CustomClimate : public Component, public Climate {
111113

112114
class Heating : public CustomClimate {
113115
public:
114-
// -------------------------------------------------------------------
115-
// Full features (Heating + Cooling + Fan)
116-
// -------------------------------------------------------------------
116+
// Full features
117117
template <typename Sensor, typename BinarySensor>
118118
Heating(Sensor* current_temperature_sensor, Sensor* target_temperature_sensor, BinarySensor* heating_sensor,
119119
BinarySensor* cooling_sensor, BinarySensor* fan_sensor, const Property targetHeatingTemperature,
@@ -130,9 +130,7 @@ class Heating : public CustomClimate {
130130
register_fan_callback(fan_sensor);
131131
}
132132

133-
// -------------------------------------------------------------------
134-
// Heating + Fan (No Cooling)
135-
// -------------------------------------------------------------------
133+
// Heating + Fan
136134
template <typename Sensor, typename BinarySensor>
137135
Heating(Sensor* current_temperature_sensor, Sensor* target_temperature_sensor, BinarySensor* heating_sensor,
138136
BinarySensor* fan_sensor, const Property targetHeatingTemperature)
@@ -145,9 +143,7 @@ class Heating : public CustomClimate {
145143
register_fan_callback(fan_sensor);
146144
}
147145

148-
// -------------------------------------------------------------------
149-
// Basic Heating Only (No Cooling, No Fan)
150-
// -------------------------------------------------------------------
146+
// Basic Heating Only
151147
template <typename Sensor, typename BinarySensor>
152148
Heating(Sensor* current_temperature_sensor, Sensor* target_temperature_sensor, BinarySensor* heating_sensor,
153149
const Property targetHeatingTemperature)
@@ -173,3 +169,6 @@ class HotWater : public CustomClimate {
173169
register_heating_callback(heating_sensor);
174170
}
175171
};
172+
173+
} // namespace wp_climate
174+
} // namespace esphome

‎components/wp_core/__init__.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import esphome.codegen as cg
2+
import esphome.config_validation as cv
3+
4+
def to_code(config):
5+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/callback_handler.h"'))
6+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/communication.h"'))
7+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/mapper.h"'))
8+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/property.h"'))
9+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/simple_variant.h"'))
10+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/type.h"'))
11+
cg.add_global(cg.RawStatement('#include "esphome/components/wp_core/util.h"'))
12+
13+
CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(cg.Component) })

0 commit comments

Comments
 (0)