You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On occasion a camera doesn't respond with all the expected values. Ideally the code should check for unexpected values and handle them gracefully.
On several occasions I've seen a perfectly operating camera not being able to initialize in Home Assistant with this index out of range error. I've seen reports from others that have experienced this as well - such as: home-assistant/core#30216
I've tracked this problem down to the async_get_day_night_color call expecting VideoInOptions[0].DayNightColor=n to be returned in the response. When it is inexplicably missing, the following error results:
2023-02-12 16:18:35.484 ERROR (MainThread) [homeassistant.components.camera] amcrest: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 739, in async_device_update
await task
File "/usr/src/homeassistant/homeassistant/components/amcrest/camera.py", line 411, in async_update
) = await asyncio.gather(
File "/usr/src/homeassistant/homeassistant/components/amcrest/camera.py", line 641, in _async_get_color_mode
return _CBW[await self._api.async_day_night_color]
File "/usr/local/lib/python3.10/site-packages/amcrest/video.py", line 261, in async_day_night_color
return await self.async_get_day_night_color(channel=0)
File "/usr/local/lib/python3.10/site-packages/amcrest/video.py", line 285, in async_get_day_night_color
return values[channel]
IndexError: list index out of range
This is the video.py code section that throws this error when the result is undefined:
async def async_get_day_night_color(self, channel: int) -> int:
"""
Return Day & Night Color Mode for Day profile.
Result is 0: always multicolor
1: autoswitch along with brightness
2: always monochrome
"""
values = [
int(x) for x in await self.async_video_in_option("DayNightColor")
]
return values[channel]
I have no idea why the camera will sometimes not respond with the full expected VideoInOptions API payload. What I typically do to fix this is to reset the firmware to defaults and set it all back up again. So while maybe it can be argued that this is not a bug in the code when the camera API is misbehaving, there really should be a value/range check with a default value created and warning that allows the camera to continue to be set up.
For reference, here is the full response received from the /cgi-bin/configManager.cgi?action=getConfig&name=VideoInOptions command when this error occurs:
UPDATE: Overnight a perfectly working different camera suddenly failed with this exact error. 2858 times and counting! It had the exact same reduced response to the VideoInOptions payload as above.
Logger: homeassistant.helpers.entity
Source: components/amcrest/camera.py:641
First occurred: February 15, 2023 at 8:36:23 PM (2858 occurrences)
Last logged: 8:31:59 AM
Update for camera.frontdrive failed
Problem still occurring with 2 Dahua IPC-T5442T-ZE cameras updated with latest firmware.
Only resolution (other than a software update) is to reset camera to factory defaults and restore a config backup that gets it 90% reconfigured properly.
On occasion a camera doesn't respond with all the expected values. Ideally the code should check for unexpected values and handle them gracefully.
On several occasions I've seen a perfectly operating camera not being able to initialize in Home Assistant with this index out of range error. I've seen reports from others that have experienced this as well - such as: home-assistant/core#30216
I've tracked this problem down to the async_get_day_night_color call expecting VideoInOptions[0].DayNightColor=n to be returned in the response. When it is inexplicably missing, the following error results:
This is the video.py code section that throws this error when the result is undefined:
I have no idea why the camera will sometimes not respond with the full expected VideoInOptions API payload. What I typically do to fix this is to reset the firmware to defaults and set it all back up again. So while maybe it can be argued that this is not a bug in the code when the camera API is misbehaving, there really should be a value/range check with a default value created and warning that allows the camera to continue to be set up.
For reference, here is the full response received from the /cgi-bin/configManager.cgi?action=getConfig&name=VideoInOptions command when this error occurs:
The text was updated successfully, but these errors were encountered: