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

Support disconnected Powerwall configuration #67325

Conversation

jumbledbytes
Copy link
Contributor

Proposed change

This is a small change that fixes the is_on function in the binary sensor for the powerwall component to handle the case when the Powerwall is disconnected or unavailable. Currently if the powerwall is disconnected from a PV system with a Tesla Gateway configured the Tesla integration will fail to load data due to:



[31m2022-02-27 02:57:42 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up powerwall platform for binary_sensor
--
AttributeError: 'NoneType' object has no attribute 'is_sending_to'�
    return self.data.meters.get_meter(MeterType.BATTERY).is_sending_to()
File "/usr/src/homeassistant/homeassistant/components/powerwall/binary_sensor.py", line 122, in is_on
     if (is_on := self.is_on) is None:
File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 209, in state
    if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in _stringify_state
    state = self._stringify_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 572, in _async_write_ha_state
    self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in async_write_ha_state
    self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 783, in add_to_platform_finish
    await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 614, in _async_add_entity
    await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    Traceback (most recent call last):

This error occurs because when the Powerwall is not available self.data.meters.get_meter(MeterType.BATTERY) returns None. This prevents the sensors for a functional Tesla Gateway from reporting data to Home Assistant.

Type of change

This is a small bug fix that makes the powerwall integration work in configurations where only the gateway is online and available.

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

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

I have tested this change locally and it fixes the issue for me. I'm not sure how or where to add tests for this edge case, but can add them with a pointer on where the appropriate tests are for this.

  • 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
  • The code has been formatted using Black (black --fast 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

This is my first contribution to this project.

@homeassistant
Copy link
Contributor

Hi @jumbledbytes,

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!

@probot-home-assistant
Copy link

Hey there @bdraco, @jrester, 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!
(message by CodeOwnersMention)

@jumbledbytes
Copy link
Contributor Author

Hey there @bdraco, @jrester, 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!
(message by CodeOwnersMention)

Hi @bdraco @jrester this is my first contribution to this project to add a fix I applied locally to get the Tesla integration to work properly for me (my Powerwall is backordered, but the Tesla Backup Gateway is installed and functioning properly). This change allows me to monitor the PV system inputs into the Gateway while I wait for the Powerwall.

Please let me know if there is anything I should do from a testing or convention perspective that is missing from this small change.

@jumbledbytes jumbledbytes marked this pull request as ready for review February 27, 2022 04:25
@jumbledbytes jumbledbytes requested a review from bdraco as a code owner February 27, 2022 04:25
@jrester
Copy link
Contributor

jrester commented Feb 27, 2022

@jumbledbytes @bdraco Might the available property be more suited for this case? Because returning False does only indicate that the battery is not charging but you cannot distinguish between not charging and no battery available in the installation.

Comment on lines 122 to 124
battery = self.data.meters.get_meter(MeterType.BATTERY)
if battery == None:
return False
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
battery = self.data.meters.get_meter(MeterType.BATTERY)
if battery == None:
return False
if (battery := self.data.meters.get_meter(MeterType.BATTERY)) is None:
return False

@bdraco
Copy link
Member

bdraco commented Feb 27, 2022

@jumbledbytes @bdraco Might the available property be more suited for this case? Because returning False does only indicate that the battery is not charging but you cannot distinguish between not charging and no battery available in the installation.

I agree. Setting available to False makes more sense in this case.

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 👍

#67325 (comment)

Co-authored-by: J. Nick Koston <[email protected]>
@jumbledbytes jumbledbytes changed the title Support disconnected Powerwall Configuration Support disconnected Powerwall configuration Feb 28, 2022
@bdraco bdraco merged commit 508ed25 into home-assistant:dev Feb 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2022
@bdraco bdraco added this to the 2022.3.0 milestone Mar 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants