File: dpi_restriction_app.py

package info (click to toggle)
python-aiounifi 79-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: python: 11,124; sh: 5; makefile: 5
file content (83 lines) | stat: -rw-r--r-- 1,884 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
"""DPI Restrictions as part of a UniFi network."""

from dataclasses import dataclass
from typing import Self, TypedDict

from .api import ApiItem, ApiRequest


class TypedDPIRestrictionApp(TypedDict):
    """DPI restriction app type definition."""

    _id: str
    apps: list[str]
    blocked: bool
    cats: list[str]
    enabled: bool
    log: bool
    site_id: str


@dataclass
class DpiRestrictionAppListRequest(ApiRequest):
    """Request object for DPI restriction app list."""

    @classmethod
    def create(cls) -> Self:
        """Create DPI restriction app list request."""
        return cls(method="get", path="/rest/dpiapp")


@dataclass
class DPIRestrictionAppEnableRequest(ApiRequest):
    """Request object for enabling DPI Restriction App."""

    @classmethod
    def create(cls, app_id: str, enable: bool) -> Self:
        """Create enabling DPI Restriction App request."""
        return cls(
            method="put",
            path=f"/rest/dpiapp/{app_id}",
            data={"enabled": enable},
        )


class DPIRestrictionApp(ApiItem):
    """Represents a DPI App configuration."""

    raw: TypedDPIRestrictionApp

    @property
    def id(self) -> str:
        """DPI app ID."""
        return self.raw["_id"]

    @property
    def apps(self) -> list[str]:
        """List of apps."""
        return self.raw["apps"]

    @property
    def blocked(self) -> bool:
        """Is blocked."""
        return self.raw["blocked"]

    @property
    def cats(self) -> list[str]:
        """Categories."""
        return self.raw["cats"]

    @property
    def enabled(self) -> bool:
        """Is enabled."""
        return self.raw["enabled"]

    @property
    def log(self) -> bool:
        """Is logging enabled."""
        return self.raw["log"]

    @property
    def site_id(self) -> str:
        """Site ID."""
        return self.raw["site_id"]