Skip to content

Conversation

@bubonicbob
Copy link
Contributor

@bubonicbob bubonicbob commented Jan 19, 2024

Proposed change

Add batteries as devices with their own individual sensors. Making this PR to get early feedback on the direction of adding the devices and basic structure for adding a sensor.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @bdraco, @jrester, @daniel-simpson, mind taking a look at this pull request as it has been labeled with an integration (powerwall) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of powerwall can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign powerwall Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@bubonicbob bubonicbob marked this pull request as ready for review January 20, 2024 23:29
@bubonicbob bubonicbob requested a review from bdraco as a code owner January 20, 2024 23:29
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Please see comments above.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft January 27, 2024 03:29
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@bubonicbob bubonicbob force-pushed the powerwall_batterydevice branch from f3cdd18 to 8fb7d46 Compare January 28, 2024 17:12
@bubonicbob
Copy link
Contributor Author

I need some help testing this out. I am only able to run unit tests.

@bdraco bdraco mentioned this pull request Jan 28, 2024
20 tasks
@bubonicbob bubonicbob force-pushed the powerwall_batterydevice branch from f94154d to 989593b Compare January 30, 2024 23:33
@bubonicbob
Copy link
Contributor Author

bubonicbob commented Jan 30, 2024

I need some help testing this out. I am only able to run unit tests.

I did end up testing this by creating a simulated powerwall server using cached results from a multi-powerwall installation. It shows each battery bank as a separate device with individual sensor entities for each as expected.

@bubonicbob
Copy link
Contributor Author

Not sure if it's still marked as draft on purpose?

Oh I'll change that. I was waiting for the other PRs to merge, but now they're done.

@bubonicbob
Copy link
Contributor Author

Looks good to me on my phone at least, are you looking to get this in before beta in the morning?

Whenever you feel comfortable. Doesn't have to be.

@bubonicbob bubonicbob marked this pull request as ready for review January 31, 2024 03:22
@home-assistant home-assistant bot requested a review from bdraco January 31, 2024 03:22
@bdraco
Copy link
Member

bdraco commented Jan 31, 2024

I'll try to load this on my production before my flight takes off

@bdraco bdraco added smash Indicator this PR is close to finish for merging or closing docs-missing labels Jan 31, 2024
@bdraco
Copy link
Member

bdraco commented Jan 31, 2024

One small review comment, and should be good to merge once a docs PR is opened and linked since we do document which sensors are expected https://www.home-assistant.io/integrations/powerwall/

@bubonicbob
Copy link
Contributor Author

One small review comment, and should be good to merge once a docs PR is opened and linked since we do document which sensors are expected https://www.home-assistant.io/integrations/powerwall/

No problem.

I am a little confused by the terminology on the docs page though. When somebody says "Powerwall" in the context of the integration, they are actually referring to a gateway whereas the "powerwall" I would think of is the actual battery bank + inverter. If I look at the Tesla marketing page for purchasing a Powerwall, they list specifically a single battery bank and inverter spec and they say you can "stack up to 10 Powerwalls" in a single installation. I presume that all those Powerwalls would be accessed via a single gateway.

@bdraco
Copy link
Member

bdraco commented Jan 31, 2024

One small review comment, and should be good to merge once a docs PR is opened and linked since we do document which sensors are expected https://www.home-assistant.io/integrations/powerwall/

No problem.

I am a little confused by the terminology on the docs page though. When somebody says "Powerwall" in the context of the integration, they are actually referring to a gateway whereas the "powerwall" I would think of is the actual battery bank + inverter. If I look at the Tesla marketing page for purchasing a Powerwall, they list specifically a single battery bank and inverter spec and they say you can "stack up to 10 Powerwalls" in a single installation. I presume that all those Powerwalls would be accessed via a single gateway.

Normally that's the most common to use a single gateway. Apparently you can have multiple gateways though I've never seen that configuration in person.

It would be fine to adjust the docs to make it more clear that we are connecting to a gateway

bubonicbob added a commit to bubonicbob/home-assistant.io that referenced this pull request Jan 31, 2024
Add documentation for new sensors added in home-assistant/core#108339.   Also clarifies the different sensors per Backup Gateway and per Powerwall
bubonicbob added a commit to bubonicbob/home-assistant.io that referenced this pull request Jan 31, 2024
Add documentation for new sensors added in home-assistant/core#108339.   Also clarifies the different sensors per Backup Gateway and per Powerwall
@bubonicbob
Copy link
Contributor Author

One small review comment, and should be good to merge once a docs PR is opened and linked since we do document which sensors are expected https://www.home-assistant.io/integrations/powerwall/

No problem.
I am a little confused by the terminology on the docs page though. When somebody says "Powerwall" in the context of the integration, they are actually referring to a gateway whereas the "powerwall" I would think of is the actual battery bank + inverter. If I look at the Tesla marketing page for purchasing a Powerwall, they list specifically a single battery bank and inverter spec and they say you can "stack up to 10 Powerwalls" in a single installation. I presume that all those Powerwalls would be accessed via a single gateway.

Normally that's the most common to use a single gateway. Apparently you can have multiple gateways though I've never seen that configuration in person.

It would be fine to adjust the docs to make it more clear that we are connecting to a gateway

Ok, I should have made a docs PR targeting the "next" branch. home-assistant/home-assistant.io#31158

Hope that's the right thing to do.

_attr_has_entity_name = True

def __init__(
self, powerwall_data: PowerwallRuntimeData, battery: BatteryResponse
Copy link
Member

@bdraco bdraco Jan 31, 2024

Choose a reason for hiding this comment

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

It would be so much better if PowerwallRuntimeData was a dataclass as we wouldn't have to use as many type hints. This integration predates us being able to use dataclasses so it's never been converted.

@bdraco bdraco merged commit b629ad9 into home-assistant:dev Jan 31, 2024
@bdraco
Copy link
Member

bdraco commented Jan 31, 2024

Thanks @bubonicbob

@bubonicbob bubonicbob deleted the powerwall_batterydevice branch January 31, 2024 05:04

def _get_battery_charge(battery_data: BatteryResponse) -> float:
"""Get the current value in %."""
ratio = float(battery_data.energy_remaining) / float(battery_data.capacity)
Copy link
Member

@MartinHjelmare MartinHjelmare Jan 31, 2024

Choose a reason for hiding this comment

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

We don't allow calculating state of entities in integrations that integrate devices or services. The API data should be shown as is, while following our entity design guidelines. Only exception is around time state. Please remove this sensor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure! What is the alternative to provide the same information to the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

State of charge for batteries is naturally a computation based on models for the battery chemistry, so wouldn't it make sense that it is a computed value? Either the computation is done explicitly here or buried lower in the stack in support libraries or in the firmware of the powerwall that this is representing.

I'm happy to update this to meet any guidelines, but please go easy on me since these are my first contributions and I'd like to get to learn HA. :)

Copy link
Member

Choose a reason for hiding this comment

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

The other option is to have the underlying library return the value so we don't do the calculation in HA

@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants