yaleman / pygoodwe

Python library for querying the GoodWe Solar SEMS API
https://yaleman.github.io/pygoodwe/
MIT License
27 stars 9 forks source link

Add error message for wrong email/password #246

Closed nelsbrock closed 8 months ago

nelsbrock commented 8 months ago

When the log in fails because of an invalid email or password, the API returns a HTTP 200 response with the following JSON content (tested with the example config):

{
  "hasError": false,
  "code": 100005,
  "msg": "Email or password error.",
  "data": null,
  "components": {
    "para": null,
    "langVer": 179,
    "timeSpan": 0,
    "api": "http://semsportal.com:85/api/v2/Common/CrossLogin",
    "msgSocketAdr": "https://eu-xxzx.semsportal.com"
  }
}

Currently, this error is ignored by pygoodwe.

This pull request adds a check for this response (to be more specific, it checks for a non-zero code value, since even hasError is false in this error response ...) and logs an appropriate error message:

ERROR:root:Failed to log in: Email or password error.
yaleman commented 8 months ago

I tweaked it slightly, added tests and released it as a new version on pypi.