-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bedjet] expose the outlet temperature on the climate and as a sensor
- Loading branch information
1 parent
41b1950
commit 18fe40a
Showing
10 changed files
with
165 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
|
||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import sensor | ||
from esphome.const import ( | ||
CONF_ID, | ||
DEVICE_CLASS_TEMPERATURE, | ||
STATE_CLASS_MEASUREMENT, | ||
UNIT_CELSIUS, | ||
) | ||
from .. import ( | ||
BEDJET_CLIENT_SCHEMA, | ||
bedjet_ns, | ||
register_bedjet_child, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
CODEOWNERS = ["@jhansche", "@javawizard"] | ||
DEPENDENCIES = ["bedjet"] | ||
|
||
CONF_OUTLET_TEMPERATURE = "outlet_temperature" | ||
CONF_AMBIENT_TEMPERATURE = "ambient_temperature" | ||
|
||
BedjetSensor = bedjet_ns.class_("BedjetSensor", cg.Component) | ||
|
||
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(): cv.declare_id(BedjetSensor), | ||
cv.Optional(CONF_OUTLET_TEMPERATURE): sensor.sensor_schema( | ||
unit_of_measurement=UNIT_CELSIUS, | ||
device_class=DEVICE_CLASS_TEMPERATURE, | ||
state_class=STATE_CLASS_MEASUREMENT, | ||
), | ||
cv.Optional(CONF_AMBIENT_TEMPERATURE): sensor.sensor_schema( | ||
unit_of_measurement=UNIT_CELSIUS, | ||
device_class=DEVICE_CLASS_TEMPERATURE, | ||
state_class=STATE_CLASS_MEASUREMENT, | ||
), | ||
} | ||
).extend(BEDJET_CLIENT_SCHEMA) | ||
|
||
|
||
async def to_code(config): | ||
var = cg.new_Pvariable(config[CONF_ID]) | ||
await cg.register_component(var, config) | ||
await register_bedjet_child(var, config) | ||
|
||
if CONF_OUTLET_TEMPERATURE in config: | ||
sensor_var = await sensor.new_sensor(config[CONF_OUTLET_TEMPERATURE]) | ||
cg.add(var.set_outlet_temperature_sensor(sensor_var)) | ||
|
||
if CONF_AMBIENT_TEMPERATURE in config: | ||
sensor_var = await sensor.new_sensor(config[CONF_AMBIENT_TEMPERATURE]) | ||
cg.add(var.set_ambient_temperature_sensor(sensor_var)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "bedjet_sensor.h" | ||
#include "esphome/core/log.h" | ||
|
||
namespace esphome { | ||
namespace bedjet { | ||
|
||
std::string BedjetSensor::describe() { return "BedJet Sensor"; } | ||
|
||
void BedjetSensor::dump_config() { | ||
ESP_LOGCONFIG(TAG, "BedJet Sensor:"); | ||
LOG_SENSOR(" ", "Outlet Temperature", this->outlet_temperature_sensor_); | ||
LOG_SENSOR(" ", "Ambient Temperature", this->ambient_temperature_sensor_); | ||
} | ||
|
||
void BedjetSensor::on_bedjet_state(bool is_ready) {} | ||
|
||
void BedjetSensor::on_status(const BedjetStatusPacket *data) { | ||
if (this->outlet_temperature_sensor_ != nullptr) { | ||
float converted_temp = bedjet_temp_to_c(data->actual_temp_step); | ||
if (converted_temp > 0) { | ||
this->outlet_temperature_sensor_->publish_state(converted_temp); | ||
} | ||
} | ||
|
||
if (this->ambient_temperature_sensor_ != nullptr) { | ||
float converted_temp = bedjet_temp_to_c(data->ambient_temp_step); | ||
if (converted_temp > 0) { | ||
this->ambient_temperature_sensor_->publish_state(converted_temp); | ||
} | ||
} | ||
} | ||
|
||
} // namespace bedjet | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "esphome/core/component.h" | ||
#include "esphome/components/sensor/sensor.h" | ||
#include "esphome/components/bedjet/bedjet_child.h" | ||
#include "esphome/components/bedjet/bedjet_codec.h" | ||
|
||
namespace esphome { | ||
namespace bedjet { | ||
|
||
class BedjetSensor : public BedJetClient, public Component { | ||
public: | ||
void dump_config() override; | ||
|
||
void on_status(const BedjetStatusPacket *data) override; | ||
void on_bedjet_state(bool is_ready) override; | ||
std::string describe() override; | ||
|
||
void set_outlet_temperature_sensor(sensor::Sensor *outlet_temperature_sensor) { | ||
this->outlet_temperature_sensor_ = outlet_temperature_sensor; | ||
} | ||
void set_ambient_temperature_sensor(sensor::Sensor *ambient_temperature_sensor) { | ||
this->ambient_temperature_sensor_ = ambient_temperature_sensor; | ||
} | ||
|
||
protected: | ||
sensor::Sensor *outlet_temperature_sensor_{nullptr}; | ||
sensor::Sensor *ambient_temperature_sensor_{nullptr}; | ||
}; | ||
|
||
} // namespace bedjet | ||
} // namespace esphome |