-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathconst.py
284 lines (267 loc) · 10.6 KB
/
const.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"""The OPNsense component."""
from typing import Final
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import PERCENTAGE, UnitOfInformation, UnitOfTime
VERSION = "v0.3.13"
DOMAIN = "opnsense"
OPNSENSE_LTD_FIRMWARE = "24.7" # Some functions may not work but the integration in general should work. Show repair warning.
OPNSENSE_MIN_FIRMWARE = "24.1" # Don't allow install, will not work.
UNDO_UPDATE_LISTENER = "undo_update_listener"
PLATFORMS: list = ["sensor", "switch", "device_tracker", "binary_sensor", "update"]
LOADED_PLATFORMS = "loaded_platforms"
OPNSENSE_CLIENT = "opnsense_client"
COORDINATOR = "coordinator"
DEVICE_TRACKER_COORDINATOR = "device_tracker_coordinator"
SHOULD_RELOAD = "should_reload"
TRACKED_MACS = "tracked_macs"
DEFAULT_SCAN_INTERVAL = 30
CONF_TLS_INSECURE = "tls_insecure"
DEFAULT_TLS_INSECURE = False
DEFAULT_VERIFY_SSL = True
CONF_DEVICE_TRACKER_ENABLED = "device_tracker_enabled"
DEFAULT_DEVICE_TRACKER_ENABLED = False
CONF_DEVICE_TRACKER_SCAN_INTERVAL = "device_tracker_scan_interval"
DEFAULT_DEVICE_TRACKER_SCAN_INTERVAL = 150
CONF_DEVICE_TRACKER_CONSIDER_HOME = "device_tracker_consider_home"
DEFAULT_DEVICE_TRACKER_CONSIDER_HOME = 0
CONF_DEVICE_UNIQUE_ID = "device_unique_id"
CONF_FIRMWARE_VERSION = "firmware_version"
CONF_DEVICES = "devices"
CONF_MANUAL_DEVICES = "manual_devices"
COUNT = "count"
# pulled from upnp component
BYTES_RECEIVED = "bytes_received"
BYTES_SENT = "bytes_sent"
PACKETS_RECEIVED = "packets_received"
PACKETS_SENT = "packets_sent"
DATA_PACKETS = "packets"
DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{UnitOfTime.SECONDS}"
ICON_MEMORY = "mdi:memory"
ATTR_UNBOUND_BLOCKLIST = "unbound_blocklist"
ATTR_NAT_PORT_FORWARD = "nat_port_forward"
ATTR_NAT_OUTBOUND = "nat_outbound"
STATIC_SENSORS: Final[dict[str, SensorEntityDescription]] = {
# pfstate
"telemetry.pfstate.used": SensorEntityDescription(
key="telemetry.pfstate.used",
name="pf State Table Used",
native_unit_of_measurement=COUNT,
device_class=None,
icon="mdi:table-network",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.pfstate.total": SensorEntityDescription(
key="telemetry.pfstate.total",
name="pf State Table Total",
native_unit_of_measurement=COUNT,
device_class=None,
icon="mdi:table-network",
state_class=None,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.pfstate.used_percent": SensorEntityDescription(
key="telemetry.pfstate.used_percent",
name="pf State Table Used Percentage",
native_unit_of_measurement=PERCENTAGE,
device_class=None,
icon="mdi:table-network",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# mbuf
"telemetry.mbuf.used": SensorEntityDescription(
key="telemetry.mbuf.used",
name="Memory Buffers Used",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.KILOBYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.mbuf.total": SensorEntityDescription(
key="telemetry.mbuf.total",
name="Memory Buffers Total",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=None,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.KILOBYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.mbuf.used_percent": SensorEntityDescription(
key="telemetry.mbuf.used_percent",
name="Memory Buffers Used Percentage",
native_unit_of_measurement=PERCENTAGE,
device_class=None,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# memory with state_class due to being less static
"telemetry.memory.swap_reserved": SensorEntityDescription(
key="telemetry.memory.swap_reserved",
name="Memory Swap Reserved",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# memory without state_class due to being generally static
"telemetry.memory.physmem": SensorEntityDescription(
key="telemetry.memory.physmem",
name="Memory Physmem",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=None,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.used": SensorEntityDescription(
key="telemetry.memory.used",
name="Memory Used",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.swap_total": SensorEntityDescription(
key="telemetry.memory.swap_total",
name="Memory Swap Total",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon=ICON_MEMORY,
state_class=None,
suggested_display_precision=1,
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# memory percentages
"telemetry.memory.swap_used_percent": SensorEntityDescription(
key="telemetry.memory.swap_used_percent",
name="Memory Swap Used Percentage",
native_unit_of_measurement=PERCENTAGE,
device_class=None,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.used_percent": SensorEntityDescription(
key="telemetry.memory.used_percent",
name="Memory Used Percentage",
native_unit_of_measurement=PERCENTAGE,
device_class=None,
icon=ICON_MEMORY,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.cpu.count": SensorEntityDescription(
key="telemetry.cpu.count",
name="CPU Count",
native_unit_of_measurement=COUNT,
device_class=None,
icon="mdi:speedometer-medium",
state_class=None,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.cpu.usage_total": SensorEntityDescription(
key="telemetry.cpu.usage_total",
name="CPU Usage",
native_unit_of_measurement=PERCENTAGE,
device_class=None,
icon="mdi:speedometer-medium",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.load_average.one_minute": SensorEntityDescription(
key="telemetry.system.load_average.one_minute",
name="System Load Average One Minute",
native_unit_of_measurement=None,
device_class=None,
icon="mdi:speedometer-slow",
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.load_average.five_minute": SensorEntityDescription(
key="telemetry.system.load_average.five_minute",
name="System Load Average Five Minute",
native_unit_of_measurement=None,
device_class=None,
icon="mdi:speedometer-slow",
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.load_average.fifteen_minute": SensorEntityDescription(
key="telemetry.system.load_average.fifteen_minute",
name="System Load Average Fifteen Minute",
native_unit_of_measurement=None,
device_class=None,
icon="mdi:speedometer-slow",
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.boottime": SensorEntityDescription(
key="telemetry.system.boottime",
name="System Boottime",
device_class=SensorDeviceClass.TIMESTAMP,
icon="mdi:clock-outline",
state_class=None,
entity_registry_enabled_default=True,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"certificates": SensorEntityDescription(
key="certificates",
name="Certificates",
device_class=None,
icon="mdi:certificate-outline",
state_class=None,
entity_registry_enabled_default=False,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
SERVICE_CLOSE_NOTICE = "close_notice"
SERVICE_START_SERVICE = "start_service"
SERVICE_STOP_SERVICE = "stop_service"
SERVICE_RESTART_SERVICE = "restart_service"
SERVICE_SYSTEM_HALT = "system_halt"
SERVICE_SYSTEM_REBOOT = "system_reboot"
SERVICE_SEND_WOL = "send_wol"
SERVICE_RELOAD_INTERFACE = "reload_interface"
SERVICE_GENERATE_VOUCHERS = "generate_vouchers"
SERVICE_KILL_STATES = "kill_states"
SERVICE_TOGGLE_ALIAS = "toggle_alias"