Add ability to track accounting data from Mikrotik.

This commit is contained in:
Ivan Pavlina 2020-04-04 19:42:05 +02:00
parent 35936352a8
commit 30c11db741
9 changed files with 449 additions and 13 deletions

View file

@ -27,6 +27,7 @@ from .const import (
DEFAULT_SCAN_INTERVAL,
DEFAULT_TRAFFIC_TYPE,
TRAFFIC_TYPES,
CONF_TRACK_ACCOUNTING,
)
from .mikrotikapi import MikrotikAPI
@ -51,7 +52,7 @@ def configured_instances(hass):
class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN):
"""MikrotikControllerConfigFlow class"""
VERSION = 1
VERSION = 2
CONNECTION_CLASS = CONN_CLASS_LOCAL_POLL
def __init__(self):
@ -81,10 +82,13 @@ class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN):
username=user_input["username"],
password=user_input["password"],
port=user_input["port"],
use_ssl=user_input["ssl"],
use_ssl=user_input["ssl"]
)
if not api.connect():
errors[CONF_HOST] = api.error
else:
if user_input[CONF_TRACK_ACCOUNTING] and not api.is_accounting_enabled():
errors[CONF_HOST] = "accounting_disabled"
# Save instance
if not errors:
@ -99,6 +103,7 @@ class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN):
port=user_input["port"],
name=user_input["name"],
use_ssl=user_input["ssl"],
track_accounting=user_input["track_accounting"],
errors=errors,
)
@ -115,6 +120,7 @@ class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN):
port=0,
name="Mikrotik",
use_ssl=False,
track_accounting=False,
errors=None,
):
"""Show the configuration form to edit data."""
@ -131,6 +137,7 @@ class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN):
vol.Optional(CONF_PORT, default=port): int,
vol.Optional(CONF_NAME, default=name): str,
vol.Optional(CONF_SSL, default=use_ssl): bool,
vol.Optional(CONF_TRACK_ACCOUNTING, default=track_accounting): bool,
}
),
errors=errors,