dbuezas / icsee-ptz

61 stars 10 forks source link

Hangs after some time #20

Open slydiman opened 1 year ago

slydiman commented 1 year ago

HA 2023.9.3 ICSee-PTZ 4.0.2

I faced 2 issues:

  1. After restarting HA or ICSee-PTZ integration the state of binary_sensor.some_cam_motion_alarm is unknown until the camera report the new state. It's inconvenient. Note some cards do not show any data or graphs while the state is unknown.

It would be great to request the current state at startup.

  1. After few hours something went wrong due to a leak in the camera or integration. self.socket_recv(20) in asyncio_dvrip.py, line 193 returned 0 bytes array (not None) for any request including KeepAlive. binary_sensor.some_cam_motion_alarm and all ptz service calls stopped working. I see the following exception in HA logs:
    File "/config/custom_components/icsee_ptz/camera.py", line 64, in async_ensure_alive
    await dvrip_alarm.alarmStart(self.hass.loop)
    File "/config/custom_components/icsee_ptz/asyncio_dvrip.py", line 412, in alarmStart
    return await self.get_command("", self.QCODES["AlarmSet"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/config/custom_components/icsee_ptz/asyncio_dvrip.py", line 537, in get_command
    if data["Ret"] in self.OK_CODES and command in data:
       ~~~~^^^^^^^
    TypeError: 'NoneType' object is not subscriptable

    It is necessary to reload the integration ICSee-PTZ manually to resume work. Note I have 15 differrent XM cameras. I see this issue with 4 cameras: XM530 50X20-WGH, model id 0003067f, firmware date 2020-10-10 XM530 RF50X30_8M, model id 00030746, firmware date 2020-12-07 or 2021-07-20 I don't see such issue with RA50X20 camaras and few DVRs.

It would be great to fix a leak or at least reload/reconnect everything if socket_recv(20) returned b'' (0 bytes array).

slydiman commented 1 year ago

For now I have configured an automation to reload the integration ICSee each hour

- alias: ICSee Reload
  initial_state: true
  trigger:
  - platform: time_pattern
    hours: "/1"
  action:
  - service: homeassistant.reload_config_entry
    data:
      entry_id: 061169e2669d6c74fa3fab0e8830e1ff # config entry for cam1
  - service: homeassistant.reload_config_entry
    data:
      entry_id: da158ca7acb9975b4a0221e0e08b1de2 # config entry for cam2
# etc.

but I see the state unknown each hour until a movement.