cibernox / homeassistant-poolstation

HomeAssistant custom component for integrating the Poolstation platform.
MIT License
9 stars 4 forks source link

Auth error #1

Closed arturonaredo closed 2 years ago

arturonaredo commented 2 years ago

Hi @cibernox !

I'm having the following auth error when trying to connect to poolstation:

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/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 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 94, 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 79, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 206, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *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 260, in async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/poolstation/config_flow.py", line 40, in async_step_user return await self._attempt_login(user_input) File "/config/custom_components/poolstation/config_flow.py", line 85, in _attempt_login account = self._create_account(self, user_input) TypeError: _create_account() takes 2 positional arguments but 3 were given

This seems to be due an error on this line

https://github.com/cibernox/homeassistant-poolstation/blob/baa0f7cd3b45a31f1de4fc5a672fcaea67c8298b/custom_components/poolstation/config_flow.py#L76

And a solution is removing that method create_account:

  ```

Author: Arturo Naredo Ortega arturono@.com Date: Sun May 8 15:10:42 2022 +0200

      Fix authentication error

  diff --git a/custom_components/poolstation/config_flow.py b/custom_components/poolstation/config_flow.py
  index fe217bd..4bf345f 100644
  --- a/custom_components/poolstation/config_flow.py
  +++ b/custom_components/poolstation/config_flow.py
  @@ -5,7 +5,7 @@ from asyncio import TimeoutError
   import logging
   from typing import Any

  -from aiohttp import ClientResponseError, DummyCookieJar
  +from aiohttp import ClientResponseError, CookieJar
   from pypoolstation import Account, AuthenticationException
   import voluptuous as vol

  @@ -74,15 +74,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
               return self.async_abort(reason="reauth_successful")

       def _create_account(self, user_input):
  -        session = async_create_clientsession(self.hass, cookie_jar=DummyCookieJar())
  -        return Account(
  -            session, username=user_input[CONF_EMAIL], password=user_input[CONF_PASSWORD]
  -        )
  +        session = async_create_clientsession(self.hass, cookie_jar=CookieJar(unsafe=True))
  +        return Account(session, username=user_input[CONF_EMAIL], password=user_input[CONF_PASSWORD])

       async def _attempt_login(self, user_input):
           errors: dict[str, str]
           errors = {}
  -        account = self._create_account(self, user_input)
  +        session = async_create_clientsession(self.hass, cookie_jar=CookieJar(unsafe=True))
  +        account = Account(session, username=user_input[CONF_EMAIL], password=user_input[CONF_PASSWORD])


I was about to do a PR to show the changes but, of course this is no the ideal solution, but at least this works and solves the auth problem.

<img width="426" alt="Captura de Pantalla 2022-05-08 a las 15 02 01" src="https://user-images.githubusercontent.com/714159/167297941-9c050ee2-b167-40e2-a5a2-53fd8d08f40b.png">
cibernox commented 2 years ago

@arturonaredo if you go to HACS and install the latest version of this integration I believe it all should be working properly. I implemented a few improvements to handle session expiration:

Give it a go.

arturonaredo commented 2 years ago

Hi @cibernox ,

this issue is fixed! I have now the parsing one posted here https://github.com/cibernox/PyPoolstation/issues/2 but I'm closing this one!

Thanks!