From 25e09eccfc6ea9458c03aaba0d868beddb907faa Mon Sep 17 00:00:00 2001 From: Snuffy2 Date: Thu, 5 Sep 2024 17:43:06 -0400 Subject: [PATCH] Don't show error if OpenVPN isn't used --- custom_components/opnsense/pyopnsense/__init__.py | 6 ++++++ custom_components/opnsense/sensor.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom_components/opnsense/pyopnsense/__init__.py b/custom_components/opnsense/pyopnsense/__init__.py index 6c4d1fd..4e8bbab 100644 --- a/custom_components/opnsense/pyopnsense/__init__.py +++ b/custom_components/opnsense/pyopnsense/__init__.py @@ -1205,6 +1205,12 @@ def _get_telemetry_filesystems(self) -> dict: def _get_telemetry_openvpn(self) -> dict: openvpn_info: Mapping[str, Any] = self._post("/api/openvpn/export/providers") _LOGGER.debug(f"[get_telemetry_openvpn] openvpn_info: {openvpn_info}") + if ( + openvpn_info is not None + and isinstance(openvpn_info, list) + and len(openvpn_info) == 0 + ): + return {} if ( openvpn_info is None or not isinstance(openvpn_info, Mapping) diff --git a/custom_components/opnsense/sensor.py b/custom_components/opnsense/sensor.py index 9bcd522..e8d1266 100644 --- a/custom_components/opnsense/sensor.py +++ b/custom_components/opnsense/sensor.py @@ -501,7 +501,7 @@ def native_value(self): property = self._opnsense_get_interface_property_name() try: return interface[property] - except KeyError: + except (KeyError, TypeError): return STATE_UNKNOWN