Pyhass / Hive-Custom-Component

A custom version of the home assistant hive component
MIT License
33 stars 17 forks source link

HiveApiError #160

Open solderchicken opened 6 days ago

solderchicken commented 6 days ago

Hi there

I have has custom component on HA on a RPi4 working great for a few years now.

I trigger Hive GU10 bulbs using Shelly i3/i4 and wall switches and HA automations.

I noticed when they stopped working that Hive Integration had 'Failed to Setup'.

After much trial and error I removed/reinstalled/deleted old trusted devices etc and not the latest Hive Custom Component sets up OK.

Devices all add to HA OK and work for about a minute, then they stop working.

The issue seems to be the

raise HiveApiError

apyhiveapi.helper.hive_exceptions.HiveApiError

at the botoom of the LOG below.

Can anyone help please?

Thank you

LOG:

Logger: homeassistant.core Source: core.py:2781 First occurred: September 29, 2024 at 23:40:58 (72 occurrences) Last logged: 00:17:58

Error executing service: <ServiceCall light.turn_on (c:01J9013GF20R93TG1RGYCR8G8A): entity_id=['light.cellar_lights'], params=transition=30.0, color_temp=370, color_temp_kelvin=2702> Error executing service: <ServiceCall light.turn_on (c:01J9014DRK018ZWVEJADDV4X62): entity_id=['light.cellar_lights'], params=transition=30.0, color_temp=370, color_temp_kelvin=2702> Error executing service: <ServiceCall light.turn_on (c:01J9015B24BWP4ZYK8CB6KP86K): entity_id=['light.cellar_lights'], params=transition=30.0, color_temp=370, color_temp_kelvin=2702> Error executing service: <ServiceCall light.turn_on (c:01J90168BNS5CCE35THJCN0XCG): entity_id=['light.cellar_lights'], params=transition=30.0, color_temp=370, color_temp_kelvin=2702> Error executing service: <ServiceCall light.turn_on (c:01J90175N5QKMEFQPPS9SM7GPF): entity_id=['light.cellar_lights'], params=transition=30.0, color_temp=370, color_temp_kelvin=2702> Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 2781, in _run_service_call_catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 626, in async_handle_light_on_service await light.async_turn_on(filter_turn_on_params(light, params)) File "/usr/src/homeassistant/homeassistant/components/group/light.py", line 179, in async_turn_on await self.hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call raise result from None File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call return await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 626, in async_handle_light_on_service await light.async_turn_on(filter_turn_on_params(light, params)) File "/usr/src/homeassistant/homeassistant/components/hive/init.py", line 138, in wrapper await func(self, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/components/hive/light.py", line 82, in async_turn_on await self.hive.light.turnOn( File "/usr/local/lib/python3.12/site-packages/apyhiveapi/light.py", line 426, in turnOn return await self.setColorTemp(device, color_temp) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/apyhiveapi/light.py", line 272, in setColorTemp resp = await self.session.api.setState( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_async_api.py", line 288, in setState resp = await self.request("post", url, data=jsc) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_async_api.py", line 92, in request raise HiveApiError apyhiveapi.helper.hive_exceptions.HiveApiError

holdestmade commented 3 days ago

Same issue here, except I got a 2FA code on mobile and HA wanted to reconfigure Hive. I added the 2FA code and got the following in logs, and I get this every start up or 'reconfigure'

2024-10-03 09:27:24.496 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry xxxx.xxxx@xxxx.com for hive
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_auth_async.py", line 548, in refresh_token
    result = await self.loop.run_in_executor(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botocore/client.py", line 565, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botocore/client.py", line 1021, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Invalid Refresh Token.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hive/__init__.py", line 89, in async_setup_entry
    devices = await hive.session.startSession(hive_config)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 502, in startSession
    await self.getDevices("No_ID")
  File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 425, in getDevices
    await self.hiveRefreshTokens()
  File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 304, in hiveRefreshTokens
    result = await self.auth.refresh_token(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_auth_async.py", line 562, in refresh_token
    raise HiveInvalid2FACode from err
apyhiveapi.helper.hive_exceptions.HiveInvalid2FACode
Ni3kjm commented 2 days ago

similar issue here

Log details (ERROR) Logger: homeassistant.config_entries Source: config_entries.py:594 First occurred: 15:31:06 (3 occurrences) Last logged: 15:38:38

Error setting up entry **@gmail.com for hive Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_auth_async.py", line 548, in refresh_token result = await self.loop.run_in_executor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call return self._make_api_call(operation_name, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Refresh Token has expired

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/hive/init.py", line 89, in async_setup_entry devices = await hive.session.startSession(hive_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 502, in startSession await self.getDevices("No_ID") File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 425, in getDevices await self.hiveRefreshTokens() File "/usr/local/lib/python3.12/site-packages/apyhiveapi/session.py", line 304, in hiveRefreshTokens result = await self.auth.refresh_token( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/apyhiveapi/api/hive_auth_async.py", line 562, in refresh_token raise HiveInvalid2FACode from err apyhiveapi.helper.hive_exceptions.HiveInvalid2FACode