Access Levels and Unknown Inventories
An OPNsense API user can be granted some privileges and not others. A getter
therefore has to tell an inventory the Router reports as empty apart from one
the API user may not see. Applications that delete items missing from an
inventory, as hass-opnsense does, depend on this distinction. The rules below
apply with throw_errors=False. Strict mode keeps each getter’s existing
exceptions.
Empty, missing and unknown inventories
Getters whose result is an inventory a caller reconciles follow one rule:
An empty inventory means the Router has nothing to report. A missing (404) endpoint means the feature is not installed, so the getter returns an empty inventory or the feature’s missing marker, such as
{"available": False}fromget_speedtest().Nonemeans the inventory is unknown: the read was forbidden (403), failed, or returned a body that could not be decoded or had the wrong shape. Keep the items you already have and reconcile on a later successful read.When one result holds several independent inventories, each is decided on its own.
get_telemetry()sets onlyfilesystemsortempstoNone, andget_firewall()does the same forrulesand each NAT group undernat.A read that only adds detail to items already listed leaves those details unset instead of making the inventory unknown.
These getters follow the rule: get_services(), get_unbound_blocklist(),
get_interfaces(), get_gateways(), get_telemetry() (filesystems
and temps), get_smart(), get_smart_info(),
get_nut_ups_status(), get_speedtest(), get_vnstat(),
get_carp(), get_firewall() (each rule group) and
get_dhcp_leases().
Status Access and Configuration Access
Some categories can still return useful data when the API user may read their live status but not their configuration. These getters report the access level detected from the Router’s answers on the result itself:
get_openvpn(),get_wireguard()andget_ipsec()get_dhcp_leases()get_carp()
Read the level with aiopnsense.result_access():
from aiopnsense import Access, result_access
openvpn = await client.get_openvpn()
if openvpn is None:
print("OpenVPN status unavailable; keep existing items")
elif result_access(openvpn) is Access.STATUS:
print("Inventory may be incomplete; do not remove missing items")
else:
print("Configuration Access; the inventory is complete")
Under Status Access the result may lack items or detail that the configuration reads would add, such as disabled VPN Instances or CARP VIP descriptions, and nothing can be Toggled. Treat it as incomplete: add and update items, but do not remove the ones it lacks. The level comes only from the Router; there is no option to set it.
The result is an AccessDict or AccessList, which compares equal to and
passes isinstance checks as a plain dict or list. The level survives
copy.deepcopy and pickling, but plain copies made with dict(),
list(), {**result} or JSON drop it. result_access() then returns
None, meaning the level was not reported. Handle that as you would a result
from a release without access reporting.
The design and the per-category details are recorded in ADR 0004, Results report their access level.
API reference
- class aiopnsense.Access(*values)[source]
Access level detected from the Router’s responses.
- STATUS = 'status'
- CONFIGURATION = 'configuration'
- class aiopnsense.AccessDict(data, *, access)[source]
Dictionary result that carries its reported access level.
Initialize a dictionary result.
- Parameters:
data (Mapping[K, V]) – Result entries.
access (Access) – Detected access level.
- class aiopnsense.AccessList(data, *, access)[source]
List result that carries its reported access level.
Initialize a list result.
- Parameters:
data (Iterable[T]) – Result items.
access (Access) – Detected access level.
- aiopnsense.result_access(result)[source]
Read the access level attached to a result.
- Parameters:
result (object) – Data returned by a getter.
- Returns:
- Reported level, or
Noneif the result does not carry one. Callers handle an unreported level as they handled results before access reporting existed. Deep copying and pickling preserve the level. Plain copies made with
dict(),list()or JSON serialization discard it.
- Reported level, or
- Return type:
Access | None