diff --git a/README.md b/README.md index 9db7a4e..627aac8 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Config is done in the HA integrations UI. ### Host -The IP address of the main deco which you visit in the browser to see the web admin page. Example: `192.168.0.1` +The IP address of the main deco which you visit in the browser to see the web admin page. Example: `http://192.168.0.1`. Some decos use https, so if you have trouble connection, try using `https` e.g. `https://192.168.0.1`. ### Login Credentials diff --git a/custom_components/tplink_deco/__init__.py b/custom_components/tplink_deco/__init__.py index 1627412..e489441 100644 --- a/custom_components/tplink_deco/__init__.py +++ b/custom_components/tplink_deco/__init__.py @@ -263,6 +263,10 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry): new[CONF_DECO_PREFIX] = "" new[CONF_DECO_POSTFIX] = DEFAULT_DECO_POSTFIX + if config_entry.version == 5: + config_entry.version = 6 + new[CONF_HOST] = f"http://{new[CONF_HOST]}" + hass.config_entries.async_update_entry(config_entry, data=new) _LOGGER.info("Migration to version %s successful", config_entry.version) diff --git a/custom_components/tplink_deco/api.py b/custom_components/tplink_deco/api.py index a802ae8..beb79f5 100644 --- a/custom_components/tplink_deco/api.py +++ b/custom_components/tplink_deco/api.py @@ -172,7 +172,7 @@ async def _async_list_devices(self) -> dict: device_list_payload = {"operation": "read"} response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok={self._stok}/admin/device", + f"{self._host}/cgi-bin/luci/;stok={self._stok}/admin/device", params={"form": "device_list"}, data=self._encode_payload(device_list_payload), ) @@ -207,7 +207,7 @@ async def async_reboot_decos(self, deco_macs) -> dict: } response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok={self._stok}/admin/device", + f"{self._host}/cgi-bin/luci/;stok={self._stok}/admin/device", params={"form": "system"}, data=self._encode_payload(client_payload), ) @@ -227,7 +227,7 @@ async def _async_list_clients(self, deco_mac) -> dict: client_payload = {"operation": "read", "params": {"device_mac": deco_mac}} response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok={self._stok}/admin/client", + f"{self._host}/cgi-bin/luci/;stok={self._stok}/admin/client", params={"form": "client_list"}, data=self._encode_payload(client_payload), ) @@ -263,7 +263,7 @@ async def _async_fetch_keys(self): context = "Fetch keys" response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok=/login", + f"{self._host}/cgi-bin/luci/;stok=/login", params={"form": "keys"}, data=json.dumps({"operation": "read"}), ) @@ -288,7 +288,7 @@ async def _async_fetch_auth(self): context = "Fetch auth" response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok=/login", + f"{self._host}/cgi-bin/luci/;stok=/login", params={"form": "auth"}, data=json.dumps({"operation": "read"}), ) @@ -356,7 +356,7 @@ async def _async_login(self): try: response_json = await self._async_post( context, - f"http://{self._host}/cgi-bin/luci/;stok=/login", + f"{self._host}/cgi-bin/luci/;stok=/login", params={"form": "login"}, data=self._encode_payload(login_payload), ) diff --git a/custom_components/tplink_deco/config_flow.py b/custom_components/tplink_deco/config_flow.py index af69379..824c532 100644 --- a/custom_components/tplink_deco/config_flow.py +++ b/custom_components/tplink_deco/config_flow.py @@ -16,6 +16,7 @@ from homeassistant.core import callback from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.exceptions import ConfigEntryNotReady from .__init__ import async_create_and_refresh_coordinators from .const import CONF_CLIENT_POSTFIX @@ -54,7 +55,9 @@ def _get_schema(data: dict[str:Any]): scan_interval = data.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL) schema.update( { - vol.Required(CONF_HOST, default=data.get(CONF_HOST, "10.0.0.1")): str, + vol.Required( + CONF_HOST, default=data.get(CONF_HOST, "http://192.168.0.1") + ): str, vol.Required( CONF_SCAN_INTERVAL, default=scan_interval, @@ -126,17 +129,21 @@ async def _async_test_credentials(hass: HomeAssistant, data: dict[str:Any]): except TimeoutException: return {"base": "timeout_connect"} except ConfigEntryAuthFailed as err: - _LOGGER.warning("Error authenticating credentials: %s", err) + _LOGGER.error("Error authenticating credentials: %s", err) return {"base": "invalid_auth"} + except ConfigEntryNotReady as err: + _LOGGER.error("Error connection to host: %s", err) + return {"base": "invalid_host"} except Exception as err: - _LOGGER.warning("Error testing credentials: %s", err) + _LOGGER.error("Error testing credentials: %s", err) + raise err return {"base": "unknown"} class TplinkDecoFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Config flow for tplink_deco.""" - VERSION = 5 + VERSION = 6 CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL reauth_entry: ConfigEntry = None diff --git a/custom_components/tplink_deco/strings.json b/custom_components/tplink_deco/strings.json index 8fdac29..ebf2420 100644 --- a/custom_components/tplink_deco/strings.json +++ b/custom_components/tplink_deco/strings.json @@ -28,6 +28,7 @@ }, "error": { "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "invalid_host": "[%key:common::config_flow::error::invalid_host%]", "timeout_connect": "[%key:common::config_flow::error::timeout_connect%]", "unknown": "[%key:common::config_flow::error::unknown%]" } @@ -57,6 +58,7 @@ }, "error": { "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "invalid_host": "[%key:common::config_flow::error::invalid_host%]", "timeout_connect": "[%key:common::config_flow::error::timeout_connect%]", "unknown": "[%key:common::config_flow::error::unknown%]" } diff --git a/custom_components/tplink_deco/translations/en.json b/custom_components/tplink_deco/translations/en.json index 97189a1..6a3ad51 100644 --- a/custom_components/tplink_deco/translations/en.json +++ b/custom_components/tplink_deco/translations/en.json @@ -31,6 +31,7 @@ }, "error": { "invalid_auth": "Invalid authentication", + "invalid_host": "Unable to connect to host.", "timeout_connect": "Timeout establishing connection", "unknown": "Unexpected error" } @@ -57,6 +58,7 @@ }, "error": { "invalid_auth": "Invalid authentication", + "invalid_host": "Unable to connect to host.", "timeout_connect": "Timeout establishing connection", "unknown": "Unexpected error" }