Skip to content

Commit

Permalink
installation: parse user access type
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
  • Loading branch information
Noltari committed Jul 25, 2024
1 parent 3e4e8a2 commit be119c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions aioairzone_cloud/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,21 @@ def parse_str(data: Any) -> str | None:
if data is not None:
return str(data)
return None


class UserAccessType(StrEnum):
"""Airzone Cloud user access type."""

UNKNOWN = "unknown"

ADMIN = "admin"
ADVANCED = "advanced"
BASIC = "basic"

@classmethod
def _missing_(cls, value: Any) -> UserAccessType:
return cls.UNKNOWN

def is_admin(self) -> bool:
"""Return if access type is admin."""
return self.value in [self.ADMIN, self.ADVANCED]
5 changes: 5 additions & 0 deletions aioairzone_cloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

AIRZONE_SERVER: Final[str] = "m.airzonecloud.com"

API_ACCESS_TYPE: Final[str] = "access_type"
API_ACTIVE: Final[str] = "active"
API_AIR_ACTIVE: Final[str] = "air_active"
API_AUTH_LOGIN: Final[str] = "auth/login"
Expand Down Expand Up @@ -97,6 +98,9 @@
API_TIMER: Final[str] = "timer"
API_TOKEN: Final[str] = "token"
API_TYPE: Final[str] = "type"
API_TYPE_ALL: Final[str] = "all"
API_TYPE_ADVANCED: Final[str] = "advanced"
API_TYPE_USER: Final[str] = "user"
API_UNITS: Final[str] = "units"
API_URL: Final[str] = f"https://{AIRZONE_SERVER}"
API_USER: Final[str] = "user"
Expand Down Expand Up @@ -200,6 +204,7 @@
AZD_TEMP_SET_MIN_VENT_AIR: Final[str] = "temperature-setpoint-min-vent-air"
AZD_TEMP_SET_MIN: Final[str] = "temperature-setpoint-min"
AZD_TYPE: Final[str] = "type"
AZD_USER_ACCESS: Final[str] = "user-access"
AZD_WARNINGS: Final[str] = "warnings"
AZD_WEBSERVER: Final[str] = "web-server"
AZD_WEBSERVERS: Final[str] = "web-servers"
Expand Down
21 changes: 21 additions & 0 deletions aioairzone_cloud/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

from typing import Any

from .common import UserAccessType
from .const import (
API_ACCESS_TYPE,
API_INSTALLATION_ID,
API_NAME,
API_TYPE_ALL,
API_TYPE_USER,
API_WS_IDS,
AZD_GROUPS,
AZD_NUM_GROUPS,
AZD_USER_ACCESS,
AZD_WEBSERVERS,
)
from .device_group import DeviceGroup
Expand All @@ -25,6 +30,7 @@ def __init__(self, inst_data: dict[str, Any]) -> None:

self.groups: dict[str, Group] = {}
self.id = str(inst_data[API_INSTALLATION_ID])
self.user_access: UserAccessType = UserAccessType.UNKNOWN
self.webservers: list[str] = []

name: str = inst_data.get(API_NAME, "")
Expand All @@ -33,6 +39,10 @@ def __init__(self, inst_data: dict[str, Any]) -> None:
else:
self.name = "Installation"

access_type = inst_data.get(API_ACCESS_TYPE)
if access_type is not None:
self.user_access = UserAccessType(str(access_type))

for ws_id in inst_data[API_WS_IDS]:
self.webservers += [ws_id]

Expand All @@ -44,6 +54,7 @@ def data(self) -> dict[str, Any]:
data[AZD_GROUPS] = list(self.groups)

data[AZD_NUM_GROUPS] = self.get_groups_num()
data[AZD_USER_ACCESS] = self.get_user_access()
data[AZD_WEBSERVERS] = self.get_webservers()

return data
Expand All @@ -66,6 +77,16 @@ def get_name(self) -> str:
"""Return Installation name."""
return self.name

def get_request_type(self) -> str:
"""Return request type."""
if self.user_access.is_admin():
return API_TYPE_ALL
return API_TYPE_USER

def get_user_access(self) -> str:
"""Return Installation user access."""
return self.user_access

def get_webservers(self) -> list[str]:
"""Return Installation WebServers."""
return self.webservers

0 comments on commit be119c3

Please sign in to comment.