Skip to content

GrowattServer: Add "Account is locked" message #142874

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

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

thimo-seitz
Copy link
Contributor

Breaking change

Proposed change

If the account is temporarily locked, display an aproperiate message.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue: Growatt: Login fail #121703
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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.

To help with the load of incoming pull requests:

@thimo-seitz thimo-seitz marked this pull request as ready for review April 14, 2025 12:20
Comment on lines 66 to 73
if login_response["msg"] == LOGIN_INVALID_AUTH_CODE:
# Invalid auth code
return self._async_show_user_form({"base": "invalid_auth"})
if login_response["msg"] == LOGIN_LOCKED_CODE:
# Account locked
return self._async_show_user_form({"base": "account_locked"})
# Unknown error
return self._async_show_user_form({"base": "unknown_error"})
Copy link
Member

Choose a reason for hiding this comment

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

You can do a dict lookup

{
    LOGIN_INVALID_AUTH_CODE: "invalid_auth",
    LOGIN_LOCKED_CODE: "account_locked"
}.get(login_response["msg"], "unknown_error")

To make this more neat

if login_response["msg"] == LOGIN_INVALID_AUTH_CODE:
raise ConfigEntryError("Username, Password or URL may be incorrect!")
if login_response["msg"] == LOGIN_LOCKED_CODE:
raise ConfigEntryError(login_response["error"])
Copy link
Member

Choose a reason for hiding this comment

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

why can it be locked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The api has a request limit which you can reach, if you use the same account for the HA-Integration and the App on the phone. A screenshot of that is inside the linkes issue #121703

raise ConfigEntryError("Username, Password or URL may be incorrect!")
if login_response["msg"] == LOGIN_LOCKED_CODE:
raise ConfigEntryError(login_response["error"])
raise ConfigEntryError(
Copy link
Member

Choose a reason for hiding this comment

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

when would this happen? This means someone has to restart whole of HA in order to make it work again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This are the responses of the growatt cloud. There are a unknown number of causes, why a login isn't valid anymore. The implementors of the used api https://github.com/indykoning/PyPi_GrowattServer doesn't mention details there. When the user changes their password in the growatt cloud, they have to update the integratrion. The locked state will be unlocked after 24 hours, if the user hit the request limit. IMHO a restart is not necassary. Maybe a reconfiguration of the integration.

Copy link
Member

@joostlek joostlek Apr 15, 2025

Choose a reason for hiding this comment

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

Is that 24 hour limit a hard limit? Or will it be reset to 24h again when I do more requests?

Should we ask the user to reauthenticate in this scenario? Or will it recover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really know, but it seems not to reset if you do more request within these 24 hours. The PyPi_GrowattServer is a reverse engineering work, so there's no offical doc of the api. The response in that case of a "lock" contains a lockDuration property which states 24 in the beginning.

{   'error': 'Current account has been locked for 24 hours',
    'lockDuration': '24',
    'msg': '507',
    'success': False}

But these 24 doesn't change over time.

At the Growatt webpage you can add "visitor" accounts. It seems to be a good idea to use a seperate account for the integration, so the (unkown) limit shouldn't be hit.

"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"account_locked": "Account is locked for 24 hours. Please try again later.",
"unknown_error": "Unknown error occured."
Copy link
Member

Choose a reason for hiding this comment

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

You can use a common translation key here

Copy link
Member

Choose a reason for hiding this comment

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

This would be test_sensor.py instead.

Copy link
Member

Choose a reason for hiding this comment

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

Why is this called test_sensor_init? This should be in test_init.py (and I think the code in sensor/__init__.py should be moved to __init__.py in general, but that is outside of the scope of this PR)

LOGIN_INVALID_AUTH_CODE,
LOGIN_LOCKED_CODE,
)
from homeassistant.components.growatt_server.sensor import get_device_list
Copy link
Member

Choose a reason for hiding this comment

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

We should not touch internals directly, we should rather patch the library and have HA set up the integration

@home-assistant home-assistant bot marked this pull request as draft April 14, 2025 15:23
@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants