Skip to content

Commit

Permalink
Fixes for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mjiggidy committed Mar 29, 2022
1 parent 3b832f7 commit 3d9fd5c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
3 changes: 3 additions & 0 deletions adderlib/adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def login(self, username:str, password:str):
"password":password
}

if self._user.logged_in:
raise AdderRequestError(f"Already logged in as {self._user.username}")

response = self._url_handler.api_call(self._server_address, args)

if response.get("success") == "1" and response.get("token") is not None:
Expand Down
34 changes: 17 additions & 17 deletions adderlib/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class DeviceModel(enum.Enum):
ALIF1002 = 's'
ALIF2020 = 't'
ALIF100T = 'd'
ALIF100T_VGA = 'f',
ALIF101T_HDMI = 'h',
ALIF4021R = '4',
ALIF100T_VGA = 'f'
ALIF101T_HDMI = 'h'
ALIF4021R = '4'
ALIFE300R = '8'


Expand Down Expand Up @@ -273,7 +273,7 @@ def __init__(self, properties:dict):
@property
def name(self) -> str:
"""Device name"""
return self._extended.get("d_name","")
return self._extended.get("name","")

@property
def ip_address(self) -> typing.Union[ipaddress.IPv4Address, ipaddress.IPv6Address, None]:
Expand All @@ -285,7 +285,7 @@ def mac_address(self) -> str:

@property
def is_online(self) -> bool:
return self._extended.get("online") == 1
return self._extended.get("online") == "1"

@property
def network_interface(self) -> NetworkInterface:
Expand All @@ -308,28 +308,28 @@ class AdderServer:
@enum.unique
class Role(enum.Enum):
"""The role of the AIM"""
SOLO = "solo",
BACKUP = "backup",
PRIMARY = "primary",
UNCONFIGURED = "unconfigured",
SOLO = "solo"
BACKUP = "backup"
PRIMARY = "primary"
UNCONFIGURED = "unconfigured"
UNKNOWN = "unknown"

@enum.unique
class Status(enum.Enum):
"""The status of the AIM"""
ACTIVE = "active",
STANDBY = "standby",
FAILED = "failed",
QUISCENT = "quiscent",
ACTIVE = "active"
STANDBY = "standby"
FAILED = "failed"
QUISCENT = "quiscent"
UNKNOWN = "unknown"

@enum.unique
class DualEthernetConfig(enum.Enum):
"""The configuration of the second ethernet port"""
NO = 0,
DHCP = 1,
STATIC = 2,
BONDED = 3,
NO = 0
DHCP = 1
STATIC = 2
BONDED = 3
UNKNOWN = -1


Expand Down
8 changes: 4 additions & 4 deletions adderlib/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def description(self) -> str:
def pair_count(self) -> int:
"""Number of valid channel/receiver pairs"""
cp_pairs = self._extended.get("cp_pairs","")
return int(cp_pairs) if cp_pairs.isnumeric() else 0
return int(cp_pairs) if str(cp_pairs).isnumeric() else 0

@property
def pair_problem_count(self) -> int:
"""Number of problematic channel/receiver pairs"""
problem_cp_pairs = self._extended.get("problem_cp_pairs","0")
return int(problem_cp_pairs) if problem_cp_pairs.isnumeric() else 0
problem_cp_pairs = self._extended.get("problem_cp_pairs","")
return int(problem_cp_pairs) if str(problem_cp_pairs).isnumeric() else 0

@property
def currently_active(self) -> ActiveState:
Expand All @@ -68,7 +68,7 @@ def currently_active(self) -> ActiveState:
def connected_rx_count(self) -> int:
"""The number of receivers already connected to this preset"""
rx_count = self._extended.get("connected_rx_count","")
return int(rx_count) if rx_count.isnumeric() else 0
return int(rx_count) if str(rx_count).isnumeric() else 0

@property
def view_button(self) -> ButtonState:
Expand Down
2 changes: 1 addition & 1 deletion adderlib/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def set_logged_out(self):
@property
def logged_in(self) -> bool:
"""Whether the user has been successfully authenticated"""
return self._username and self._token
return bool(self._username and self._token)

@property
def logged_out(self) -> bool:
Expand Down

0 comments on commit 3d9fd5c

Please sign in to comment.