1 """UniFi Network config entry abstraction."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from datetime
import timedelta
8 from typing
import Literal, Self
20 CONF_ALLOW_BANDWIDTH_SENSORS,
21 CONF_ALLOW_UPTIME_SENSORS,
25 CONF_DPI_RESTRICTIONS,
26 CONF_IGNORE_WIRED_BUG,
31 CONF_TRACK_WIRED_CLIENTS,
32 DEFAULT_ALLOW_BANDWIDTH_SENSORS,
33 DEFAULT_ALLOW_UPTIME_SENSORS,
34 DEFAULT_DETECTION_TIME,
35 DEFAULT_DPI_RESTRICTIONS,
36 DEFAULT_IGNORE_WIRED_BUG,
37 DEFAULT_TRACK_CLIENTS,
38 DEFAULT_TRACK_DEVICES,
39 DEFAULT_TRACK_WIRED_CLIENTS,
45 """Represent a UniFi config entry."""
54 ssl_context: ssl.SSLContext | Literal[
False]
56 option_supported_clients: list[str]
57 """Allow creating entities from clients."""
61 option_track_clients: list[str]
62 """Config entry option to not track clients."""
63 option_track_wired_clients: list[str]
64 """Config entry option to not track wired clients."""
65 option_track_devices: bool
66 """Config entry option to not track devices."""
67 option_ssid_filter: set[str]
68 """Config entry option listing what SSIDs are being used to track clients."""
69 option_detection_time: timedelta
70 """Config entry option defining number of seconds from last seen to away"""
71 option_ignore_wired_bug: bool
72 """Config entry option to ignore wired bug."""
76 option_block_clients: list[str]
77 """Config entry option with list of clients to control network access."""
78 option_dpi_restrictions: bool
79 """Config entry option to control DPI restriction groups."""
83 option_allow_bandwidth_sensors: bool
84 """Config entry option to allow bandwidth sensors."""
85 option_allow_uptime_sensors: bool
86 """Config entry option to allow uptime sensors."""
90 """Create object from config entry."""
91 config = config_entry.data
92 options = config_entry.options
95 host=config[CONF_HOST],
96 username=config[CONF_USERNAME],
97 password=config[CONF_PASSWORD],
98 port=config[CONF_PORT],
99 site=config[CONF_SITE_ID],
100 ssl_context=config.get(CONF_VERIFY_SSL,
False),
101 option_supported_clients=options.get(CONF_CLIENT_SOURCE, []),
102 option_track_clients=options.get(CONF_TRACK_CLIENTS, DEFAULT_TRACK_CLIENTS),
103 option_track_wired_clients=options.get(
104 CONF_TRACK_WIRED_CLIENTS, DEFAULT_TRACK_WIRED_CLIENTS
106 option_track_devices=options.get(CONF_TRACK_DEVICES, DEFAULT_TRACK_DEVICES),
107 option_ssid_filter=set(options.get(CONF_SSID_FILTER, [])),
109 seconds=options.get(CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME)
111 option_ignore_wired_bug=options.get(
112 CONF_IGNORE_WIRED_BUG, DEFAULT_IGNORE_WIRED_BUG
114 option_block_clients=options.get(CONF_BLOCK_CLIENT, []),
115 option_dpi_restrictions=options.get(
116 CONF_DPI_RESTRICTIONS, DEFAULT_DPI_RESTRICTIONS
118 option_allow_bandwidth_sensors=options.get(
119 CONF_ALLOW_BANDWIDTH_SENSORS, DEFAULT_ALLOW_BANDWIDTH_SENSORS
121 option_allow_uptime_sensors=options.get(
122 CONF_ALLOW_UPTIME_SENSORS, DEFAULT_ALLOW_UPTIME_SENSORS
Self from_config_entry(cls, ConfigEntry config_entry)