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

status entities for battery calibration & balancing #296

Closed
wants to merge 5 commits into from

Conversation

oliverrahner
Copy link
Contributor

@oliverrahner oliverrahner commented Apr 13, 2023

This PR implements #264.
It provides two new binary sensor entities that show whether battery calibration or balancing are currently active:

image

I don't like the naming much, maybe there is a better alternative?

A viable alternative to having two separate entities would be to have only one entity (like Battery Operation Status) with a custom enum state consisting of Calibrating, Balancing, Normal operation.

The current ID generation logic in this integration does not cater for the situation where multiple entities rely on the same set of objects, that's why I needed to "hack" my way around this by adding an actually not used object. I don't fully understand why you didn't rely on the entity key that is defined in entities.py, but there might be good reasons for that.

Last but not least: I am aware that you tried to keep a certain level of abstraction in handling objects, entities and their relation, which gets a bit contradicted by the very explicit methods get_battery_calibration_status and get_battery_balancing_status, but I couldn't come up with a better way.

@weltenwort
Copy link
Owner

Hi @oliverrahner, thanks for opening this PR and for providing such a useful description 😍 I'll try to set some time aside for a review within the next few days.

@weltenwort weltenwort self-requested a review April 15, 2023 22:57
@weltenwort
Copy link
Owner

ℹ️ I took the liberty of merging main into your PR branch so it uses the most recent linting action and dependency versions

@oliverrahner
Copy link
Contributor Author

@weltenwort Is there anything I can do to have this integrated? Do you see any issues that I could solve or is it just lack of time on your end?

@weltenwort
Copy link
Owner

It's indeed just a lack of time 🙈 Sorry to keep you waiting for so long. Thanks for making the changes, I'll try to prioritize looking at it this weekend 🤞

Copy link
Owner

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

Hey @oliverrahner, sorry again for the huge delay. In general you changes make sense, but aren't quite in line with the conventions of HA sets up its platforms. You ran into this problem because you introduced a new platform (binary_sensor), which is meant to be setup from a binary_sensor.py entry point.

Your alternative suggestion for an enum-based sensor wouldn't require that.

Comment on lines +214 to +218
# 'battery.status2' is not required here, this is just a hack
# so that this entity's generated id doesn't conflict with
# "battery.bat_status.calibrating"
# changing the id generation scheme would break existing installations
object_names=["battery.bat_status", "battery.status2"],
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can avoid this hack by setting the unique_id. I honestly don't remember why I'm not using the key either. That's what you get when nobody reviews my code 🙈

Suggested change
# 'battery.status2' is not required here, this is just a hack
# so that this entity's generated id doesn't conflict with
# "battery.bat_status.calibrating"
# changing the id generation scheme would break existing installations
object_names=["battery.bat_status", "battery.status2"],
unique_id="battery.bat_status.balancing",
object_names=["battery.bat_status"],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I didn't think that we could just override the use of a generated id by setting it explicitly. Will change this.

@@ -35,6 +37,15 @@ async def async_setup_entry(
for entity_description in battery_sensor_entity_descriptions
]

battery_binary_sensor_entities = [
Copy link
Owner

Choose a reason for hiding this comment

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

If I understand HA's component architecture correctly, setting up a binary sensor in sensor.py would not be correct. Instead, it should be set up as part of the binary_sensor platform (meaning in binary_sensor.py), which is being delegated to by the __init__.py's loop over the PLATFORMS list (which would also have to be extended to include binary sensors). In light of that I actually like your alternative suggestion of introducing a single sensor that displays the state using an enum. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH, I'm not fully aware of the component architecture, as I never built an integration myself. But it makes sense, even though it just seems to work in my installation without complying with the convention.
But nevertheless, I also think we should go for the enum alternative. I just thought about this after I made the current implementation.
I will refactor this and update the PR once I tested it.

@weltenwort
Copy link
Owner

Hey @oliverrahner, thanks for your willingness to refactor. Since I had the editor open I figured I could also give it a try. I opened oliverrahner#1 against your main branch in case you haven't done any refactoring yourself. Please feel free to close it if you already have a better implementation.

@V4n1X
Copy link

V4n1X commented Jan 16, 2024

Plans to merge these in the next release?

@weltenwort
Copy link
Owner

@oliverrahner thanks again for submitting this. I took the liberty of including your findings with some modifications in #349.

@V4n1X the new "Battery Status" entity has been released in https://github.com/weltenwort/home-assistant-rct-power-integration/releases/tag/v0.12.0.

@weltenwort weltenwort closed this Jan 20, 2024
@oliverrahner
Copy link
Contributor Author

@weltenwort thanks for picking this up again, I lost it out of focus… much appreciated :)

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.

3 participants