mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
Further code fixes
Fixed use of size()==0 instead of empty() on vectors. Fixed invalid convertions from union to uint8_t in log message.
This commit is contained in:
parent
6c68a4f738
commit
30ee664e4f
2 changed files with 16 additions and 10 deletions
|
@ -281,7 +281,7 @@ bool DS3232Component::read_memory(uint8_t reg_id, std::vector<uint8_t> &data) {
|
|||
ESP_LOGW(TAG, "NVRAM: Memory reset process in progress. Try later.");
|
||||
return false;
|
||||
}
|
||||
if (data.size() == 0) {
|
||||
if (data.empty()) {
|
||||
ESP_LOGW(TAG, "NVRAM: Nothing to write to memory.");
|
||||
return true;
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ bool DS3232Component::read_memory(uint8_t reg_id, std::vector<uint8_t> &data) {
|
|||
}
|
||||
|
||||
bool DS3232Component::write_memory(const uint8_t reg_id, const std::vector<uint8_t> &data) {
|
||||
if (data.size() == 0) {
|
||||
if (data.empty()) {
|
||||
ESP_LOGW(TAG, "NVRAM: Nothing to write to memory.");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ DS3232Alarm DS3232Alarm::create(const bool is_enabled, const DS3232AlarmMode mod
|
|||
alarm.seconds_supported = is_seconds_supported;
|
||||
ESP_LOGVV(TAG, " Seconds supported: %s", YESNO(alarm.seconds_supported));
|
||||
alarm.mode = mode;
|
||||
ESP_LOGVV(TAG, " Mode set to: %.2u (%.2u)", alarm.mode, mode);
|
||||
ESP_LOGVV(TAG, " Mode set to: %.2u (%.2u)", alarm.mode.raw, mode.raw);
|
||||
alarm.second = second;
|
||||
ESP_LOGVV(TAG, " Seconds set to: %.2u (%.2u)", alarm.second, second);
|
||||
alarm.minute = minute;
|
||||
|
@ -89,11 +89,13 @@ std::string DS3232Alarm::to_string() const {
|
|||
return std::string(INVALID);
|
||||
char formatted_string[DS3232_ALARM_FORMAT_STRING_LENGTH];
|
||||
size_t len;
|
||||
switch (this->mode.alarm_mode) {
|
||||
case AlarmMode::EVERY_TIME:
|
||||
switch (this->mode.raw) {
|
||||
//AlarmMode::EVERY_TIME
|
||||
case 15:
|
||||
case 31:
|
||||
return std::string(this->seconds_supported ? FORMAT_STRING_EVERY_TIME_S : FORMAT_STRING_EVERY_TIME_M);
|
||||
case AlarmMode::MATCH_SECONDS:
|
||||
//AlarmMode::MATCH_SECONDS
|
||||
case 14:
|
||||
case 30:
|
||||
if (!this->seconds_supported)
|
||||
return std::string(FORMAT_STRING_EVERY_TIME_M);
|
||||
|
@ -104,7 +106,8 @@ std::string DS3232Alarm::to_string() const {
|
|||
return std::string(INVALID);
|
||||
}
|
||||
return std::string(formatted_string);
|
||||
case AlarmMode::MATCH_MINUTES_SECONDS:
|
||||
//AlarmMode::MATCH_MINUTES_SECONDS
|
||||
case 12:
|
||||
case 28:
|
||||
len = snprintf(formatted_string, sizeof(formatted_string), FORMAT_STRING_EVERY_HOUR, this->minute, this->second);
|
||||
if (len < 0) {
|
||||
|
@ -112,7 +115,8 @@ std::string DS3232Alarm::to_string() const {
|
|||
return std::string(INVALID);
|
||||
}
|
||||
return std::string(formatted_string);
|
||||
case AlarmMode::MATCH_TIME:
|
||||
//AlarmMode::MATCH_TIME
|
||||
case 8:
|
||||
case 24:
|
||||
len = snprintf(formatted_string, sizeof(formatted_string), FORMAT_STRING_EVERY_DAY, this->hour, this->minute,
|
||||
this->second);
|
||||
|
@ -121,7 +125,8 @@ std::string DS3232Alarm::to_string() const {
|
|||
return std::string(INVALID);
|
||||
}
|
||||
return std::string(formatted_string);
|
||||
case AlarmMode::MATCH_DAY_OF_WEEK_AND_TIME:
|
||||
//AlarmMode::MATCH_DAY_OF_WEEK_AND_TIME
|
||||
case 16:
|
||||
len = snprintf(formatted_string, sizeof(formatted_string), FORMAT_STRING_EVERY_WEEK,
|
||||
DAYS_OF_WEEK[this->day_of_week], this->hour, this->minute, this->second);
|
||||
if (len < 0) {
|
||||
|
@ -129,7 +134,8 @@ std::string DS3232Alarm::to_string() const {
|
|||
return std::string(INVALID);
|
||||
}
|
||||
return std::string(formatted_string);
|
||||
case AlarmMode::MATCH_DATE_AND_TIME:
|
||||
//AlarmMode::MATCH_DATE_AND_TIME
|
||||
case 0:
|
||||
len = snprintf(formatted_string, sizeof(formatted_string), FORMAT_STRING_EVERY_MONTH, this->day_of_month,
|
||||
ORDINAL_SUFFIX(this->day_of_month), this->hour, this->minute, this->second);
|
||||
if (len < 0) {
|
||||
|
|
Loading…
Reference in a new issue