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

Fixes millis errors #116

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fixes millis errors #116

wants to merge 5 commits into from

Conversation

Maxxxel
Copy link

@Maxxxel Maxxxel commented Jan 4, 2025

I had problems compiling the project locally with esphome run example.yaml

This PR fixes the problem.
resource: https://community.home-assistant.io/t/esphome-version-2021-10-0-breaks-my-project/348906

@ginkage
Copy link
Owner

ginkage commented Jan 5, 2025

Why is the diff so big, did indentation change as well? Is there a way to minimise the diff?

@Maxxxel
Copy link
Author

Maxxxel commented Jan 5, 2025

Why is the diff so big, did indentation change as well? Is there a way to minimise the diff?

The class needs to be wrapped in a esphome namespace, else it won't work. So most of the indentation changed hence the number of changed lines.

@ginkage
Copy link
Owner

ginkage commented Jan 5, 2025

It's somewhat uncommon in C++ to introduce extra indentation when adding a namespace. Makes diff harder to read, too.

@Maxxxel
Copy link
Author

Maxxxel commented Jan 5, 2025

It's somewhat uncommon in C++ to introduce extra indentation when adding a namespace. Makes diff harder to read, too.

Sorry, I'm no c++ Dev 🤫🥺

@ginkage
Copy link
Owner

ginkage commented Jan 5, 2025

I mean, take a look at what e.g. esphome source code itself looks like in such cases: https://github.com/esphome/esphome/blob/dev/esphome/components/climate_ir/climate_ir.cpp ;)
So yeah, please remove the extra indent, it's not needed anyway. :)

changed indentaiton
@Maxxxel
Copy link
Author

Maxxxel commented Jan 6, 2025

Updated.

@@ -39,7 +39,9 @@ static const std::vector<std::string> protection_states = {

static const char* TAG = "mhi_ac_ctrl";

unsigned long room_temp_api_timeout_ms = millis();
unsigned long room_temp_api_timeout_ms = esphome::millis();
Copy link
Contributor

@arpiecodes arpiecodes Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you could move this line within the esphome namespace block, so it's defined within the proper scope. Also, no need for the esphome:: prefix on millis() here if you do that.

@@ -150,9 +152,9 @@ class MhiAcCtrl : public climate::Climate,
}
void loop() override
{
if(millis() - room_temp_api_timeout_ms >= room_temp_api_timeout*1000) {
if(esphome::millis() - room_temp_api_timeout_ms >= room_temp_api_timeout*1000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have to prefix every call to millis() with the esphome:: prefix while already within the esphome namespace.

@oliv3r
Copy link

oliv3r commented Jan 16, 2025

That post seems to come from 2021, and I'm seeing 0 compilation or runtime errors. Are we sure this is still relevant? Or are our compile options hiding warnings?

(I'm using the docker container, so who knows :p)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants