nickknissen / hass-monta

Monta Home Assistant custom component
MIT License
21 stars 2 forks source link

Error when using the UI to add the Monta Int #47

Closed markjsmith closed 6 months ago

markjsmith commented 6 months ago

System Health details

System Information

version core-2023.12.3
installation_type Home Assistant Supervised
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 5.10.0-26-amd64
arch x86_64
timezone Europe/London
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4945 Installed Version | 1.33.0 Stage | running Available Repositories | 1440 Downloaded Repositories | 160 HACS Data | ok
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | 17 March 2024 at 00:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | true google_enabled | false remote_server | eu-central-1-10.ui.nabu.casa certificate_status | ready instance_id | a6e9fbfc7c1a46e08ff29ba4f1d1a0f4 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Debian GNU/Linux 11 (bullseye) -- | -- update_channel | beta supervisor_version | supervisor-2023.12.0 agent_version | 1.4.1 docker_version | 24.0.7 disk_total | 232.2 GB disk_used | 93.7 GB healthy | true supported | ok supervisor_api | ok version_api | ok installed_addons | Check Home Assistant configuration (3.11.0), Mosquitto broker (6.4.0), Z-Wave JS (0.4.3), AirCast (4.0.1), AppDaemon (0.16.0), MariaDB (2.6.1), phpMyAdmin (0.9.0), FTP (4.7.3), Home Assistant Google Drive Backup (0.112.1), Duck DNS (1.15.0), eWeLink Smart Home (1.4.3), Vaultwarden (Bitwarden) (0.20.1), Node-RED (16.0.2), Traccar (0.23.1), Terminal & SSH (9.8.1), Samba share (12.2.0), PSA Car Controller (v3.2.0), Spotify Connect (0.12.6), Squeezelite (1.35), File editor (5.7.0), Nginx Proxy Manager (0.12.3), Inadyn (2.12.0), Firefly iii (6.1.0), Firefly iii Data Importer (1.4.0), Portainer (2.19.4-3), Photoprism (preview-ubuntu-2023-04-29-4), Matter Server (5.0.1), Filebrowser (2.23.0_8), Mealie (Omni): (v1.0.0-RC1.1), Seafile (testing), ESPHome (2023.12.5), room-assistant (2.20.0), Piper (1.4.0), Whisper (1.0.0), ESPresense Companion (0.6.0), OpenThread Border Router (2.4.1), ecowitt2mqtt (2023.11.2), Zigbee2MQTT (1.34.0-1), DeepStack Server (CPU) (2022.01.1), DeepStack Client (Trainer) (2.2.0-1), SteVe (2.0.15), evcc (0.123.1), emoncms (alpine3.16.3), TeslaMate (0.21.1), Postgres (15.5-3), Iotics (0.11.45), deCONZ (6.22.0), Music Assistant BETA (2.0.0b78)
Dashboards dashboards | 12 -- | -- resources | 92 views | 52 mode | storage
Recorder oldest_recorder_run | 16 December 2023 at 21:35 -- | -- current_recorder_run | 26 December 2023 at 14:02 estimated_db_size | 1955.53 MiB database_engine | sqlite database_version | 3.41.2
Solcast PV Forecast can_reach_server | ok -- | -- used_requests | 12 rooftop_site_count | 2
Sonoff version | 3.5.2 (2ad1cd7) -- | -- cloud_online | 9 / 10 local_online | 9 / 9
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

I have tried adding the client secret and id, but keep getting "an unknown error" Monta is connected to a Rolec Dura - dual outlet charger, in case this is relevant.

Reproduction steps

  1. installed Monta custom component
  2. Rebooted Hassio
  3. selected add integration and filled in details from Monta

"Unknown error occured"

Debug logs

This error originated from a custom integration.

Logger: custom_components.monta
Source: custom_components/monta/config_flow.py:33
Integration: Monta (documentation, issues)
First occurred: 14:04:50 (7 occurrences)
Last logged: 14:16:31

Something really wrong happened!
Traceback (most recent call last):
  File "/config/custom_components/monta/api.py", line 243, in _api_wrapper
    raise MontaApiClientAuthenticationError(
custom_components.monta.api.MontaApiClientAuthenticationError: Invalid credentials

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

Traceback (most recent call last):
  File "/config/custom_components/monta/config_flow.py", line 33, in async_step_user
    response = await self._test_credentials(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/config_flow.py", line 82, in _test_credentials
    return await client.async_request_token()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/api.py", line 84, in async_request_token
    response_json = await self._api_wrapper(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/api.py", line 266, in _api_wrapper
    raise MontaApiClientError("Something really wrong happened!") from exception
custom_components.monta.api.MontaApiClientError: Something really wrong happened!

Diagnostics dump

not available as not installed

nickknissen commented 6 months ago

Looks like Monta is throwing an authentication error. Either 401 or 403.

Are you signed up to beta in the app?

Could you also add the following to your home assistant config?

logger:
  default: info
  logs:
    custom_components.monta: debug

The restart home assistant and try adding the integration again.

This will enable debug logging for the integration. The logs should be prefixed with custom_components.monta

markjsmith commented 6 months ago

Hi Nick, Yes, i have the beta enabled in the app. I tried disabling and the applications (and so api codes) vanish. Once re-enabling i got the following in my log

2023-12-29 17:22:07.383 DEBUG (MainThread) [custom_components.monta.api] [auth/token] Response header: <CIMultiDictProxy('Date': 'Fri, 29 Dec 2023 17:22:07 GMT', 'Content-Type': 'application/json', 'Content-Length': '181', 'Connection': 'keep-alive', 'request-id': '46abde38-1edc-4ffa-8f5a-aa12174aaea2', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains')>
2023-12-29 17:22:07.383 DEBUG (MainThread) [custom_components.monta.api] [auth/token] Response status: 401
2023-12-29 17:22:07.383 ERROR (MainThread) [custom_components.monta] Something really wrong happened!
Traceback (most recent call last):
  File "/config/custom_components/monta/api.py", line 243, in _api_wrapper
    raise MontaApiClientAuthenticationError(
custom_components.monta.api.MontaApiClientAuthenticationError: Invalid credentials

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

Traceback (most recent call last):
  File "/config/custom_components/monta/config_flow.py", line 33, in async_step_user
    response = await self._test_credentials(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/config_flow.py", line 82, in _test_credentials
    return await client.async_request_token()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/api.py", line 84, in async_request_token
    response_json = await self._api_wrapper(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monta/api.py", line 266, in _api_wrapper
    raise MontaApiClientError("Something really wrong happened!") from exception
custom_components.monta.api.MontaApiClientError: Something really wrong happened!

I created a new application and made sure there were no spaces in the name to be sure and it worked!

Maybe something got confused on the old applications or it did not like the spaces?

nickknissen commented 6 months ago

Looks like a monta error. I will look into improving the error message, when adding credential fails.

birkirb commented 6 months ago

The error is the same as mine, but not clear if the circumstances are the same and thus not sure if it's a duplicate.

nickknissen commented 6 months ago

I have improved the error message on initial setup in 2f1dd31