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

Selects! Numbers! Buttons! ... and more ;) #75

Merged
merged 11 commits into from
Jan 15, 2025

Conversation

RustyDust
Copy link
Collaborator

Inspired by #74 and spurred on by the recent success with services/actions I had a closer look at how to implement selects, sliders and whatnot. This is the result with some added goodies

Main stuff

You'll now get some new inputs that are shown with the device under the "Configuration" section:

  • a "select" entity to switch the operating mode between "manual", "automatic" and "timeofuse" (yes, "expansion" is
    excluded on purpose)
  • two sliders to set the "charge" or "discharge" power of in W.
  • three buttons to reset either "charge" or "discharge" or both to 0W
    Bildschirmfoto 2025-01-11 um 01 33 48

There's a lot of code added to make those work. Don't despair, I intend to clean that up if possible.

Warning

When using the sliders, buttons and the selector in the developer tools the help text states that there will be no communication with the device. That's not true here. All changes will be sent to the SonnenBatterie immediately.

Candies

  • Found and fixed a bug that caused "production_w" (legacy sensor name, new name is "state_prodcution") to not show up in the sensor list under a recognizable name. It was caused by the translation entry being named "state_poduction_w" instead of "state_production". This fix might also fix the problem reported by @whiteman7 in Integration doesn’t update entities #65
  • Added some more icons to various sensors, hope you like it
  • Added more information to the device info shown on the device screen
    Bildschirmfoto 2025-01-11 um 01 34 42

Under the hood

Coordinator

Completely reworked the coordinator. Instead of passing around the credentials and using different client sessions for every sub-section, the integration now uses one connection to rule them do it all. The central connection object is now passed around in the hass.data[DOMAIN][config_entry.entry_id]["coordinator"]global scope of HA.
Also, to prevent timeouts when querying the SonnenBatterie, the coordinator now automatically reconnects if the last "login" to the SonnenBatterie API is older than 60 seconds.

Services et al.

For better readability and easier maintenance all sub sections are now split out into different files:

  • service.py for the services/actions
  • button.py for the buttons
  • number.py for number inputs/sliders
  • sensor.py well, for the sensors, actually that one isn't new
  • select.py for the selctors
  • entities.py is the central hub that holds all the helper classes for the files above and also contains the base definitions for selects, numbers and buttons

Finally

Have fun ;)

- split out services into own file
- use global coordinator passed around in hacs.data
- optimize data gathering a bit
- update device info to show hardware version in HA
- update device info to show detailled firmware version

Signed-off-by: stefan <[email protected]>
Signed-off-by: stefan <[email protected]>
Signed-off-by: stefan <[email protected]>
@RustyDust RustyDust requested a review from weltmeyer January 11, 2025 00:35
This was linked to issues Jan 11, 2025
@weltmeyer
Copy link
Owner

weltmeyer commented Jan 11, 2025

Wow.. nearly a rewrite :)

But.. did we loose Units?
image

In my Prod-Env it looks like this:
image

@weltmeyer
Copy link
Owner

Wow.. nearly a rewrite :)

But.. did we loose Units?

Never mind! Units came back after a few minutes

@RustyDust
Copy link
Collaborator Author

Never mind! Units came back after a few minutes

To my recollection I didn't change anything there (sensor_list.py) besides some icons. Still wondering why it took some time for them to show up for you. Browser cache?

…rmeter

generation/fixup out of try/except

Signed-off-by: stefan <[email protected]>
@weltmeyer
Copy link
Owner

Never mind! Units came back after a few minutes

To my recollection I didn't change anything there (sensor_list.py) besides some icons. Still wondering why it took some time for them to show up for you. Browser cache?

yepp i think it was browser cache.

as this version ran a few days without errors on my side i'll merge this pr

@weltmeyer weltmeyer merged commit b82a963 into weltmeyer:master Jan 15, 2025
2 checks passed
@RustyDust RustyDust deleted the more_global_data branch January 15, 2025 14:53
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.

Feature request for actions Integration doesn’t update entities
2 participants