mirror of
https://github.com/esphome/esphome.git
synced 2026-05-20 09:31:56 +08:00
[online_image][sim800l] Use std::string::starts_with for prefix checks (#16097)
This commit is contained in:
@@ -28,7 +28,7 @@ bool OnlineImage::validate_url_(const std::string &url) {
|
||||
ESP_LOGE(TAG, "URL is too long");
|
||||
return false;
|
||||
}
|
||||
if (url.compare(0, 7, "http://") != 0 && url.compare(0, 8, "https://") != 0) {
|
||||
if (!url.starts_with("http://") && !url.starts_with("https://")) {
|
||||
ESP_LOGE(TAG, "URL must start with http:// or https://");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
case STATE_INIT: {
|
||||
// While we were waiting for update to check for messages, this notifies a message
|
||||
// is available.
|
||||
bool message_available = message.compare(0, 6, "+CMTI:") == 0;
|
||||
bool message_available = message.starts_with("+CMTI:");
|
||||
if (!message_available) {
|
||||
if (message == "RING") {
|
||||
// Incoming call...
|
||||
@@ -120,7 +120,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
this->call_state_ = 6;
|
||||
this->call_disconnected_callback_.call();
|
||||
}
|
||||
} else if (message.compare(0, 6, "+CUSD:") == 0) {
|
||||
} else if (message.starts_with("+CUSD:")) {
|
||||
// Incoming USSD MESSAGE
|
||||
this->state_ = STATE_CHECK_USSD;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
break;
|
||||
case STATE_CHECK_USSD:
|
||||
ESP_LOGD(TAG, "Check ussd code: '%s'", message.c_str());
|
||||
if (message.compare(0, 6, "+CUSD:") == 0) {
|
||||
if (message.starts_with("+CUSD:")) {
|
||||
this->state_ = STATE_RECEIVED_USSD;
|
||||
this->ussd_ = "";
|
||||
size_t start = 10;
|
||||
@@ -196,8 +196,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
case STATE_CREG_WAIT: {
|
||||
// Response: "+CREG: 0,1" -- the one there means registered ok
|
||||
// "+CREG: -,-" means not registered ok
|
||||
bool registered =
|
||||
message.size() > 9 && message.compare(0, 6, "+CREG:") == 0 && (message[9] == '1' || message[9] == '5');
|
||||
bool registered = message.size() > 9 && message.starts_with("+CREG:") && (message[9] == '1' || message[9] == '5');
|
||||
if (registered) {
|
||||
if (!this->registered_) {
|
||||
ESP_LOGD(TAG, "Registered OK");
|
||||
@@ -223,7 +222,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
this->state_ = STATE_CSQ_RESPONSE;
|
||||
break;
|
||||
case STATE_CSQ_RESPONSE:
|
||||
if (message.compare(0, 5, "+CSQ:") == 0) {
|
||||
if (message.starts_with("+CSQ:")) {
|
||||
size_t comma = message.find(',', 6);
|
||||
if (comma != 6) {
|
||||
int rssi = parse_number<int>(message.substr(6, comma - 6)).value_or(0);
|
||||
@@ -243,7 +242,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
this->state_ = STATE_CHECK_SMS;
|
||||
break;
|
||||
case STATE_PARSE_SMS_RESPONSE:
|
||||
if (message.compare(0, 6, "+CMGL:") == 0 && this->parse_index_ == 0) {
|
||||
if (message.starts_with("+CMGL:") && this->parse_index_ == 0) {
|
||||
size_t start = 7;
|
||||
size_t end = message.find(',', start);
|
||||
uint8_t item = 0;
|
||||
@@ -278,7 +277,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
}
|
||||
break;
|
||||
case STATE_CHECK_CALL:
|
||||
if (message.compare(0, 6, "+CLCC:") == 0 && this->parse_index_ == 0) {
|
||||
if (message.starts_with("+CLCC:") && this->parse_index_ == 0) {
|
||||
this->expect_ack_ = true;
|
||||
size_t start = 7;
|
||||
size_t end = message.find(',', start);
|
||||
@@ -324,7 +323,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
/* Our recipient is set and the message body is in message
|
||||
kick ESPHome callback now
|
||||
*/
|
||||
if (ok || message.compare(0, 6, "+CMGL:") == 0) {
|
||||
if (ok || message.starts_with("+CMGL:")) {
|
||||
ESP_LOGD(TAG,
|
||||
"Received SMS from: %s\n"
|
||||
" %s",
|
||||
@@ -360,7 +359,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
}
|
||||
break;
|
||||
case STATE_SENDING_SMS_3:
|
||||
if (message.compare(0, 6, "+CMGS:") == 0) {
|
||||
if (message.starts_with("+CMGS:")) {
|
||||
ESP_LOGD(TAG, "SMS Sent OK: %s", message.c_str());
|
||||
this->send_pending_ = false;
|
||||
this->state_ = STATE_CHECK_SMS;
|
||||
@@ -383,7 +382,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
this->state_ = STATE_INIT;
|
||||
break;
|
||||
case STATE_PARSE_CLIP:
|
||||
if (message.compare(0, 6, "+CLIP:") == 0) {
|
||||
if (message.starts_with("+CLIP:")) {
|
||||
std::string caller_id;
|
||||
size_t start = 7;
|
||||
size_t end = message.find(',', start);
|
||||
|
||||
Reference in New Issue
Block a user