-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoon_policy.py
More file actions
40 lines (30 loc) · 1.36 KB
/
Copy pathoon_policy.py
File metadata and controls
40 lines (30 loc) · 1.36 KB
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
"""OON policy model for UniFi Network Rules integration."""
from __future__ import annotations
from typing import Any
class OONPolicy:
"""Representation of a UniFi Object-Oriented Network policy."""
def __init__(self, data: dict[str, Any]) -> None:
"""Initialize OON policy from raw API data."""
self.raw = data.copy() # Store raw data for API updates
# Core properties
# UniFi API uses "_id" but some responses may use "id"
self._id = data.get("_id") or data.get("id")
self.name = data.get("name", "")
self.enabled = data.get("enabled", False)
self.target_type = data.get("target_type", "CLIENTS")
self.targets = data.get("targets", [])
# Nested configurations stored as dicts (can be parsed if needed)
self.qos = data.get("qos", {})
self.route = data.get("route", {})
self.secure = data.get("secure", {})
@property
def id(self) -> str:
"""Get the policy ID."""
return self._id or ""
def to_api_dict(self) -> dict[str, Any]:
"""Convert to dictionary for API updates."""
return dict(self.raw)
def has_kill_switch(self) -> bool:
"""Check if policy has routing enabled with kill switch."""
route = self.route
return route.get("enabled", False) is True and isinstance(route.get("kill_switch"), bool)