RobertD502 / home-assistant-petkit

Home Assistant integration for PetKit devices
MIT License
156 stars 24 forks source link

Failed to login (EU region) #26

Closed Theetjuh closed 11 months ago

Theetjuh commented 11 months ago

Hi my account is an EU regions and when I try to login via hass integration, I got this error: ! Unknown error occurred

I did not check asia or china account checkboxes.

Logger: aiohttp.server
Source: deps/lib/python3.11/site-packages/petkitaio/petkit_client.py:403
First occurred: 13:53:27 (1 occurrences)
Last logged: 13:53:27

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/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 85, 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 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 181, 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 297, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 393, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/petkit/config_flow.py", line 118, in async_step_user
    await async_validate_api(self.hass, email, password, asia_account, china_account)
  File "/config/custom_components/petkit/util.py", line 30, in async_validate_api
    devices_query = await client.get_device_roster()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.11/site-packages/petkitaio/petkit_client.py", line 176, in get_device_roster
    device_roster = await self._post(url, header, data)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.11/site-packages/petkitaio/petkit_client.py", line 403, in _post
    async with self._session.post(url, headers=headers, data=data, timeout=self.timeout) as resp:
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 558, in _request
    resp = await req.send(conn)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 670, in send
    await writer.write_headers(status_line, self.headers)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 129, in write_headers
    buf = _serialize_headers(status_line, headers)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_writer.pyx", line 132, in aiohttp._http_writer._serialize_headers
  File "aiohttp/_http_writer.pyx", line 109, in aiohttp._http_writer.to_str
TypeError: Cannot serialize non-str key None
RobertD502 commented 11 months ago

Are you running Home Assistant as a docker container?

Theetjuh commented 11 months ago

Yeah am running it on k3s

RobertD502 commented 11 months ago

This is more than likely due to the TZ environment variable not being set for the container and similar to issue #2. The tzlocal library needs a timezone to convert into a name, but since there isn't one, the timezoneID key in the header is empty resulting in the error that you're seeing.

Theetjuh commented 11 months ago

I have manually exported that setting, within the running container, but that didn’t fix it either.

RobertD502 commented 11 months ago

Can you enter into the container and execute cat /etc/timezone.

Theetjuh commented 11 months ago

No such file or directory

RobertD502 commented 11 months ago

Sorry, that's about as much as I can help since I don't use Kubernetes myself. The core issue is that a timezone doesn't exist within the container that the tzlocal library can convert to a local name.

Theetjuh commented 11 months ago

Setting the ENV worked, but still no /etc/timezone btw, so that isn’t part of the official docker image.

Thanks for the help, weird it didn’t work with the manual setting though.

RobertD502 commented 11 months ago

I'm surprised that /etc/timezone doesn't exist given that Home Assistant has a Linux base so it should.

Glad the environment variable solved it!

Theetjuh commented 11 months ago

Yeah really nice, a big improvement over the other integration, thanks for all the work!

One thing that is shown as unavailable is the battery status on the Fresh Element Mini Pro, known issue?

RobertD502 commented 11 months ago

Check out the documentation all is explained there 😬.

Theetjuh commented 11 months ago

Oops, rtfm ;)

RobertD502 commented 11 months ago

Although I wouldn't use batteries in the mini pro. They never fixed the issue of the batteries potentially causing the feeder to lock up which results in no scheduled feedings dispensing. Problem is you never know when it may happen.

Theetjuh commented 11 months ago

Aahh never knew that was an issue, from what I saw in the app, the schedule is maintained.

RobertD502 commented 11 months ago

Right, until it isn't. Installing batteries doesn't cause it to immediately lock up, but it does eventually sometime down the road.

Although this review mentions that scheduled feedings require WiFi, it is wrong since the feedings are in fact stored on the feeder. However, the unit locks up and you won't know until it is showing as offline:

image

Theetjuh commented 11 months ago

Well, will remove the batteries with the next cleanup session then, thanks for letting me know!