Add config_flow's seperated reaseon and more debug information (#131131)

Co-authored-by: yunseon.park <yunseon.park@lge.com>
This commit is contained in:
LG-ThinQ-Integration 2024-11-23 04:12:01 +09:00 committed by GitHub
parent 49eeb2d99e
commit 02f16ff568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 7 deletions

View File

@ -95,6 +95,7 @@ async def async_setup_coordinators(
raise ConfigEntryNotReady(exc.message) from exc raise ConfigEntryNotReady(exc.message) from exc
if not bridge_list: if not bridge_list:
_LOGGER.warning("No devices registered with the correct profile")
return return
# Setup coordinator per device. # Setup coordinator per device.

View File

@ -6,7 +6,7 @@ import logging
from typing import Any from typing import Any
import uuid import uuid
from thinqconnect import ThinQApi, ThinQAPIException from thinqconnect import ThinQApi, ThinQAPIErrorCodes, ThinQAPIException
from thinqconnect.country import Country from thinqconnect.country import Country
import voluptuous as vol import voluptuous as vol
@ -26,6 +26,13 @@ from .const import (
) )
SUPPORTED_COUNTRIES = [country.value for country in Country] 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__) _LOGGER = logging.getLogger(__name__)
@ -83,8 +90,9 @@ class ThinQFlowHandler(ConfigFlow, domain=DOMAIN):
try: try:
return await self._validate_and_create_entry(access_token, country_code) return await self._validate_and_create_entry(access_token, country_code)
except ThinQAPIException: except ThinQAPIException as exc:
errors["base"] = "token_unauthorized" errors["base"] = THINQ_ERRORS.get(exc.code, "token_unauthorized")
_LOGGER.error("Failed to validate access_token %s", exc)
return self.async_show_form( return self.async_show_form(
step_id="user", step_id="user",

View File

@ -77,5 +77,9 @@ async def async_setup_device_coordinator(
coordinator = DeviceDataUpdateCoordinator(hass, ha_bridge) coordinator = DeviceDataUpdateCoordinator(hass, ha_bridge)
await coordinator.async_refresh() 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 return coordinator

View File

@ -51,7 +51,7 @@ class ThinQEntity(CoordinatorEntity[DeviceDataUpdateCoordinator]):
self._attr_device_info = dr.DeviceInfo( self._attr_device_info = dr.DeviceInfo(
identifiers={(DOMAIN, coordinator.unique_id)}, identifiers={(DOMAIN, coordinator.unique_id)},
manufacturer=COMPANY, 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, name=coordinator.device_name,
) )
self._attr_unique_id = f"{coordinator.unique_id}_{self.property_id}" self._attr_unique_id = f"{coordinator.unique_id}_{self.property_id}"

View File

@ -167,7 +167,6 @@ class ThinQMQTT:
async def async_handle_device_event(self, message: dict) -> None: async def async_handle_device_event(self, message: dict) -> None:
"""Handle received mqtt message.""" """Handle received mqtt message."""
_LOGGER.debug("async_handle_device_event: message=%s", message)
unique_id = ( unique_id = (
f"{message["deviceId"]}_{list(message["report"].keys())[0]}" f"{message["deviceId"]}_{list(message["report"].keys())[0]}"
if message["deviceType"] == DeviceType.WASHTOWER if message["deviceType"] == DeviceType.WASHTOWER
@ -178,6 +177,12 @@ class ThinQMQTT:
_LOGGER.error("Failed to handle device event: No device") _LOGGER.error("Failed to handle device event: No device")
return 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") push_type = message.get("pushType")
if push_type == DEVICE_STATUS_MESSAGE: if push_type == DEVICE_STATUS_MESSAGE:

View File

@ -5,6 +5,12 @@
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]" "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]"
}, },
"error": { "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." "token_unauthorized": "The token is invalid or unauthorized."
}, },
"step": { "step": {

View File

@ -50,7 +50,7 @@ async def test_config_flow_invalid_pat(
data={CONF_ACCESS_TOKEN: MOCK_PAT, CONF_COUNTRY: MOCK_COUNTRY}, data={CONF_ACCESS_TOKEN: MOCK_PAT, CONF_COUNTRY: MOCK_COUNTRY},
) )
assert result["type"] is FlowResultType.FORM 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() mock_invalid_thinq_api.async_get_device_list.assert_called_once()