dlink_hnap
dlink_hnap copied to clipboard
Add device_info and unique_id
Device information should now be shown under Configuration -> Devices. As unique_id
is set, it should also be possible to edit the entity in the UI, e.g. change name.
It doesn't seem to be working:
2020-07-28 12:59:51 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 134, in async_update
last_trigger = await self._sensor.latest_trigger()
File "/config/custom_components/dlink_hnap/dlink.py", line 202, in latest_trigger
if "GetLatestDetection" in self.client.actions:
TypeError: argument of type 'NoneType' is not iterable
2020-07-28 12:59:51 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 134, in async_update
last_trigger = await self._sensor.latest_trigger()
File "/config/custom_components/dlink_hnap/dlink.py", line 202, in latest_trigger
if "GetLatestDetection" in self.client.actions:
TypeError: argument of type 'NoneType' is not iterable
2020-07-28 12:59:51 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update water sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 163, in async_update
water_detected = await self._sensor.water_detected()
File "/config/custom_components/dlink_hnap/dlink.py", line 231, in water_detected
if not self._soap_actions:
AttributeError: 'WaterSensor' object has no attribute '_soap_actions'
2020-07-28 12:59:51 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up dlink_hnap platform for binary_sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 187, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 330, in _async_add_entity
if entity.unique_id is not None:
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 106, in unique_id
return self._sensor.mac
File "/config/custom_components/dlink_hnap/dlink.py", line 194, in mac
return self._settings.get("DeviceMacId")
AttributeError: 'coroutine' object has no attribute 'get'
2020-07-28 12:59:56 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update water sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 163, in async_update
water_detected = await self._sensor.water_detected()
File "/config/custom_components/dlink_hnap/dlink.py", line 231, in water_detected
if not self._soap_actions:
AttributeError: 'WaterSensor' object has no attribute '_soap_actions'
2020-07-28 13:00:01 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update water sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 163, in async_update
water_detected = await self._sensor.water_detected()
File "/config/custom_components/dlink_hnap/dlink.py", line 231, in water_detected
if not self._soap_actions:
AttributeError: 'WaterSensor' object has no attribute '_soap_actions'
2020-07-28 13:00:06 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update water sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 163, in async_update
water_detected = await self._sensor.water_detected()
File "/config/custom_components/dlink_hnap/dlink.py", line 231, in water_detected
if not self._soap_actions:
AttributeError: 'WaterSensor' object has no attribute '_soap_actions'
New update pushed, hopefully fixes the issues! 🤞
New update pushed, hopefully fixes the issues! 🤞
There are still some issues :/:
2020-07-28 21:29:49 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')]) 2020-07-28 21:29:49 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor Traceback (most recent call last): File "/config/custom_components/dlink_hnap/binary_sensor.py", line 134, in async_update last_trigger = await self._sensor.latest_trigger() File "/config/custom_components/dlink_hnap/dlink.py", line 212, in latest_trigger log_list = resp["MotionDetectorLogList"] KeyError: 'MotionDetectorLogList' 2020-07-28 21:29:49 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')]) 2020-07-28 21:29:49 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor Traceback (most recent call last): File "/config/custom_components/dlink_hnap/binary_sensor.py", line 134, in async_update last_trigger = await self._sensor.latest_trigger() File "/config/custom_components/dlink_hnap/dlink.py", line 212, in latest_trigger log_list = resp["MotionDetectorLogList"] KeyError: 'MotionDetectorLogList'
It also says fo the sensors in UI :/
'This entity does not have a unique ID, therefore its settings cannot be managed from the UI.'
same result for me
It was a stupid asyncio mistake (didn't await
properly). Should be fixed now! Ran pylint on the code a fixed quite a few issues here and there, hope it works better now!
I believe that the ui saying it does not have unique id is a direct consequence of the error above.
I'm still getting: 'This entity does not have a unique ID, therefore its settings cannot be managed from the UI.'
It was a stupid asyncio mistake (didn't
await
properly). Should be fixed now! Ran pylint on the code a fixed quite a few issues here and there, hope it works better now!I believe that the ui saying it does not have unique id is a direct consequence of the error above.
I'm afraid there is still some issue left :/:
2020-07-28 22:52:39 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')])
NoneType: None
2020-07-28 22:52:39 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 128, in async_update
last_trigger = await self._sensor.latest_trigger()
File "/config/custom_components/dlink_hnap/dlink.py", line 206, in latest_trigger
log_list = resp["MotionDetectorLogList"]
KeyError: 'MotionDetectorLogList'
2020-07-28 22:52:39 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')])
NoneType: None
2020-07-28 22:52:39 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 128, in async_update
last_trigger = await self._sensor.latest_trigger()
File "/config/custom_components/dlink_hnap/dlink.py", line 206, in latest_trigger
log_list = resp["MotionDetectorLogList"]
KeyError: 'MotionDetectorLogList'
2020-07-28 22:52:43 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')])
NoneType: None
2020-07-28 22:52:43 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
File "/config/custom_components/dlink_hnap/binary_sensor.py", line 128, in async_update
last_trigger = await self._sensor.latest_trigger()
File "/config/custom_components/dlink_hnap/dlink.py", line 206, in latest_trigger
log_list = resp["MotionDetectorLogList"]
KeyError: 'MotionDetectorLogList'
So, the problem is this. Which "function" that is ought to be used to figure out latest motion, depends on the firmware version. D-link changed it at some point. I fetch the list of all supported functions and look for "the new" one and use that if available, otherwise fall back to the old method. For some reason that list doesn't seem to be fetched correctly/at all/when it should, so defection falls back to the old function which your device (with newer firmware) does not support. I don't really understand why, but I have tried to revert the behavior a bit. Can you try the latest version?
Still no unique id
Now I have resurrected an old sensor so that I can actually try the code myself... Latest push now works with unique_id
, but I guess I need to use config entries in order to use the device registry. I will look into that. It should pave the way to support config flow and discovery in a simple way too.
The work you're doing is sincerely appreciated
Now I have resurrected an old sensor so that I can actually try the code myself... Latest push now works with
unique_id
, but I guess I need to use config entries in order to use the device registry. I will look into that. It should pave the way to support config flow and discovery in a simple way too.
There are some improvements so the sensors have setting now, however, the sensors don't update anymore:
2020-07-31 19:05:53 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')]) NoneType: None 2020-07-31 19:05:53 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor Traceback (most recent call last): File "/config/custom_components/dlink_hnap/binary_sensor.py", line 130, in async_update last_trigger = await self._sensor.latest_trigger() File "/config/custom_components/dlink_hnap/dlink.py", line 210, in latest_trigger log_list = resp["MotionDetectorLogList"] KeyError: 'MotionDetectorLogList' 2020-07-31 19:05:53 ERROR (MainThread) [custom_components.dlink_hnap.dlink] log list: OrderedDict([('@xmlns', 'http://purenetworks.com/HNAP1/'), ('GetMotionDetectorLogsResult', 'ERROR')]) NoneType: None 2020-07-31 19:05:53 ERROR (MainThread) [custom_components.dlink_hnap.binary_sensor] failed to update motion sensor Traceback (most recent call last): File "/config/custom_components/dlink_hnap/binary_sensor.py", line 130, in async_update last_trigger = await self._sensor.latest_trigger() File "/config/custom_components/dlink_hnap/dlink.py", line 210, in latest_trigger log_list = resp["MotionDetectorLogList"] KeyError: 'MotionDetectorLogList'