From 3c97b0f08374761686209deecec708e37be77b21 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 16 May 2019 11:48:27 +0200 Subject: [PATCH] Updates --- esphome/components/tcl112/climate.py | 2 +- esphome/components/tcl112/tcl112.cpp | 19 +++++++++---------- esphome/components/tcl112/tcl112.h | 7 +------ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/esphome/components/tcl112/climate.py b/esphome/components/tcl112/climate.py index 044bf7c0e4..d24dd6855f 100644 --- a/esphome/components/tcl112/climate.py +++ b/esphome/components/tcl112/climate.py @@ -6,7 +6,7 @@ from esphome.const import CONF_ID, CONF_NAME, CONF_SENSOR AUTO_LOAD = ['sensor'] 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_SUPPORTS_HEAT = 'supports_heat' diff --git a/esphome/components/tcl112/tcl112.cpp b/esphome/components/tcl112/tcl112.cpp index 9101dcd089..cbe2f53402 100644 --- a/esphome/components/tcl112/tcl112.cpp +++ b/esphome/components/tcl112/tcl112.cpp @@ -74,10 +74,8 @@ void Tcl112Climate::control(const climate::ClimateCall &call) { } 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) remote_state[0] = 0x23; remote_state[1] = 0xCB; @@ -113,7 +111,7 @@ void Tcl112Climate::transmit_state_() { float safecelsius = std::max(this->target_temperature, TCL112_TEMP_MIN); safecelsius = std::min(safecelsius, TCL112_TEMP_MAX); // Convert to integer nr. of half degrees. - uint8_t half_degrees = safecelsius * 2; + auto half_degrees = static_cast(safecelsius * 2); if (half_degrees & 1) // Do we have a half degree celsius? remote_state[12] |= TCL112_HALF_DEGREE; // Add 0.5 degrees else @@ -123,10 +121,10 @@ void Tcl112Climate::transmit_state_() { // Calculate & set the checksum for the current internal state of the remote. // Stored the checksum value in the last byte. - for (uint8_t checksumByte = 0; checksumByte < TCL112_STATE_LENGTH - 1; checksumByte++) - remote_state[TCL112_STATE_LENGTH - 1] += remote_state[checksumByte]; + for (uint8_t checksum_byte = 0; checksum_byte < TCL112_STATE_LENGTH - 1; checksum_byte++) + 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 data = transmit.get_data(); @@ -137,10 +135,11 @@ void Tcl112Climate::transmit_state_() { data->mark(TCL112_HEADER_MARK); data->space(TCL112_HEADER_SPACE); // Data - for (uint8_t i = 0; i < TCL112_STATE_LENGTH; i++) - for (uint8_t bit = 0; bit < 8; bit++, remote_state[i] >>= 1) { + for (uint8_t i : remote_state) + for (uint8_t j = 0; j < 8; j++) { 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 data->mark(TCL112_BIT_MARK); diff --git a/esphome/components/tcl112/tcl112.h b/esphome/components/tcl112/tcl112.h index 501fb24cb3..0b80dedbef 100644 --- a/esphome/components/tcl112/tcl112.h +++ b/esphome/components/tcl112/tcl112.h @@ -12,8 +12,6 @@ namespace tcl112 { class Tcl112Climate : public climate::Climate, public Component { public: - Tcl112Climate(const std::string &name) : climate::Climate(name) {} - void setup() override; void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) { this->transmitter_ = transmitter; @@ -31,9 +29,6 @@ class Tcl112Climate : public climate::Climate, public Component { /// Transmit via IR the state of this climate controller. 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_heat_{true}; @@ -41,5 +36,5 @@ class Tcl112Climate : public climate::Climate, public Component { sensor::Sensor *sensor_{nullptr}; }; -} // namespace coolix +} // namespace tcl112 } // namespace esphome