GuyKh / iec-custom-component

HomeAssistant Custom Component for IEC
MIT License
131 stars 5 forks source link

IEC integration stops working after few days - shows unavailable on all metrics and error 400 on token #227

Open skedemintel opened 2 hours ago

skedemintel commented 2 hours ago

System Health details

System Information

version core-2024.11.2
installation_type Home Assistant Supervised
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.1.0-18-arm64
arch aarch64
timezone Asia/Jerusalem
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.1 Stage | running Available Repositories | 1471 Downloaded Repositories | 30
AccuWeather can_reach_server | ok -- | -- remaining_requests | 30
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | June 7, 2025 at 03:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true cloud_ice_servers_enabled | true remote_server | eu-central-1-17.ui.nabu.casa certificate_status | ready instance_id | 02bf973173a24552bf74e82e68f5cc36 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Debian GNU/Linux 12 (bookworm) -- | -- update_channel | stable supervisor_version | supervisor-2024.11.3 agent_version | 1.6.0 docker_version | 25.0.3 disk_total | 61.3 GB disk_used | 43.2 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | qemu supervisor_api | ok version_api | ok installed_addons | Terminal & SSH (9.15.0), ESPHome (2024.10.3), Homeway (1.5.6), Let's Encrypt (5.2.3), Duck DNS (1.18.0), NGINX Home Assistant SSL proxy (3.11.1), File editor (5.8.0), Home Assistant Google Drive Backup (0.112.1), Mosquitto broker (6.4.1), Matter Server (6.6.0), Zigbee2MQTT (1.41.0-1), Zigbee2MQTT (1.41.0-1), motionEye (0.21.0), Browserless Chromium (2.23.0), MQTT Explorer (browser-1.0.3), Docker Wyze Bridge (2.10.3), go2rtc (1.9.7)
Dashboards dashboards | 5 -- | -- resources | 21 views | 24 mode | storage
Recorder oldest_recorder_run | November 8, 2024 at 08:30 -- | -- current_recorder_run | November 17, 2024 at 11:56 estimated_db_size | 569.96 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

IEC costume integ stops working after couple of days integration status: "failed setup, will retry bad request code 400" see picture

restart HA / reload integ does not work no way to do reconfig steps toget new token w/o removing the integ completely

in logs:

280: 2024-11-18 11:38:38.283 DEBUG (MainThread) [iec_api.commons] HTTP POST: https://iec-ext.okta.com/oauth2/default/v1/token Line 290: 2024-11-18 11:38:38.813 DEBUG (MainThread) [iec_api.commons] HTTP Content POST: b'client_id=0oaqf6zr7yEcQZqqt2p7&redirect_uri=com.iecrn%3A%2F&refresh_token=xxxxx-lIGsH05FTFxbTCXoCtw&grant_type=refresh_token&scope=openid+email+profile+offline_access' Line 292: 2024-11-18 11:38:39.027 DEBUG (MainThread) [iec_api.commons] HTTP POST Response <400>: {"error":"invalid_grant","error_description":"The refresh token is invalid or expired."} Line 293: 2024-11-18 11:38:39.027 WARNING (MainThread) [iec_api.commons] Failed call: (Code 400): Bad Request Line

iec_not_working

Reproduction steps

  1. it just stops working after a while, reporting the error mentioned
  2. I supply the IEC log files after startup

...

Debug logs

This error originated from a custom integration.

Logger: custom_components.iec.coordinator
Source: helpers/update_coordinator.py:382
integration: Israel Electric Corporation (IEC) (documentation, issues)
First occurred: 11:38:39 (8 occurrences)
Last logged: 11:44:30

Unexpected error fetching Iec data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/iec/coordinator.py", line 619, in _async_update_data
    await self.api.load_jwt_token(
  File "/usr/local/lib/python3.12/site-packages/iec_api/iec_client.py", line 763, in load_jwt_token
    if await self.check_token():
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/iec_api/iec_client.py", line 796, in check_token
    await self.refresh_token()
  File "/usr/local/lib/python3.12/site-packages/iec_api/iec_client.py", line 804, in refresh_token
    self._token = await login.refresh_token(self._session, self._token)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/iec_api/login.py", line 206, in refresh_token
    response = await commons.send_post_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/iec_api/commons.py", line 183, in send_post_request
    parse_error_response(resp, json_resp)
  File "/usr/local/lib/python3.12/site-packages/iec_api/commons.py", line 103, in parse_error_response
    raise IECError(resp.status, resp.reason)
iec_api.models.exceptions.IECError: (Code 400): Bad Request

This error originated from a custom integration.

Logger: iec_api.commons
Source: custom_components/iec/coordinator.py:619
integration: Israel Electric Corporation (IEC) (documentation, issues)
First occurred: 11:38:39 (8 occurrences)
Last logged: 11:44:30

Failed call: (Code 400): Bad Request

Diagnostics dump

No response

GuyKh commented 2 hours ago

For some reason, looks like the token is expired. Try to remove and add again (generate new token)