Thank you sir. I follow your suggestions I install Home Assistant development environment on Windows then debug the integration,but the result also different with hassos.
In order to confirm the problem I add some debug information. At the same time, I changed post to asynchronous request. The code is following:
async def async_get_baseinf(self):
_LOGGER.debug("async_get_baseinf runing")
ret = True
base_url_headers = self.commonHeaders()
base_url_params = {
"openid": self._openid,
"timestamp": self._time_stamp,
"noncestr": self._noncestr,
"sign": self._sign,
"unionid": self._unionid,
"userInfo": 'null'
}
_LOGGER.debug(f"{base_url_params}")
resp = await self._session.post(
BASE_API_URL, params=base_url_params, headers=base_url_headers, timeout=200
)
_LOGGER.debug(resp.url)
_LOGGER.debug(resp.status)
return ret
Test result:
devcontainer:
2022-11-21 16:39:06.979 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] async_get_baseinf runing
2022-11-21 16:39:06.980 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] {‘openid’: ‘olmSdjqd2XxpgBdfojReFrccPnY0’, ‘timestamp’: ‘1665300701’, ‘noncestr’: ‘38b3eff8baf56627478ec76a704e9b52’, ‘sign’: ‘3afd7eb882840837b0422a736990374dfc39fc80’, ‘unionid’: ‘oEa171AhIMfwxgYeR2XIJ59FqlFg’, ‘userInfo’: ‘null’}
2022-11-21 16:39:07.018 DEBUG (SyncWorker_0) [asyncio] Get address info weixin.js.sgcc.com.cn:443, type=<SocketKind.SOCK_STREAM: 1>, flags=<AddressInfo.AI_ADDRCONFIG: 32>
2022-11-21 16:39:07.079 DEBUG (SyncWorker_0) [asyncio] Getting address info weixin.js.sgcc.com.cn:443, type=<SocketKind.SOCK_STREAM: 1>, flags=<AddressInfo.AI_ADDRCONFIG: 32> took 60.463ms: [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, ‘’, (‘218.94.127.86’, 443))]
2022-11-21 16:39:07.100 DEBUG (MainThread) [asyncio] <asyncio.sslproto.SSLProtocol object at 0x7f8dcd66d7f0> starts SSL handshake
2022-11-21 16:39:07.126 DEBUG (MainThread) [asyncio] <asyncio.sslproto.SSLProtocol object at 0x7f8dcd66d7f0>: SSL handshake took 25.4 ms
2022-11-21 16:39:07.128 DEBUG (MainThread) [asyncio] <asyncio.TransportSocket fd=17, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=(‘172.17.0.2’, 57862), raddr=(‘218.94.127.86’, 443)> connected to 218.94.127.86:443: (<asyncio.sslproto._SSLProtocolTransport object at 0x7f8db1968c40>, <aiohttp.client_proto.ResponseHandler object at 0x7f8db2cc0100>)
2022-11-21 16:39:07.150 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] https://weixin.js.sgcc.com.cn/wx … g&userInfo=null
2022-11-21 16:39:07.151 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] 200
2022-11-21 16:39:07.159 DEBUG (MainThread) [custom_components.js_sgcc_energy] Finished fetching js_sgcc_energy data in 0.182 seconds (success: True)
2022-11-21 16:39:07.160 DEBUG (MainThread) [custom_components.js_sgcc_energy] Successful to update data, now loading entities
HASSOS:
2022-11-22 00:35:22.303 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] async_get_baseinf runing
2022-11-22 00:35:22.304 DEBUG (MainThread) [custom_components.js_sgcc_energy.jsdw] {‘openid’: ‘olmSdjqd2XxpgBdfojReFrccPnY0’, ‘timestamp’: ‘1665300701’, ‘noncestr’: ‘38b3eff8baf56627478ec76a704e9b52’, ‘sign’: ‘3afd7eb882840837b0422a736990374dfc39fc80’, ‘unionid’: ‘oEa171AhIMfwxgYeR2XIJ59FqlFg’, ‘userInfo’: ‘null’}
2022-11-22 00:35:28.232 ERROR (MainThread) [custom_components.js_sgcc_energy] Error fetching js_sgcc_energy data: Failed to data update with unknown reason
2022-11-22 00:35:28.235 DEBUG (MainThread) [custom_components.js_sgcc_energy] Finished fetching js_sgcc_energy data in 5.932 seconds (success: False)
Testing environment:
1、windows+visual_studio_code+devcontainer
2、Hassos+Raspbarry Pi
I don’t know why,This problem has troubled me for a long time,please tell me how to do next?
why the code
resp = await self._session.post(
BASE_API_URL, params=base_url_params, headers=base_url_headers, timeout=200
)
next two debug statements no reply?
_LOGGER.debug(resp.url)
_LOGGER.debug(resp.status)
Thank you very mach!