FalkTannhaeuser / python-onvif-zeep

ONVIF Client Implementation in Python 2+3 (using https://github.com/mvantellingen/python-zeep instead of suds as SOAP client)
MIT License
424 stars 138 forks source link

Support async zeep / allow services transport override #43

Closed GeertvanHorrik closed 5 years ago

GeertvanHorrik commented 5 years ago

It looks like this lib doesn't support async out of the box. Whenever I define a custom transport:

loop = asyncio.get_event_loop()
transport = AsyncTransport(loop, cache=None)

self._camera = ONVIFCamera(self._host,
                           self._port,
                           self._username,
                           self._password,
                           '{}/wsdl/'
                           .format(os.path.dirname(onvif.__file__)),
                           transport=transport)

I get an error:

  File "/config/custom_components/onvif/camera.py", line 155, in __init__
    transport=transport)
  File "/config/deps/lib/python3.7/site-packages/onvif/client.py", line 216, in __init__
    self.update_xaddrs()
  File "/config/deps/lib/python3.7/site-packages/onvif/client.py", line 234, in update_xaddrs
    for name in capabilities:
TypeError: 'coroutine' object is not iterable

There are a few things that could be done here:

  1. Always check whether a service call is async or not (lots of work)
  2. Allow transport override for the services (in create_onvif_service, see https://github.com/FalkTannhaeuser/python-onvif-zeep/blob/zeep/onvif/client.py#L308)

In the 2nd case, it can be kept simple because you can keep "force-using" the sync stuff on the internals (e.g. to get the attributes, etc), but end-users could decide to override the transport for custom created services and use this library async.

If you are open to this, and you are able to deploy this in a timely manner, I am happy to contribute.