rsnodgrass / hass-poolmath

Pool Math for Home Assistant
Other
30 stars 9 forks source link

Sensor(s) not being created. #18

Closed rig0 closed 2 years ago

rig0 commented 2 years ago

Fresh installation (of integration) on:

Home Assistant Core 2022.6.6 Home Assistant Supervisor 2022.05.3 Home Assistant OS 8.2

Added the following line to my configuration.yaml

sensor:
  - platform: poolmath
    url: https://api.poolmathapp.com/share/MyPOOL

Restarted HA but the sensors never get created. Tried a full device reboot as well.

Home Assistant Core logs show a hang up loading sensor platform then some errors:

2022-06-15 13:36:16 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform poolmath is taking over 10 seconds.
2022-06-15 13:36:16 ERROR (MainThread) [homeassistant.components.sensor] poolmath: Error on device update!
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 218, in connect_tcp
await event.wait()
File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1842, in wait
if await self._event.wait():
File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 218, in connect_tcp
await event.wait()
File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 658, in __aexit__
raise CancelledError
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
yield
File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "/usr/local/lib/python3.9/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
raise TimeoutError
TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
raise exc
File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
stream = await self._connect(request)
File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 111, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
File "/usr/local/lib/python3.9/site-packages/httpcore/backends/auto.py", line 29, in connect_tcp
return await self._backend.connect_tcp(
File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc)
httpcore.ConnectTimeout
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 736, in async_device_update
await task
File "/config/custom_components/poolmath/sensor.py", line 117, in async_update
soup = await client.async_update()
File "/config/custom_components/poolmath/client.py", line 34, in async_update
response = await client.request("GET", self._url, timeout=self._timeout)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectTimeout
glynweston commented 2 years ago

Hi rig0 I had the same issue today but looking back through open issues it seems it has not been working for a while. I found a solution in issue "Parsing HTML is no fun, how about json instead?" ccpk1 commented on Dec 14, 2021

I uninstalled this integration and added the sensor code ccpk1 provided. You just need to change tfp-168502 to your unique id in the line resource: "https://api.poolmathapp.com/share/**tfp-168502**.json"

rig0 commented 2 years ago

Hi glynweston,

I also ended up adopting the same solution. Currently trying to extract more data such as timestamps and notes log with that method. I uninstalled this integration and will attempt to use it again when there is a fix.

rsnodgrass commented 2 years ago

This has been resolved in 0.2.0 as it now uses the json interface for accessing data. This also adds attributes for sensors with any targets defined on Pool Math.