Debian Codegraph @

examples/get_volume.py

raw
1 #!/usr/bin/env python
2
3 """
4 Example to get the current volume from a DLNA/DMR capable TV.
5
6 Change the target variable below to point at your TV.
7 Use, for example, something like netdisco to discover the URL for the service.
8
9 You can run contrib/dummy_tv.py locally to emulate a TV.
10 """
11
12 import asyncio
13 import logging
14
15 from async_upnp_client.aiohttp import AiohttpRequester
16 from async_upnp_client.client_factory import UpnpFactory
17
18 logging.basicConfig(level=logging.INFO)
19
20
21 target = "http://192.168.178.11:49152/description.xml"
22
23
24 async def main():
25 # create the factory
26 requester = AiohttpRequester()
27 factory = UpnpFactory(requester)
28
29 # create a device
30 device = await factory.async_create_device(target)
31 print("Device: {}".format(device))
32
33 # get RenderingControle-service
34 service = device.service("urn:schemas-upnp-org:service:RenderingControl:1")
35 print("Service: {}".format(service))
36
37 # perform GetVolume action
38 get_volume = service.action("GetVolume")
39 print("Action: {}".format(get_volume))
40 result = await get_volume.async_call(InstanceID=0, Channel="Master")
41 print("Action result: {}".format(result))
42
43
44 loop = asyncio.get_event_loop()
45 loop.run_until_complete(main())