Bug: 自动刷新登陆后,API返回“没有绑定户号”
CubicPill opened this issue · comments
GBP commented
抛出异常如下:
2022-11-20 01:41:33.568 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up china_southern_power_grid_stat platform for sensor
Traceback (most recent call last):
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/sensor.py", line 443, in _async_update_data
return await self.hass.async_add_executor_job(csg_fetch_all)
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/sensor.py", line 361, in csg_fetch_all
bal, arr = client.get_balance_and_arrears(account)
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/csg_client/__init__.py", line 557, in get_balance_and_arrears
resp_data = self.api_query_account_surplus(
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/csg_client/__init__.py", line 393, in api_query_account_surplus
self._handle_unsuccessful_response(resp_data)
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/csg_client/__init__.py", line 262, in _handle_unsuccessful_response
raise CSGAPIError(response_data["sta"], response_data.get("message"))
custom_components.china_southern_power_grid_stat.csg_client.CSGAPIError: <CSGAPIError sta=0500 message=没有绑定户号!>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pill/core/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
self.data = await self._async_update_data()
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/sensor.py", line 449, in _async_update_data
raise UpdateFailed(f"Error communicating with API: {err}") from err
homeassistant.helpers.update_coordinator.UpdateFailed: Error communicating with API: <CSGAPIError sta=0500 message=没有绑定户号!>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pill/core/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
await asyncio.shield(task)
File "/home/pill/core/config/custom_components/china_southern_power_grid_stat/sensor.py", line 137, in async_setup_entry
await coordinator.async_config_entry_first_refresh()
File "/home/pill/core/homeassistant/helpers/update_coordinator.py", line 178, in async_config_entry_first_refresh
raise ex
homeassistant.exceptions.ConfigEntryNotReady: Error communicating with API: <CSGAPIError sta=0500 message=没有绑定户号!>
原因:刷新登录态后,绑定缴费号的bindingId
也会随之改变,导致上述错误
修复方法:刷新登录态时同时刷新账户信息,并更新到配置中