muppet3000 / homeassistant-growatt_server_api

Home Assistant Integration for Growatt - Upstream repo for the growatt_server integration that is part of the Core Home Assistant repository
MIT License
54 stars 7 forks source link

BUG - Error while setting up growatt_server_api platform for sensor after last core update #28

Closed Maxpako closed 1 year ago

Maxpako commented 1 year ago

Describe the bug After Home Assistant update, the integration no longer works, showing following error in logs:

Logger: homeassistant.components.sensor
Source: custom_components/growatt_server_api/sensor.py:51
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 16:47:38 (2 occurrences)
Last logged: 17:42:17

Error while setting up growatt_server_api platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/growatt_server_api/sensor.py", line 88, in async_setup_entry
    devices, plant_id = await hass.async_add_executor_job(get_device_list, api, config)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/growatt_server_api/sensor.py", line 51, in get_device_list
    user_id = login_response["user"]["id"]
KeyError: 'user'

To Reproduce Update Home Assistant to the last version (2023.3.6)

Growatt Device Type Device(s): ShineWifi-X (Dataloger), MIN 3600 TL-XH (Inverter), SDM (Meter) Logged with the same user as with the integration.

Home Assistant information

Additional context Trying to add again the integration fails with:

Logger: aiohttp.server
Source: custom_components/growatt_server_api/config_flow.py:63
Integration: Servidor Growatt ([documentation](https://github.com/muppet3000/homeassistant-growatt_server_api), [issues](https://github.com/muppet3000/homeassistant-growatt_server_api/issues))
First occurred: 17:47:32 (1 occurrences)
Last logged: 17:47:32

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 67, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 234, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/growatt_server_api/config_flow.py", line 63, in async_step_user
    self.user_id = login_response["user"]["id"]
KeyError: 'user'

Home Assistant 2023.3.6 Supervisor 2023.03.2 Operating System 9.5 Frontend 20230309.1 - latest

Saentist commented 1 year ago

You have API ban

muppet3000 commented 1 year ago

Hi @Maxpako it's likely that your account has been blocked temporarily as discussed over on #15.

Do the same credentials still work on the Android App or are they marked as blocked there as well?

If you look in the FAQs there's a how-to guide for setting up a spare set of credentials via the Growatt website, I have a handful that I cycle between when my account gets blocked.

Maxpako commented 1 year ago

Yup, account locked.

Very high coincidence that happened at the same time updating HA.

Thanks @saentist and @muppet3000

muppet3000 commented 1 year ago

Yup, account locked.

Very high coincidence that happened at the same time updating HA.

Thanks @saentist and @muppet3000

Not a coincidence at all actually, the way the integration works is by logging on once when you boot up and then hanging on to the authentication token and reusing it until it expires (which is actually a stupidly long time), therefore when you reboot it tries to re-authenticate, if your account has been blocked, it can't, so it bombs out.

If you've been following #15 at all you'll see that I'm starting to steer people towards grott. I'm VERY close to launching a new integration which works with Grott, just working out the final kinks!

Saentist commented 1 year ago

@muppet3000 Is it possible to make this bug fixed by complicated solution. ;) Not sure where and how but, is it possible integration to make log when was last grep time, and not to update update until next possible time frame. Currently if update restart HA next update is in too short time and BAN is guarantied.