Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce parse_number() helper function #2659

Merged
merged 6 commits into from
Nov 10, 2021

Conversation

oxan
Copy link
Member

@oxan oxan commented Nov 3, 2021

What does this implement/fix?

This is the first in a series to clean-up helpers.h and helpers.cpp, and to provide consistently-named, generic helper functions. Final result will look something like this (but note that not everything in there is working/tested yet).

Introduce the parse_number() template function that properly parses a decimal number:

  • Overloads for std::string and C-style strings
  • Returns optional<T>
  • Checks for over- and underflow
  • Does not accept trailing garbage

Convert all uses of the existing parse_int() and parse_float() helpers, and drops them.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @buxtronix, mind taking a look at this pull request as it has been labeled with an integration (anova) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @andreashergert1984, mind taking a look at this pull request as it has been labeled with an integration (pipsolar) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @0hax, mind taking a look at this pull request as it has been labeled with an integration (teleinfo) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @ssieb, mind taking a look at this pull request as it has been labeled with an integration (ezo) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @netmikey, mind taking a look at this pull request as it has been labeled with an integration (hrxl_maxsonar_wr) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @glmnet, mind taking a look at this pull request as it has been labeled with an integration (sim800l) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

probot-esphome bot commented Nov 3, 2021

Hey there @OttoWinter, mind taking a look at this pull request as it has been labeled with an integration (homeassistant) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@jesserockz jesserockz merged commit 15f9677 into esphome:dev Nov 10, 2021
@oxan oxan deleted the helpers/parse-number branch November 10, 2021 18:19
@jesserockz jesserockz mentioned this pull request Nov 10, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants