mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
Updates
This commit is contained in:
parent
c0f6fe2e2e
commit
3c97b0f083
@ -6,7 +6,7 @@ from esphome.const import CONF_ID, CONF_NAME, CONF_SENSOR
|
|||||||
AUTO_LOAD = ['sensor']
|
AUTO_LOAD = ['sensor']
|
||||||
|
|
||||||
tcl112_ns = cg.esphome_ns.namespace('tcl112')
|
tcl112_ns = cg.esphome_ns.namespace('tcl112')
|
||||||
Tcl112Climate = tcl112_ns.class_('Tcl112Climate', climate.ClimateDevice, cg.Component)
|
Tcl112Climate = tcl112_ns.class_('Tcl112Climate', climate.Climate, cg.Component)
|
||||||
|
|
||||||
CONF_TRANSMITTER_ID = 'transmitter_id'
|
CONF_TRANSMITTER_ID = 'transmitter_id'
|
||||||
CONF_SUPPORTS_HEAT = 'supports_heat'
|
CONF_SUPPORTS_HEAT = 'supports_heat'
|
||||||
|
@ -74,10 +74,8 @@ void Tcl112Climate::control(const climate::ClimateCall &call) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Tcl112Climate::transmit_state_() {
|
void Tcl112Climate::transmit_state_() {
|
||||||
uint8_t remote_state[TCL112_STATE_LENGTH];
|
uint8_t remote_state[TCL112_STATE_LENGTH] = {0};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < TCL112_STATE_LENGTH; i++)
|
|
||||||
remote_state[i] = 0x0;
|
|
||||||
// A known good state. (On, Cool, 24C)
|
// A known good state. (On, Cool, 24C)
|
||||||
remote_state[0] = 0x23;
|
remote_state[0] = 0x23;
|
||||||
remote_state[1] = 0xCB;
|
remote_state[1] = 0xCB;
|
||||||
@ -113,7 +111,7 @@ void Tcl112Climate::transmit_state_() {
|
|||||||
float safecelsius = std::max(this->target_temperature, TCL112_TEMP_MIN);
|
float safecelsius = std::max(this->target_temperature, TCL112_TEMP_MIN);
|
||||||
safecelsius = std::min(safecelsius, TCL112_TEMP_MAX);
|
safecelsius = std::min(safecelsius, TCL112_TEMP_MAX);
|
||||||
// Convert to integer nr. of half degrees.
|
// Convert to integer nr. of half degrees.
|
||||||
uint8_t half_degrees = safecelsius * 2;
|
auto half_degrees = static_cast<uint8_t>(safecelsius * 2);
|
||||||
if (half_degrees & 1) // Do we have a half degree celsius?
|
if (half_degrees & 1) // Do we have a half degree celsius?
|
||||||
remote_state[12] |= TCL112_HALF_DEGREE; // Add 0.5 degrees
|
remote_state[12] |= TCL112_HALF_DEGREE; // Add 0.5 degrees
|
||||||
else
|
else
|
||||||
@ -123,10 +121,10 @@ void Tcl112Climate::transmit_state_() {
|
|||||||
|
|
||||||
// Calculate & set the checksum for the current internal state of the remote.
|
// Calculate & set the checksum for the current internal state of the remote.
|
||||||
// Stored the checksum value in the last byte.
|
// Stored the checksum value in the last byte.
|
||||||
for (uint8_t checksumByte = 0; checksumByte < TCL112_STATE_LENGTH - 1; checksumByte++)
|
for (uint8_t checksum_byte = 0; checksum_byte < TCL112_STATE_LENGTH - 1; checksum_byte++)
|
||||||
remote_state[TCL112_STATE_LENGTH - 1] += remote_state[checksumByte];
|
remote_state[TCL112_STATE_LENGTH - 1] += remote_state[checksum_byte];
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Sending tcl code: %u", remote_state[7]);
|
ESP_LOGV(TAG, "Sending tcl code: %u", remote_state[7]);
|
||||||
|
|
||||||
auto transmit = this->transmitter_->transmit();
|
auto transmit = this->transmitter_->transmit();
|
||||||
auto data = transmit.get_data();
|
auto data = transmit.get_data();
|
||||||
@ -137,10 +135,11 @@ void Tcl112Climate::transmit_state_() {
|
|||||||
data->mark(TCL112_HEADER_MARK);
|
data->mark(TCL112_HEADER_MARK);
|
||||||
data->space(TCL112_HEADER_SPACE);
|
data->space(TCL112_HEADER_SPACE);
|
||||||
// Data
|
// Data
|
||||||
for (uint8_t i = 0; i < TCL112_STATE_LENGTH; i++)
|
for (uint8_t i : remote_state)
|
||||||
for (uint8_t bit = 0; bit < 8; bit++, remote_state[i] >>= 1) {
|
for (uint8_t j = 0; j < 8; j++) {
|
||||||
data->mark(TCL112_BIT_MARK);
|
data->mark(TCL112_BIT_MARK);
|
||||||
data->space((remote_state[i] & 1) ? TCL112_ONE_SPACE : TCL112_ZERO_SPACE);
|
bool bit = i & (1 << j);
|
||||||
|
data->space(bit ? TCL112_ONE_SPACE : TCL112_ZERO_SPACE);
|
||||||
}
|
}
|
||||||
// Footer
|
// Footer
|
||||||
data->mark(TCL112_BIT_MARK);
|
data->mark(TCL112_BIT_MARK);
|
||||||
|
@ -12,8 +12,6 @@ namespace tcl112 {
|
|||||||
|
|
||||||
class Tcl112Climate : public climate::Climate, public Component {
|
class Tcl112Climate : public climate::Climate, public Component {
|
||||||
public:
|
public:
|
||||||
Tcl112Climate(const std::string &name) : climate::Climate(name) {}
|
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) {
|
void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) {
|
||||||
this->transmitter_ = transmitter;
|
this->transmitter_ = transmitter;
|
||||||
@ -31,9 +29,6 @@ class Tcl112Climate : public climate::Climate, public Component {
|
|||||||
/// Transmit via IR the state of this climate controller.
|
/// Transmit via IR the state of this climate controller.
|
||||||
void transmit_state_();
|
void transmit_state_();
|
||||||
|
|
||||||
void send_data_(remote_base::RemoteTransmitData *transmit_data, uint16_t onemark, uint32_t onespace,
|
|
||||||
uint16_t zeromark, uint32_t zerospace, uint64_t data, uint16_t nbits, bool msb_first = true);
|
|
||||||
|
|
||||||
bool supports_cool_{true};
|
bool supports_cool_{true};
|
||||||
bool supports_heat_{true};
|
bool supports_heat_{true};
|
||||||
|
|
||||||
@ -41,5 +36,5 @@ class Tcl112Climate : public climate::Climate, public Component {
|
|||||||
sensor::Sensor *sensor_{nullptr};
|
sensor::Sensor *sensor_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace coolix
|
} // namespace tcl112
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Loading…
x
Reference in New Issue
Block a user