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

Update powerwall for tesla_powerwall 0.5.0 which is async #107164

Merged
merged 17 commits into from
Jan 10, 2024

Conversation

bubonicbob
Copy link
Contributor

@bubonicbob bubonicbob commented Jan 4, 2024

Proposed change

Updates the tesla-powerwall library to 0.5.0 and therefore requires a few async updates to the component.

changelog: jrester/tesla_powerwall@v0.4.0...v0.5.0

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:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @bubonicbob

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

home-assistant bot commented Jan 4, 2024

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
Copy link
Contributor Author

Since I don't have a powerwall, I need some help to update the fixture data so that the tests will pass. I saw these samples from a similar project but still the powerwall firmware is a few years old.

Also accepting donations to get my own powerwall(s)! 💰

@bdraco
Copy link
Member

bdraco commented Jan 4, 2024

I have power walls and I have access to 5 powerwall sites as well so I will test this throughly before merging

@bdraco

This comment was marked as outdated.

@bdraco
Copy link
Member

bdraco commented Jan 7, 2024

I fixed the cookie authentication and improve the error reporting a bit

Everything seems to be working now

@bdraco
Copy link
Member

bdraco commented Jan 7, 2024

Pushing to a production system for additional testing

@bdraco
Copy link
Member

bdraco commented Jan 7, 2024

One system went well

The other one had the order of the serial numbers change so it generated a new unique id and all new entities

@bdraco
Copy link
Member

bdraco commented Jan 7, 2024

I don't think there is anything we can do about the unique id order without doing the migration first

@bubonicbob
Copy link
Contributor Author

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.

In the future, is there an official way to request that a CI be started? According to the process, I should wait to click the "ready for review" until after CI has passed.

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Once we accept a PR and merge, you won't have to ask for the CI to be started anymore

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

bdraco commented Jan 10, 2024

Need to check if that config flow line is covered, config flows are supposed to have 100% coverage before merging, but if it's existing we can override it

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Missing coverage is new on the config flow so we do need to fix that

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

before

---------- coverage: platform darwin, python 3.12.1-final-0 ----------
Name                                                  Stmts   Miss  Cover   Missing
-----------------------------------------------------------------------------------
homeassistant/components/powerwall/binary_sensor.py      59      0   100%
homeassistant/components/powerwall/config_flow.py       122      0   100%
homeassistant/components/powerwall/const.py              14      0   100%
homeassistant/components/powerwall/entity.py             17      0   100%
homeassistant/components/powerwall/models.py             28      0   100%
homeassistant/components/powerwall/sensor.py            103      1    99%   196
homeassistant/components/powerwall/switch.py             37      0   100%
-----------------------------------------------------------------------------------
TOTAL                                                   380      1    99%

after

---------- coverage: platform darwin, python 3.12.1-final-0 ----------
Name                                                  Stmts   Miss  Cover   Missing
-----------------------------------------------------------------------------------
homeassistant/components/powerwall/binary_sensor.py      62      1    98%   139
homeassistant/components/powerwall/config_flow.py       134      1    99%   56
homeassistant/components/powerwall/const.py              13      0   100%
homeassistant/components/powerwall/entity.py             17      0   100%
homeassistant/components/powerwall/models.py             26      0   100%
homeassistant/components/powerwall/sensor.py            110      4    96%   180, 200, 256, 276
homeassistant/components/powerwall/switch.py             37      0   100%
-----------------------------------------------------------------------------------
TOTAL                                                   399      6    98%

@bubonicbob
Copy link
Contributor Author

Need to check if that config flow line is covered, config flows are supposed to have 100% coverage before merging, but if it's existing we can override it

Hmm, all but one are technically new uncovered lines of code but I'd have to think about how to even test them. They all have to do when a sensor meter isn't available. Perhaps the code should make more usage of Entity.avaliable to guard against the runtime case where the meter is None? Even so it wouldn't show up in codecov.

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

I'll take care of the sensor tests

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

I took care of the config flow test as well. I didn't think it was fair to ask you to do that since the coverage wasn't great for that in the first place

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Also if you like, you should add yourself to codeowners in manifiest.json

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

I am updating the other sites now

cd /config
curl -o- -sSL https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d powerwall -p 107164

@bubonicbob
Copy link
Contributor Author

I took care of the config flow test as well. I didn't think it was fair to ask you to do that since the coverage wasn't great for that in the first place

Oh thank you! My partner is giving me sideways glances how much time I'm spending on this anyhow. 👀

@bubonicbob
Copy link
Contributor Author

Also if you like, you should add yourself to codeowners in manifiest.json

I might have to hold off on that until the day I get my own powerwall. It was a big productivity limitation for me on this and made it much harder to understand the HA portion of the code.

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Looks like we have an exception trap missing somewhere

2024-01-10 10:32:50.421 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Koston for powerwall
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powerwall/__init__.py", line 132, in async_setup_entry
    base_info = await _login_and_fetch_base_info(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powerwall/__init__.py", line 191, in _login_and_fetch_base_info
    await power_wall.login(password)
  File "/usr/local/lib/python3.11/site-packages/tesla_powerwall/powerwall.py", line 58, in login
    return await self.login_as(User.CUSTOMER, password, email, force_sm_off)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tesla_powerwall/powerwall.py", line 49, in login_as
    response = await self._api.login(user, email, password, force_sm_off)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tesla_powerwall/api.py", line 172, in login
    return await self.post(
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tesla_powerwall/api.py", line 146, in post
    response = await self._http_session.post(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 601, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 960, in start
    with self._timer:
  File "/usr/local/lib/python3.11/site-packages/aiohttp/helpers.py", line 735, in __exit__
    raise asyncio.TimeoutError from None
TimeoutError

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

testing

  • site 1
  • site 2
  • site 3 - needed to adjust for timeout error
  • site 4
  • site 5

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Also if you like, you should add yourself to codeowners in manifiest.json

I might have to hold off on that until the day I get my own powerwall. It was a big productivity limitation for me on this and made it much harder to understand the HA portion of the code.

No worries. I'll take care of any issues that pop up from the change.

Great first contribution by the way. Most people usually start off working on a device they own 🚀

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.

Thanks @bubonicbob

@bdraco bdraco changed the title Update powerwall component to use latest tesla-powerwall dependency Update powerwall for tesla_powerwall 0.5.0 which is async Jan 10, 2024
@bubonicbob
Copy link
Contributor Author

Thanks @bubonicbob

All you integration owners deserve thanks for maintaining this awesome HA system. 👏

@bdraco
Copy link
Member

bdraco commented Jan 10, 2024

Everything working well on all 5 sites.

Will merge is CI gives us a 👍

@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Jan 10, 2024
@bdraco bdraco merged commit c74bef2 into home-assistant:dev Jan 10, 2024
53 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 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.

2 participants