display invalid lib version in UI during setup #2

This commit is contained in:
tomaae 2019-12-07 22:34:07 +01:00
parent 6467673dce
commit 619871a719
4 changed files with 20 additions and 15 deletions

View file

@ -17,9 +17,9 @@
}, },
"error": { "error": {
"name_exists": "Name already exists.", "name_exists": "Name already exists.",
"librouteros_invalid": "Invalid librouteros library version installed.",
"cannot_connect": "Cannot connect to Mikrotik.", "cannot_connect": "Cannot connect to Mikrotik.",
"wrong_login": "Invalid user name or password.", "wrong_login": "Invalid user name or password."
"routeros_api_missing": "Python module routeros_api not installed."
} }
}, },
"options": { "options": {
@ -29,7 +29,7 @@
}, },
"device_tracker": { "device_tracker": {
"data": { "data": {
"scan_interval": "Scan interval", "scan_interval": "Scan interval (requires HA restart)",
"track_arp": "Show client MAC and IP on interfaces" "track_arp": "Show client MAC and IP on interfaces"
} }
} }

View file

@ -21,6 +21,7 @@ from .const import (
DEFAULT_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL,
) )
from .exceptions import OldLibrouteros
from .mikrotikapi import MikrotikAPI from .mikrotikapi import MikrotikAPI
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -64,14 +65,18 @@ class MikrotikControllerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "name_exists" errors["base"] = "name_exists"
# Test connection # Test connection
api = MikrotikAPI(host=user_input["host"], try:
username=user_input["username"], api = MikrotikAPI(host=user_input["host"],
password=user_input["password"], username=user_input["username"],
port=user_input["port"], password=user_input["password"],
use_ssl=user_input["ssl"] port=user_input["port"],
) use_ssl=user_input["ssl"]
if not api.connect(): )
errors[CONF_HOST] = api.error except OldLibrouteros:
errors["base"] = "librouteros_invalid"
else:
if not api.connect():
errors[CONF_HOST] = api.error
# Save instance # Save instance
if not errors: if not errors:

View file

@ -39,11 +39,11 @@ class MikrotikAPI:
# --------------------------- # ---------------------------
def check_library(self): def check_library(self):
if not hasattr(librouteros.exceptions, 'ConnectionClosed'): if not hasattr(librouteros.exceptions, 'ConnectionClosed'):
error = "Old librouteros installed, check for possible conflicts with other integrations." error = "Invalid librouteros library version installed, possible conflict with other software."
raise OldLibrouteros(error) raise OldLibrouteros(error)
if not hasattr(librouteros.exceptions, 'ProtocolError'): if not hasattr(librouteros.exceptions, 'ProtocolError'):
error = "Old librouteros installed, check for possible conflicts with other integrations." error = "Invalid librouteros library version installed, possible conflict with other software."
raise OldLibrouteros(error) raise OldLibrouteros(error)
# --------------------------- # ---------------------------

View file

@ -17,9 +17,9 @@
}, },
"error": { "error": {
"name_exists": "Name already exists.", "name_exists": "Name already exists.",
"librouteros_invalid": "Invalid librouteros library version installed.",
"cannot_connect": "Cannot connect to Mikrotik.", "cannot_connect": "Cannot connect to Mikrotik.",
"wrong_login": "Invalid user name or password.", "wrong_login": "Invalid user name or password."
"routeros_api_missing": "Python module routeros_api not installed."
} }
}, },
"options": { "options": {