1 """Support for OPNSense Routers."""
5 from pyopnsense
import diagnostics
6 from pyopnsense.exceptions
import APIException
7 import voluptuous
as vol
15 _LOGGER = logging.getLogger(__name__)
17 CONF_API_SECRET =
"api_secret"
18 CONF_TRACKER_INTERFACE =
"tracker_interfaces"
22 OPNSENSE_DATA = DOMAIN
24 CONFIG_SCHEMA = vol.Schema(
28 vol.Required(CONF_URL): cv.url,
29 vol.Required(CONF_API_KEY): cv.string,
30 vol.Required(CONF_API_SECRET): cv.string,
31 vol.Optional(CONF_VERIFY_SSL, default=
False): cv.boolean,
32 vol.Optional(CONF_TRACKER_INTERFACE, default=[]): vol.All(
33 cv.ensure_list, [cv.string]
38 extra=vol.ALLOW_EXTRA,
42 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
43 """Set up the opnsense component."""
47 api_key = conf[CONF_API_KEY]
48 api_secret = conf[CONF_API_SECRET]
49 verify_ssl = conf[CONF_VERIFY_SSL]
50 tracker_interfaces = conf[CONF_TRACKER_INTERFACE]
52 interfaces_client = diagnostics.InterfaceClient(
53 api_key, api_secret, url, verify_ssl, timeout=20
56 interfaces_client.get_arp()
58 _LOGGER.exception(
"Failure while connecting to OPNsense API endpoint")
61 if tracker_interfaces:
63 netinsight_client = diagnostics.NetworkInsightClient(
64 api_key, api_secret, url, verify_ssl, timeout=20
66 interfaces =
list(netinsight_client.get_interfaces().values())
67 for interface
in tracker_interfaces:
68 if interface
not in interfaces:
70 "Specified OPNsense tracker interface %s is not found", interface
74 hass.data[OPNSENSE_DATA] = {
75 "interfaces": interfaces_client,
76 CONF_TRACKER_INTERFACE: tracker_interfaces,
79 load_platform(hass, Platform.DEVICE_TRACKER, DOMAIN, tracker_interfaces, config)
bool setup(HomeAssistant hass, ConfigType config)
None load_platform(core.HomeAssistant hass, Platform|str component, str platform, DiscoveryInfoType|None discovered, ConfigType hass_config)