diff --git a/.gitignore b/.gitignore index f84af1a..4a71d54 100644 --- a/.gitignore +++ b/.gitignore @@ -62,5 +62,5 @@ log.txt venv/ -test_consts.py +local_consts.py edgeos.key diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3fec6..dc9c2e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v1.1.4 +- Prevent the component to get installed or run with EdgeOS Firmware v1 + ## v1.1.3 - Fixed monitored_devices appear as disconnected [\#32](https://github.com/elad-bar/ha-edgeos/pull/32) by [@shlomki](https://github.com/shlomki) diff --git a/README.md b/README.md index 3de5d3b..a969748 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Provides an integration between EdgeOS (Ubiquiti) routers to Home Assistant. Look for "Integration with EdgeOS (Ubiquiti)" and install #### Requirements -* EdgeRouter with version 1.10 at least +* EdgeRouter with at least firmware version 2.0 * EdgeRouter User with 'Operator' level access or higher * Traffic Analysis set to 'Enabled' (both `dpi` and `export` enabled under `system/traffic-analysis`) @@ -35,7 +35,7 @@ General authentication error (when failed to get valid response from device) | Could not retrieve device data from EdgeOS Router | Export (traffic-analysis) configuration is disabled, please enable | Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable | -Incompatible version (Required at least v1.10) +Unsupported firmware version| ###### Encryption key got corrupted If a persistent notification popped up with the following message: diff --git a/__main__.py b/__main__.py index d7449d9..216e692 100644 --- a/__main__.py +++ b/__main__.py @@ -7,7 +7,7 @@ from custom_components.edgeos.managers.version_check import VersionCheck from custom_components.edgeos.models.config_data import ConfigData from homeassistant.core import HomeAssistant -from test_consts import * +from local_consts import * logging.basicConfig(filename="log.txt", filemode="a", level="DEBUG") diff --git a/custom_components/edgeos/helpers/const.py b/custom_components/edgeos/helpers/const.py index e6a2355..74fc056 100644 --- a/custom_components/edgeos/helpers/const.py +++ b/custom_components/edgeos/helpers/const.py @@ -252,6 +252,7 @@ SERVICE_LOG_EVENTS_SCHEMA = vol.Schema({vol.Required(ATTR_ENABLED): cv.boolean}) HTTP_ERRORS = { + 400: "incompatible_version", 404: "not_found", 403: "invalid_credentials", 500: "incompatible_version", diff --git a/custom_components/edgeos/managers/config_flow_manager.py b/custom_components/edgeos/managers/config_flow_manager.py index 77d1aad..def61af 100644 --- a/custom_components/edgeos/managers/config_flow_manager.py +++ b/custom_components/edgeos/managers/config_flow_manager.py @@ -420,6 +420,19 @@ async def _valid_login(self): ) errors = {"base": "invalid_export_configuration"} + system_info_data = await api.get_general_data(SYS_INFO_KEY) + + if system_info_data is not None: + firmware_version = system_info_data.get("fw-latest", {}) + version = firmware_version.get("version") + + if version[:2] == "v1": + _LOGGER.error( + f"Unsupported firmware version ({version})" + ) + + errors = {"base": "incompatible_version"} + else: _LOGGER.warning(f"Failed to login {name}") diff --git a/custom_components/edgeos/managers/data_manager.py b/custom_components/edgeos/managers/data_manager.py index 7c9f7c7..20a9605 100644 --- a/custom_components/edgeos/managers/data_manager.py +++ b/custom_components/edgeos/managers/data_manager.py @@ -119,8 +119,17 @@ async def _initialize(self, post_login_action=None): cookies = self._api.cookies_data session_id = self._api.session_id - _LOGGER.debug(f"Initializing WS using session: {session_id}") - await self._ws.initialize(cookies, session_id) + if self.version[:2] == "v1": + _LOGGER.error( + f"Unsupported firmware version ({self.version})" + ) + + await self.terminate() + + else: + _LOGGER.debug(f"Initializing WS using session: {session_id}") + await self._ws.initialize(cookies, session_id) + except SessionTerminatedException as stex: _LOGGER.info(f"Session terminated ({stex})") @@ -364,8 +373,11 @@ def load_system_data(self, devices_data, system_info_data): return system_data = devices_data.get("system", {}) + firmware_version = system_info_data.get("fw-latest", {}) + version = firmware_version.get("version") + self.hostname = system_data.get("host-name", self.hostname) - self.version = system_info_data.get("sw_ver", "N/A") + self.version = version def handle_interfaces(self, data): try: diff --git a/custom_components/edgeos/manifest.json b/custom_components/edgeos/manifest.json index 94e4bd5..596c508 100644 --- a/custom_components/edgeos/manifest.json +++ b/custom_components/edgeos/manifest.json @@ -6,6 +6,6 @@ "codeowners": ["@elad-bar"], "requirements": ["aiohttp"], "config_flow": true, - "version": "1.1.3", + "version": "1.1.4", "iot_class": "local_polling" } diff --git a/custom_components/edgeos/strings.json b/custom_components/edgeos/strings.json index c2ec90f..6e17b68 100644 --- a/custom_components/edgeos/strings.json +++ b/custom_components/edgeos/strings.json @@ -24,7 +24,7 @@ "invalid_dpi_configuration": "Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable", "empty_device_data": "Could not retrieve device data from EdgeOS Router", "already_configured": "EdgeOS integration already configured with the name", - "incompatible_version": "Incompatible version (Required at least v1.10)" + "incompatible_version": "Unsupported firmware version" } }, "options": { @@ -59,7 +59,7 @@ "invalid_dpi_configuration": "Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable", "empty_device_data": "Could not retrieve device data from EdgeOS Router", "already_configured": "EdgeOS integration already configured with the name", - "incompatible_version": "Incompatible version (Required at least v1.10)" + "incompatible_version": "Unsupported firmware version" } } } diff --git a/custom_components/edgeos/translations/en.json b/custom_components/edgeos/translations/en.json index c2ec90f..6e17b68 100644 --- a/custom_components/edgeos/translations/en.json +++ b/custom_components/edgeos/translations/en.json @@ -24,7 +24,7 @@ "invalid_dpi_configuration": "Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable", "empty_device_data": "Could not retrieve device data from EdgeOS Router", "already_configured": "EdgeOS integration already configured with the name", - "incompatible_version": "Incompatible version (Required at least v1.10)" + "incompatible_version": "Unsupported firmware version" } }, "options": { @@ -59,7 +59,7 @@ "invalid_dpi_configuration": "Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable", "empty_device_data": "Could not retrieve device data from EdgeOS Router", "already_configured": "EdgeOS integration already configured with the name", - "incompatible_version": "Incompatible version (Required at least v1.10)" + "incompatible_version": "Unsupported firmware version" } } } diff --git a/custom_components/edgeos/translations/nb.json b/custom_components/edgeos/translations/nb.json index f6d9e44..2a820da 100644 --- a/custom_components/edgeos/translations/nb.json +++ b/custom_components/edgeos/translations/nb.json @@ -24,7 +24,7 @@ "invalid_dpi_configuration": "Konfigurasjon av dyp pakkeinspeksjon (trafikkanalyse) er deaktivert, vennligst aktiver", "empty_device_data": "Kunne ikke hente enhetsdata fra EdgeOS Router", "already_configured": "EdgeOS-integrasjon allerede konfigurert med navnet", - "incompatible_version": "Inkompatibel versjon (påkrevd minst v1.10)" + "incompatible_version": "Inkompatibel versjon (påkrevd minst v2.0)" } }, "options": { @@ -59,7 +59,7 @@ "invalid_dpi_configuration": "Konfigurasjon av dyp pakkeinspeksjon (trafikkanalyse) er deaktivert, vennligst aktiver", "empty_device_data": "Kunne ikke hente enhetsdata fra EdgeOS Router", "already_configured": "EdgeOS-integrasjon allerede konfigurert med navnet", - "incompatible_version": "Inkompatibel versjon (påkrevd minst v1.10)" + "incompatible_version": "Inkompatibel versjon (påkrevd minst v2.0)" } } } diff --git a/info.md b/info.md index 3de5d3b..a969748 100644 --- a/info.md +++ b/info.md @@ -10,7 +10,7 @@ Provides an integration between EdgeOS (Ubiquiti) routers to Home Assistant. Look for "Integration with EdgeOS (Ubiquiti)" and install #### Requirements -* EdgeRouter with version 1.10 at least +* EdgeRouter with at least firmware version 2.0 * EdgeRouter User with 'Operator' level access or higher * Traffic Analysis set to 'Enabled' (both `dpi` and `export` enabled under `system/traffic-analysis`) @@ -35,7 +35,7 @@ General authentication error (when failed to get valid response from device) | Could not retrieve device data from EdgeOS Router | Export (traffic-analysis) configuration is disabled, please enable | Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable | -Incompatible version (Required at least v1.10) +Unsupported firmware version| ###### Encryption key got corrupted If a persistent notification popped up with the following message: