th3r3alandr3 / rehau-nea-smart-2.0-ha

"Rehua Nea Smart 2.0 Home Assistant Integration
MIT License
0 stars 2 forks source link

Title: KeyError: 'defaultInstall' during REHAU Nea Smart 2.0 integration setup #68

Open giacomoalonzi opened 22 hours ago

giacomoalonzi commented 22 hours ago

System Health details

System Information

version core-2024.9.0
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.20+rpt-rpi-v8
arch aarch64
timezone Europe/Rome
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 4974 Installed Version | 2.0.1 Stage | running Available Repositories | 1494 Downloaded Repositories | 19
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 4 -- | -- resources | 9 views | 21 mode | storage
Recorder oldest_recorder_run | 25 settembre 2024 alle ore 12:39 -- | -- current_recorder_run | 1 ottobre 2024 alle ore 19:19 estimated_db_size | 213.12 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

When setting up the REHAU Nea Smart 2.0 integration in Home Assistant, a KeyError occurs due to the absence of the "defaultInstall" key in the user object. This prevents the integration from completing its configuration and functioning properly.

Reproduction steps

1.  Add the REHAU Nea Smart 2.0 integration in Home Assistant.
2.  Enter the login credentials.
3.  The configuration fails, and the error is raised.

Debug logs

2024-10-01 19:23:00.456 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry REHAU Nea Smart 2.0 API for rehau_nea_smart_2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/rehau_nea_smart_2/__init__.py", line 27, in async_setup_entry
    await controller.connect()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/Controller.py", line 33, in connect
    await self.mqtt_client.auth_user()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 310, in auth_user
    await self.set_user(user)
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 388, in set_user
    await self.set_installations(user["installs"])
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 333, in set_installations
    self.set_install_id()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 147, in set_install_id
    default_install = self.user["defaultInstall"]
                      ~~~~~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'defaultInstall'

Diagnostics dump

home-assistant_rehau_nea_smart_2_2024-10-01T17-56-27.752Z.log

giacomoalonzi commented 21 hours ago

I've update the file MqttClient.py at line 145 in this:

def set_install_id(self):
        """Set the installation ID based on the user's default installation."""
        default_install = self.user.get("defaultInstall")
        if not default_install:
            raise ValueError("The user does not have a default installation configured.")

        installs = self.user.get("installs")
        if not installs:
            raise ValueError("No installations found for the user.")

        for install in installs:
            if install["unique"] == default_install:
                self.current_installation = {
                    "id": install["_id"],
                    "unique": install["unique"],
                    "hash": install.get("hash"),  # Safe access to 'hash'
                }
                return

        raise ValueError("The default installation was not found among the user's installations.")

Now the error is changed in this:

Error setting up entry REHAU Nea Smart 2.0 API for rehau_nea_smart_2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/rehau_nea_smart_2/__init__.py", line 27, in async_setup_entry
    await controller.connect()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/Controller.py", line 33, in connect
    await self.mqtt_client.auth_user()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 318, in auth_user
    await self.set_user(user)
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 395, in set_user
    await self.set_installations(user["installs"])
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 341, in set_installations
    self.set_install_id()
  File "/config/custom_components/rehau_nea_smart_2/rehau_mqtt_client/MqttClient.py", line 149, in set_install_id
    raise ValueError("The user does not have a default installation configured.")
ValueError: The user does not have a default installation configured.

hope this help to figuring out, 'cause I do not have any idea about what defaultInstallation is or if I have to do something on my side.

th3r3alandr3 commented 6 hours ago

The integration is currently unable to handle cases where the Rehau API doesn't provide a defaultInstall property in the user data.

As a temporary workaround, you can set a default installation in your Rehau app:

  1. Open the Rehau app.
  2. Go to the settings for one of your installations.
  3. Check the box that says "Always use this installation on startup".

This should allow the integration to connect successfully.

I'm aware of this issue and will consider it for a future update.