File: get_volume.py

package info (click to toggle)
async-upnp-client 0.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: python: 11,921; xml: 2,826; sh: 32; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Example to get the current volume from a DLNA/DMR capable TV.

Change the target variable below to point at your TV.
Use, for example, something like netdisco to discover the URL for the service.

You can run contrib/dummy_tv.py locally to emulate a TV.
"""

import asyncio
import logging

from async_upnp_client.aiohttp import AiohttpRequester
from async_upnp_client.client_factory import UpnpFactory

logging.basicConfig(level=logging.INFO)


target = "http://192.168.178.11:49152/description.xml"


async def main():
    # create the factory
    requester = AiohttpRequester()
    factory = UpnpFactory(requester)

    # create a device
    device = await factory.async_create_device(target)
    print("Device: {}".format(device))

    # get RenderingControle-service
    service = device.service("urn:schemas-upnp-org:service:RenderingControl:1")
    print("Service: {}".format(service))

    # perform GetVolume action
    get_volume = service.action("GetVolume")
    print("Action: {}".format(get_volume))
    result = await get_volume.async_call(InstanceID=0, Channel="Master")
    print("Action result: {}".format(result))


loop = asyncio.get_event_loop()
loop.run_until_complete(main())