torbennehmer / hacs-e3dc

Homeassistant E3DC Integration
GNU Affero General Public License v3.0
53 stars 8 forks source link

RSCPKeyError #140

Open drizzd opened 2 months ago

drizzd commented 2 months ago

System Health details

System Information

version core-2023.7.3
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.11.4
os_name Linux
os_version 6.1.21-v7+
arch armv7l
timezone Europe/Berlin
config_dir /config
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 3 -- | -- resources | 2 views | 6 mode | storage
Recorder oldest_recorder_run | 11. April 2024 um 16:33 -- | -- current_recorder_run | 22. April 2024 um 22:38 estimated_db_size | 238.18 MiB database_engine | sqlite database_version | 3.41.2

Checklist

Describe the issue

I started using hacs-e3dc in November 2023. I updated E3DC to latest firmware 2 weeks ago. Shortly after I updated hacs-e3dc from 3.4.2 to 3.6.2 for #118. Since then RSCPKeyError was raised twice: In e3dc.poll on April 18 and in get_manual_charge->sendRequest on April 22. In e3dc_proxy.py we raise ConfigEntryAuthFailed on RSCPKeyError. This causes Home Assistant to stop the integration until the user manually re-authenticates.

The issue does not appear to be related to authentication. I have not changed my passwords and I re-authenticate successfully with the same credentials. Removing the RSCPKeyError clause fixes the issue for me.

@@ -40,11 +41,6 @@ def e3dc_call(func):
         except AuthenticationError as ex:
             _LOGGER.exception("Failed to authenticate with E3DC: %s", ex)
             raise ConfigEntryAuthFailed("Failed to authenticate with E3DC") from ex
-        except RSCPKeyError as ex:
-            _LOGGER.exception("Encryption error with E3DC, key invalid: %s", ex)
-            raise ConfigEntryAuthFailed(
-                "Encryption Error with E3DC, key invalid"
-            ) from ex
         except (HomeAssistantError, ConfigEntryAuthFailed):
             raise
         except Exception as ex:

Reproduction steps

To reproduce I made the following change.

@@ -119,6 +120,9 @@ class E3DCProxy:
     def get_manual_charge(self) -> dict[str, Any]:
         """Poll manual charging state."""
         try:
+            if random.random() > 0.99:
+                self.e3dc.disconnect()
+                raise RSCPKeyError
             data = self.e3dc.sendRequest(
                 (RscpTag.EMS_REQ_GET_MANUAL_CHARGE, RscpType.NoneType, None), keepAlive=True
             )

Debug logs

It takes several days until the issue triggers. Please let me know if more information is required.

Diagnostics dump

No response