mirror of
https://github.com/esphome/esphome.git
synced 2026-01-19 09:36:24 -07:00
Compare commits
1 Commits
integratio
...
pipsolar_t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70fb561ce1 |
@@ -13,7 +13,7 @@ void PipsolarOutput::write_state(float state) {
|
||||
|
||||
if (std::find(this->possible_values_.begin(), this->possible_values_.end(), state) != this->possible_values_.end()) {
|
||||
ESP_LOGD(TAG, "Will write: %s out of value %f / %02.0f", tmp, state, state);
|
||||
this->parent_->queue_command(std::string(tmp));
|
||||
this->parent_->queue_command(tmp);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Will not write: %s as it is not in list of allowed values", tmp);
|
||||
}
|
||||
|
||||
@@ -45,20 +45,20 @@ void Pipsolar::loop() {
|
||||
} else {
|
||||
ESP_LOGD(TAG, "command not successful");
|
||||
}
|
||||
this->command_queue_[this->command_queue_position_] = std::string("");
|
||||
this->command_queue_[this->command_queue_position_].clear();
|
||||
this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH;
|
||||
this->state_ = STATE_IDLE;
|
||||
} else {
|
||||
// crc failed
|
||||
// no log message necessary, check_incoming_crc_() logs
|
||||
this->command_queue_[this->command_queue_position_] = std::string("");
|
||||
this->command_queue_[this->command_queue_position_].clear();
|
||||
this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH;
|
||||
this->state_ = STATE_IDLE;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGD(TAG, "command %s response length not OK: with length %zu",
|
||||
this->command_queue_[this->command_queue_position_].c_str(), this->read_pos_);
|
||||
this->command_queue_[this->command_queue_position_] = std::string("");
|
||||
this->command_queue_[this->command_queue_position_].clear();
|
||||
this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH;
|
||||
this->state_ = STATE_IDLE;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ void Pipsolar::loop() {
|
||||
const char *command = this->command_queue_[this->command_queue_position_].c_str();
|
||||
this->command_start_millis_ = millis();
|
||||
ESP_LOGD(TAG, "command %s timeout", command);
|
||||
this->command_queue_[this->command_queue_position_] = std::string("");
|
||||
this->command_queue_[this->command_queue_position_].clear();
|
||||
this->command_queue_position_ = (command_queue_position_ + 1) % COMMAND_QUEUE_LENGTH;
|
||||
this->state_ = STATE_IDLE;
|
||||
return;
|
||||
@@ -722,7 +722,7 @@ void Pipsolar::publish_binary_sensor_(esphome::optional<bool> b, binary_sensor::
|
||||
}
|
||||
}
|
||||
|
||||
esphome::optional<bool> Pipsolar::get_bit_(std::string bits, uint8_t bit_pos) {
|
||||
esphome::optional<bool> Pipsolar::get_bit_(const std::string &bits, uint8_t bit_pos) {
|
||||
if (bit_pos >= bits.length()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ class Pipsolar : public uart::UARTDevice, public PollingComponent {
|
||||
|
||||
void publish_binary_sensor_(esphome::optional<bool> b, binary_sensor::BinarySensor *sensor);
|
||||
|
||||
esphome::optional<bool> get_bit_(std::string bits, uint8_t bit_pos);
|
||||
esphome::optional<bool> get_bit_(const std::string &bits, uint8_t bit_pos);
|
||||
|
||||
std::string command_queue_[COMMAND_QUEUE_LENGTH];
|
||||
uint8_t command_queue_position_ = 0;
|
||||
|
||||
@@ -4,8 +4,7 @@ namespace esphome {
|
||||
namespace teleinfo {
|
||||
|
||||
static const char *const TAG = "teleinfo_sensor";
|
||||
TeleInfoSensor::TeleInfoSensor(const char *tag) { this->tag = std::string(tag); }
|
||||
void TeleInfoSensor::publish_val(const std::string &val) {
|
||||
void TeleInfoSensor::publish_val(const char *val) {
|
||||
auto newval = parse_number<float>(val).value_or(0.0f);
|
||||
publish_state(newval);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace teleinfo {
|
||||
|
||||
class TeleInfoSensor : public TeleInfoListener, public sensor::Sensor, public Component {
|
||||
public:
|
||||
TeleInfoSensor(const char *tag);
|
||||
void publish_val(const std::string &val) override;
|
||||
TeleInfoSensor(const char *tag) { this->tag = tag; }
|
||||
void publish_val(const char *val) override;
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -172,15 +172,15 @@ void TeleInfo::loop() {
|
||||
/* Advance buf_finger to end of group */
|
||||
buf_finger += field_len + 1 + 1 + 1;
|
||||
|
||||
publish_value_(std::string(tag_), std::string(val_));
|
||||
publish_value_(tag_, val_);
|
||||
}
|
||||
state_ = OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void TeleInfo::publish_value_(const std::string &tag, const std::string &val) {
|
||||
void TeleInfo::publish_value_(const char *tag, const char *val) {
|
||||
for (auto *element : teleinfo_listeners_) {
|
||||
if (tag != element->tag)
|
||||
if (strcmp(tag, element->tag) != 0)
|
||||
continue;
|
||||
element->publish_val(val);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ static const uint16_t MAX_TIMESTAMP_SIZE = 14;
|
||||
|
||||
class TeleInfoListener {
|
||||
public:
|
||||
std::string tag;
|
||||
virtual void publish_val(const std::string &val){};
|
||||
const char *tag{nullptr};
|
||||
virtual void publish_val(const char *val){};
|
||||
};
|
||||
class TeleInfo : public PollingComponent, public uart::UARTDevice {
|
||||
public:
|
||||
@@ -48,7 +48,7 @@ class TeleInfo : public PollingComponent, public uart::UARTDevice {
|
||||
} state_{OFF};
|
||||
bool read_chars_until_(bool drop, uint8_t c);
|
||||
bool check_crc_(const char *grp, const char *grp_end);
|
||||
void publish_value_(const std::string &tag, const std::string &val);
|
||||
void publish_value_(const char *tag, const char *val);
|
||||
};
|
||||
} // namespace teleinfo
|
||||
} // namespace esphome
|
||||
|
||||
@@ -4,8 +4,7 @@ namespace esphome {
|
||||
namespace teleinfo {
|
||||
|
||||
static const char *const TAG = "teleinfo_text_sensor";
|
||||
TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); }
|
||||
void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); }
|
||||
void TeleInfoTextSensor::publish_val(const char *val) { publish_state(val); }
|
||||
void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", "Teleinfo Text Sensor", this); }
|
||||
} // namespace teleinfo
|
||||
} // namespace esphome
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace esphome {
|
||||
namespace teleinfo {
|
||||
class TeleInfoTextSensor : public TeleInfoListener, public text_sensor::TextSensor, public Component {
|
||||
public:
|
||||
TeleInfoTextSensor(const char *tag);
|
||||
void publish_val(const std::string &val) override;
|
||||
TeleInfoTextSensor(const char *tag) { this->tag = tag; }
|
||||
void publish_val(const char *val) override;
|
||||
void dump_config() override;
|
||||
};
|
||||
} // namespace teleinfo
|
||||
|
||||
Reference in New Issue
Block a user