Aohzan / ipx800

IPX800 V4 integration for Home-Assistant
Apache License 2.0
20 stars 12 forks source link

error in my log #47

Open xmeslin opened 5 months ago

xmeslin commented 5 months ago

Hello,

I have the last version: Describe the bug it seems to work but for some reasons I have plenty of error in my log. In option I have : Enable newly added entities. : DISABLE Enable polling for updates : ENABLE

Configuration

ipx800v4:
  - name: IPX800
    host: 192.168.0.39
    api_key: xxx
    devices:
      - name: Portail_State
        type: "digitalin"
        component: "binary_sensor"
        id: 4
      - name: Portail_Action
        type: relay
        component: switch
        id: 3

Debug logs

2024-02-03 19:19:41.628 ERROR (MainThread) [custom_components.ipx800v4] Unexpected error fetching ipx800v4 data: IPX800 API request error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ipx800v4/__init__.py", line 166, in async_update_data
    return await ipx.global_get()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pypx800/ipx800.py", line 139, in global_get
    values = await self.request_api({"Get": "all"})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pypx800/ipx800.py", line 78, in request_api
    raise Ipx800RequestError("IPX800 API request error")
pypx800.exceptions.Ipx800RequestError: IPX800 API request error
2024-02-03 19:21:41.257 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 243, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 399, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 182, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 479, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1066, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1003, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 300, in state
    if (is_on := self.is_on) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/ipx800v4/binary_sensor.py", line 61, in is_on
    return self.coordinator.data[f"D{self._id}"] == 1
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'D4'
Aohzan commented 5 months ago

Hello The IPX doesn't return the state of the digital in 4. Can you send the result of the api please

xmeslin commented 5 months ago

You need that ?

http://192.168.0.39/api/xdevices.json?key=apikey&Get=All

{ "product": "IPX800_V4", "status": "Success", "A1": 0, "A2": 0, "A3": 0, "A4": 0 }

xmeslin commented 5 months ago

I got that also sometimes: { "product": "IPX800_V4", "status": "Success", "A1": 0, "A2": 0, "A3": 0, "status": "Error" }

Aohzan commented 5 months ago

It's really weird, you should have the state of all input/output, you just have Analog In Can you try to update/reboot the ipx ?

xmeslin commented 5 months ago

I already did. However it works. I means I have the state correctly reported to HA (after teh configure timer) when the state change on IPX. just sometimes I have unavailable in the state Screenshot 2024-02-05 at 9 12 00 AM

Not sure it is related but I'm struggling with the push from ipx to HA to change state "real time". I'll tshoot that later

Aohzan commented 5 months ago

It's not related to push The IPX800 doesn't return all entities state everytime, there is a problem with it, you should open a ticket to GCE

xmeslin commented 5 months ago

actually I now have all state. it is all and not All in api call. It seems to be case sensitive http://192.168.0.39/api/xdevices.json?key=apikey&Get=all

Aohzan commented 5 months ago

yes indeed how many times between 2 update? do you query the ipx from jeedom in the same time (or an other tool)

xmeslin commented 5 months ago

I have 5s between 2 updates. I have jeedom but I desactivated the device to be sure it doesn't conflict and still not unavailable. when I manual try the api I have time to time:

{ "product": "IPX800_V4", "status": "Success", "D1": 0, "D2": 1, "D3": 0, "D4": 1, "D5": 0, "D6": 0, "D7": 0, "D8": 1, "D9": 0, "D10": 0, "D11": 0, "D12": 0, "D13": 0, "D14": 0, "D15": 0, "D16": 0, "D17": 0, "D18": 0, "D19": 0, "D20": 0, "D21": 0, "D22": 0, "D23": 0, "D24": 0, "D25": 0, "D26": 0, "D27": 0, "D28": 0, "D29": 0, "D30": 0, "D31": 0, "D32": 0, "D33": 0, "D34": 0, "D35": 0, "D36": 0, "D37": 0, "D38": 0, "D39": 0, "D40": 0, "D41": 0, "D42": 0, "D43": 0, "D44": 0, "status": "Error" } and sometime very rarely I have non digital information even if I asked for D. definitely the IPX800 API is not rock solid

Aohzan commented 5 months ago

yes but if you query your ipx too much, sometimes it returns partial answer

sebastienwarin commented 4 months ago

Hi there,

I had the same problem when querying the IPX too often. To get around this, I implement "bulk update" to get the states of my IPX entities in "real time" as soon as they change on the IPX and without having to query the IPX.

It works great with Relay, DigitalIn, VirtualDigitalIn and VirtualDigitalOut (successfully tested) but I think it should work with the rest, including AnalogIn (but I couldn't test).

See the PR #50 for more information

Best