-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
Emoncms cleanup #86840
Emoncms cleanup #86840
Conversation
Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
Unless I'm missing something obvious, it is never used in the EmonCmsData class, which is instead decorated by @Throttle(MIN_TIME_BETWEEN_UPDATES) If this is supposed to work then it is a bug. Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
|
Hey there @borpin, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
- apikey is the only parameter, so just create the parameters once at init. - Don't squash the exception when logging it, use logger.exception - Use req.raise_for_status() instead of checking status code manually - Put req.json() in the try block Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
emoncms.org allows Keep-Alive so use a requests.Session object which allows urllib3 connection pooling. Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
Use _attr_name, _attr_native_unit_of_measurement and _attr_native_value. Convert the _identifier into a _attr_unique_id Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
It always takes the same elements of a dict, so just pass the dict. Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
native_value is set twice, so deduplicate the code Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
Set state_class even if the unit of measurement is not recognised, since the value will certainly be numeric or null. Emoncms can only return numeric values or null. Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
c7df0af to
cc25390
Compare
|
Looks good to me. |
|
The CI is failing, please make sure the build passes. |
|
Sorry about that, the build is now passing. Although I'm not sure the resulting code is "better" 😆 |
|
|
||
| if value_template is not None: | ||
| value_template.hass = hass | ||
|
|
||
| data = EmonCmsData(hass, url, apikey, interval) | ||
| assert url is not None and apikey is not None # Keep mypy happy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they are compulsory, then it should be using config[key] not config.get(key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a really good point. I had forgotten I was looking at a dict, rather than some opaque data class 😆 They certainly are compulsory, and marked as Required in the schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be also worried about this PR getting bigger and bigger.
- Adding type hints can usually be a single PR.
- Adding
unique_idprobably can be also it's own PR - and maybe the
state_classin a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if that is the convention. It seems like there will be a lot of admin overheard for adding one line of code at a time but if that's the standard I am happy to comply.
I don't have the time to pull it all apart this week though. Maybe next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not compulsory - but it makes reviewing ssssoooo much easier if the PR is smaller.
It also means that if there is a difference of opinion on one point then the other points can be merged anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK yes I see your point. I guess my view was that a lot of this is just tidying things up and doesn't really improve the user experience, so it makes sense to carry it along with features rather than bothering reviewers to look through multiple PRs.
I am certainly expecting to move the integration to use a config flow in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if you look at the instructions when making a new PR:
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
Don't get me wrong, I can't say I meet these instructions, many times dependency bump is also a bugfix, etc...
However, code quality are usually easy to split out to a new PR, they are also good candidates for people to review since unlike bug fixes which change the code and understanding for the change, code quality usually try to keep the same functionality and is easier to review.
There is no overhead from creating multiple PRs (@epenet is expert in creating huge number of PRs ❤️), the opposite, it makes easier to review small PRs, although this PR is still in a reasonable size (EDIT: or even small size).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that makes sense, thanks for explaining 😄 Unfortunately I have lots of work to do this week but I hope I will be able to sort out my mess next week 😄 Thanks again! ❤️
Signed-off-by: Bruce Duncan <bwduncan@gmail.com>
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Be good if this could be progressed. |
| def native_value(self): | ||
| """Return the state of the device.""" | ||
| return self._state | ||
| def native_value(self) -> str | float | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this property and use attr_native_value directly in the update instead.
| """Initialize the data object.""" | ||
| self._apikey = apikey | ||
| self._sess = requests.Session() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would not be allowed. See https://developers.home-assistant.io/docs/development_checklist
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@bwduncan - do you think you will get a chance to look at this again? |
|
I can try. If the requirement to tidy this up a bit is to create an entire package on pypi just to wrap requests.Session then I don't think I have the appetite for that... |
|
Because there hasn't been any activity on this PR for quite some time now, I've decided to close it for being stale. Feel free to re-open this PR when you are ready to pick up work on it again 👍 |

Breaking change
Proposed change
Tidy up the code a bit and add some of the newer changes in HA. Specifically, this adds
unique_idand sets thestate_classfor all sensors.Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: