File: installation.py

package info (click to toggle)
python-aioairzone-cloud 0.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 3,600; makefile: 4
file content (92 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Airzone Cloud API Installation."""

from __future__ import annotations

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
from .group import Group


class Installation(DeviceGroup):
    """Airzone Cloud Installation."""

    def __init__(self, inst_data: dict[str, Any]) -> None:
        """Airzone Cloud Installation init."""
        super().__init__()

        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, "")
        if len(name) > 0:
            self.name = name
        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]

    def data(self) -> dict[str, Any]:
        """Return Installation data."""
        data = super().data()

        if len(self.groups) > 0:
            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

    def add_group(self, group: Group) -> None:
        """Add Group to Installation."""
        group_id = group.get_id()
        if group_id not in self.groups:
            self.groups[group_id] = group

    def get_groups_num(self) -> int:
        """Return Groups count."""
        return len(self.groups)

    def get_id(self) -> str:
        """Return Installation ID."""
        return self.id

    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