-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #53 - integration fails to load EdgeOS older than 2.0.9
- Loading branch information
Showing
9 changed files
with
98 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +0,0 @@ | ||
from homeassistant.exceptions import HomeAssistantError | ||
|
||
|
||
class SessionTerminatedException(HomeAssistantError): | ||
Terminated = True | ||
|
||
|
||
class LoginException(HomeAssistantError): | ||
def __init__(self, status_code): | ||
self._status_code = status_code | ||
|
||
@property | ||
def status_code(self): | ||
return self._status_code | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from ..helpers.const import * | ||
from ..models.exceptions import IncompatibleVersion | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
MAX_PARTS = 3 | ||
MINIMUM_EDGEOS_VERSION = "1.10" | ||
|
||
class VersionManager: | ||
version: Optional[str] | ||
|
||
class VersionCheck: | ||
def __init__(self): | ||
self._minimum_version_score = self._get_score(MINIMUM_EDGEOS_VERSION) | ||
|
||
@staticmethod | ||
def _get_score(version): | ||
ver_number_arr = version.split(".") | ||
|
||
multiplier = 100000000 | ||
total_version = 0 | ||
|
||
max_numbers_to_check = len(ver_number_arr) | ||
if max_numbers_to_check > MAX_PARTS: | ||
max_numbers_to_check = MAX_PARTS | ||
self.version = None | ||
|
||
for i in range(0, max_numbers_to_check): | ||
ver_id = int(ver_number_arr[i]) * multiplier | ||
total_version = total_version + ver_id | ||
def validate(self): | ||
if self.version is None: | ||
raise IncompatibleVersion(self.version) | ||
|
||
multiplier = multiplier / 10000 | ||
if self.version == EDGEOS_VERSION_UNKNOWN: | ||
raise IncompatibleVersion(self.version) | ||
|
||
return total_version | ||
if self.version[:2] == EDGEOS_VERSION_INCOMPATIBLE: | ||
raise IncompatibleVersion(self.version) | ||
|
||
def is_compatible(self, fw_version): | ||
version_parts = fw_version.split("v") | ||
version = version_parts[len(version_parts) - 1] | ||
def update(self, system_info_data): | ||
firmware_version = system_info_data.get("fw-latest", None) | ||
if firmware_version is None: | ||
software_version = system_info_data.get("sw_ver", "N/A") | ||
software_version_items = software_version.split(".") | ||
|
||
version_score = self._get_score(version) | ||
version_without_build = software_version_items[:-3] | ||
version_without_model = version_without_build[2:] | ||
version = '.'.join(version_without_model) | ||
|
||
is_compatible = version_score >= self._minimum_version_score | ||
else: | ||
version = firmware_version.get("version", "N/A") | ||
|
||
return is_compatible | ||
self.version = version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from homeassistant.exceptions import HomeAssistantError | ||
|
||
|
||
class IncompatibleVersion(HomeAssistantError): | ||
def __init__(self, version): | ||
self._version = version | ||
|
||
def __repr__(self): | ||
return f"Unsupported EdgeOS version ({self._version})" | ||
|
||
|
||
class SessionTerminatedException(HomeAssistantError): | ||
Terminated = True | ||
|
||
|
||
class LoginException(HomeAssistantError): | ||
def __init__(self, status_code): | ||
self._status_code = status_code | ||
|
||
@property | ||
def status_code(self): | ||
return self._status_code |