diff --git a/homeassistant/components/lg_thinq/__init__.py b/homeassistant/components/lg_thinq/__init__.py index a8d3fe175ef..657524f0ef5 100644 --- a/homeassistant/components/lg_thinq/__init__.py +++ b/homeassistant/components/lg_thinq/__init__.py @@ -95,6 +95,7 @@ async def async_setup_coordinators( raise ConfigEntryNotReady(exc.message) from exc if not bridge_list: + _LOGGER.warning("No devices registered with the correct profile") return # Setup coordinator per device. diff --git a/homeassistant/components/lg_thinq/config_flow.py b/homeassistant/components/lg_thinq/config_flow.py index cdb41916688..3bbcf3cd226 100644 --- a/homeassistant/components/lg_thinq/config_flow.py +++ b/homeassistant/components/lg_thinq/config_flow.py @@ -6,7 +6,7 @@ import logging from typing import Any import uuid -from thinqconnect import ThinQApi, ThinQAPIException +from thinqconnect import ThinQApi, ThinQAPIErrorCodes, ThinQAPIException from thinqconnect.country import Country import voluptuous as vol @@ -26,6 +26,13 @@ from .const import ( ) SUPPORTED_COUNTRIES = [country.value for country in Country] +THINQ_ERRORS = { + ThinQAPIErrorCodes.INVALID_TOKEN: "invalid_token", + ThinQAPIErrorCodes.NOT_ACCEPTABLE_TERMS: "not_acceptable_terms", + ThinQAPIErrorCodes.NOT_ALLOWED_API_AGAIN: "not_allowed_api_again", + ThinQAPIErrorCodes.NOT_SUPPORTED_COUNTRY: "not_supported_country", + ThinQAPIErrorCodes.EXCEEDED_API_CALLS: "exceeded_api_calls", +} _LOGGER = logging.getLogger(__name__) @@ -83,8 +90,9 @@ class ThinQFlowHandler(ConfigFlow, domain=DOMAIN): try: return await self._validate_and_create_entry(access_token, country_code) - except ThinQAPIException: - errors["base"] = "token_unauthorized" + except ThinQAPIException as exc: + errors["base"] = THINQ_ERRORS.get(exc.code, "token_unauthorized") + _LOGGER.error("Failed to validate access_token %s", exc) return self.async_show_form( step_id="user", diff --git a/homeassistant/components/lg_thinq/coordinator.py b/homeassistant/components/lg_thinq/coordinator.py index 0ba859b1228..9f317dc21d9 100644 --- a/homeassistant/components/lg_thinq/coordinator.py +++ b/homeassistant/components/lg_thinq/coordinator.py @@ -77,5 +77,9 @@ async def async_setup_device_coordinator( coordinator = DeviceDataUpdateCoordinator(hass, ha_bridge) await coordinator.async_refresh() - _LOGGER.debug("Setup device's coordinator: %s", coordinator.device_name) + _LOGGER.debug( + "Setup device's coordinator: %s, model:%s", + coordinator.device_name, + coordinator.api.device.model_name, + ) return coordinator diff --git a/homeassistant/components/lg_thinq/entity.py b/homeassistant/components/lg_thinq/entity.py index f31b535dcaf..7856506559b 100644 --- a/homeassistant/components/lg_thinq/entity.py +++ b/homeassistant/components/lg_thinq/entity.py @@ -51,7 +51,7 @@ class ThinQEntity(CoordinatorEntity[DeviceDataUpdateCoordinator]): self._attr_device_info = dr.DeviceInfo( identifiers={(DOMAIN, coordinator.unique_id)}, manufacturer=COMPANY, - model=coordinator.api.device.model_name, + model=f"{coordinator.api.device.model_name} ({self.coordinator.api.device.device_type})", name=coordinator.device_name, ) self._attr_unique_id = f"{coordinator.unique_id}_{self.property_id}" diff --git a/homeassistant/components/lg_thinq/mqtt.py b/homeassistant/components/lg_thinq/mqtt.py index 30d1302e458..8759869aad3 100644 --- a/homeassistant/components/lg_thinq/mqtt.py +++ b/homeassistant/components/lg_thinq/mqtt.py @@ -167,7 +167,6 @@ class ThinQMQTT: async def async_handle_device_event(self, message: dict) -> None: """Handle received mqtt message.""" - _LOGGER.debug("async_handle_device_event: message=%s", message) unique_id = ( f"{message["deviceId"]}_{list(message["report"].keys())[0]}" if message["deviceType"] == DeviceType.WASHTOWER @@ -178,6 +177,12 @@ class ThinQMQTT: _LOGGER.error("Failed to handle device event: No device") return + _LOGGER.debug( + "async_handle_device_event: %s, model:%s, message=%s", + coordinator.device_name, + coordinator.api.device.model_name, + message, + ) push_type = message.get("pushType") if push_type == DEVICE_STATUS_MESSAGE: diff --git a/homeassistant/components/lg_thinq/strings.json b/homeassistant/components/lg_thinq/strings.json index 277e3db3df0..a776dde2054 100644 --- a/homeassistant/components/lg_thinq/strings.json +++ b/homeassistant/components/lg_thinq/strings.json @@ -5,6 +5,12 @@ "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]" }, "error": { + "invalid_token": "The token is not valid.", + "not_acceptable_terms": "The service terms are not accepted.", + "not_allowed_api_again": "The user does NOT have permission on the API call.", + "not_supported_country": "The country is not supported.", + "exceeded_api_calls": "The number of API calls has been exceeded.", + "exceeded_user_api_calls": "The number of User API calls has been exceeded.", "token_unauthorized": "The token is invalid or unauthorized." }, "step": { diff --git a/tests/components/lg_thinq/test_config_flow.py b/tests/components/lg_thinq/test_config_flow.py index e7ee632810e..8c5afb4dac7 100644 --- a/tests/components/lg_thinq/test_config_flow.py +++ b/tests/components/lg_thinq/test_config_flow.py @@ -50,7 +50,7 @@ async def test_config_flow_invalid_pat( data={CONF_ACCESS_TOKEN: MOCK_PAT, CONF_COUNTRY: MOCK_COUNTRY}, ) assert result["type"] is FlowResultType.FORM - assert result["errors"] == {"base": "token_unauthorized"} + assert result["errors"] mock_invalid_thinq_api.async_get_device_list.assert_called_once()