diff --git a/custom_components/mikrotik_router/.translations/en.json b/custom_components/mikrotik_router/.translations/en.json index 5aca891..36630e6 100644 --- a/custom_components/mikrotik_router/.translations/en.json +++ b/custom_components/mikrotik_router/.translations/en.json @@ -17,9 +17,9 @@ }, "error": { "name_exists": "Name already exists.", + "librouteros_invalid": "Invalid librouteros library version installed.", "cannot_connect": "Cannot connect to Mikrotik.", - "wrong_login": "Invalid user name or password.", - "routeros_api_missing": "Python module routeros_api not installed." + "wrong_login": "Invalid user name or password." } }, "options": { @@ -29,7 +29,7 @@ }, "device_tracker": { "data": { - "scan_interval": "Scan interval", + "scan_interval": "Scan interval (requires HA restart)", "track_arp": "Show client MAC and IP on interfaces" } } diff --git a/custom_components/mikrotik_router/config_flow.py b/custom_components/mikrotik_router/config_flow.py index d9ee507..ae91a3f 100644 --- a/custom_components/mikrotik_router/config_flow.py +++ b/custom_components/mikrotik_router/config_flow.py @@ -21,6 +21,7 @@ from .const import ( DEFAULT_SCAN_INTERVAL, ) +from .exceptions import OldLibrouteros from .mikrotikapi import MikrotikAPI _LOGGER = logging.getLogger(__name__) @@ -64,14 +65,18 @@ class MikrotikControllerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors["base"] = "name_exists" # Test connection - api = MikrotikAPI(host=user_input["host"], - username=user_input["username"], - password=user_input["password"], - port=user_input["port"], - use_ssl=user_input["ssl"] - ) - if not api.connect(): - errors[CONF_HOST] = api.error + try: + api = MikrotikAPI(host=user_input["host"], + username=user_input["username"], + password=user_input["password"], + port=user_input["port"], + use_ssl=user_input["ssl"] + ) + except OldLibrouteros: + errors["base"] = "librouteros_invalid" + else: + if not api.connect(): + errors[CONF_HOST] = api.error # Save instance if not errors: diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index cb0bbe0..d87334b 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -39,11 +39,11 @@ class MikrotikAPI: # --------------------------- def check_library(self): 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) 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) # --------------------------- diff --git a/custom_components/mikrotik_router/strings.json b/custom_components/mikrotik_router/strings.json index 5a74126..36630e6 100644 --- a/custom_components/mikrotik_router/strings.json +++ b/custom_components/mikrotik_router/strings.json @@ -17,9 +17,9 @@ }, "error": { "name_exists": "Name already exists.", + "librouteros_invalid": "Invalid librouteros library version installed.", "cannot_connect": "Cannot connect to Mikrotik.", - "wrong_login": "Invalid user name or password.", - "routeros_api_missing": "Python module routeros_api not installed." + "wrong_login": "Invalid user name or password." } }, "options": {