rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
383 stars 74 forks source link

XVR5216AN doesnt support lighting but 'Device supports infrared lighting=True' #267

Open si458 opened 1 year ago

si458 commented 1 year ago

when i add in my XVR5216AN (its an 16 channel BNC unit so no lighting is supported), its saying lighting is supported yet when i access the url http://192.168.52.123/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0] i clearly get a 400 error back but its showing in the logs 2023-04-09 17:17:30.107 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True any suggestions?

2023-04-09 17:17:14.264 WARNING (SyncWorker_2) [homeassistant.loader] We found a custom integration dahua which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-04-09 17:17:22.589 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 2: {'onboarding', 'energy', 'input_select', 'timer', 'diagnostics', 'auth', 'input_datetime', 'ipp', 'sun', 'config', 'logbook', 'met', 'automation', 'input_boolean', 'tag', 'tts', 'application_credentials', 'counter', 'stream', 'file_upload', 'hacs', 'repairs', 'my', 'map', 'dahua', 'system_health', 'blueprint', 'analytics', 'search', 'history', 'mqtt', 'media_source', 'input_number', 'scene', 'ffmpeg', 'schedule', 'conversation', 'radio_browser', 'mobile_app', 'homeassistant_alerts', 'frigate', 'input_button', 'hardware', 'sensor', 'default_config', 'trace', 'device_automation', 'person', 'auto_backup', 'zone', 'image_upload', 'lovelace', 'input_text', 'persistent_notification', 'script'}
2023-04-09 17:17:22.622 INFO (MainThread) [homeassistant.setup] Setting up dahua
2023-04-09 17:17:22.622 INFO (MainThread) [homeassistant.setup] Setup of domain dahua took 0.0 seconds
2023-04-09 17:17:25.558 INFO (MainThread) [custom_components.dahua] Using channel number 1
2023-04-09 17:17:26.944 INFO (MainThread) [custom_components.dahua] Using max streams 3
2023-04-09 17:17:28.777 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2023-04-09 17:17:28.866 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=True
2023-04-09 17:17:29.480 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=True
2023-04-09 17:17:29.480 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2023-04-09 17:17:29.480 INFO (MainThread) [custom_components.dahua] Device is an Amcrest floodlight=False
2023-04-09 17:17:30.107 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.52.123:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0]
2023-04-09 17:17:30.107 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
2023-04-09 17:17:30.109 INFO (Thread-2) [custom_components.dahua] Starting DahuaEventThread
2023-04-09 17:17:30.746 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.52.123:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][2]
2023-04-09 17:17:30.747 INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
2023-04-09 17:17:30.916 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.52.123:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0]
2023-04-09 17:17:31.463 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 8.643 seconds (success: True)
2023-04-09 17:17:31.467 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.dahua
2023-04-09 17:17:31.470 INFO (MainThread) [homeassistant.components.camera] Setting up camera.dahua
2023-04-09 17:18:01.483 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.52.123:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0]
si458 commented 1 year ago

im still having this issue @rroller any suggestions?

si458 commented 1 year ago

ive been able to find out the issue but im not sure how to fix it as im not an experienced python developer

STEP1: https://github.com/rroller/dahua/blob/321a576e5fee81de122c440ad28d806b519e35cc/custom_components/dahua/__init__.py#L259-L265 STEP2: https://github.com/rroller/dahua/blob/321a576e5fee81de122c440ad28d806b519e35cc/custom_components/dahua/client.py#L204-L223 STEP3: https://github.com/rroller/dahua/blob/321a576e5fee81de122c440ad28d806b519e35cc/custom_components/dahua/client.py#L195-L202

STEP 3 is returning an empty {} as expected because of the returned 400 but then in STEP2 its just returning the empty {} rather than catching the error to check if its a 400 then returning to STEP1 with empty {} rather than again catching the error