File: dashcast_blocking.py

package info (click to toggle)
pychromecast 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 332 kB
  • sloc: python: 1,751; makefile: 6; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,295 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
47
48
49
50
51
52
53
54
55
56
"""
Example that shows how the DashCast controller can be used.

Functions called in this example are blocking which means that
the function doesn't return as long as no result was received.
"""
import time
import sys
import logging

import pychromecast
import pychromecast.controllers.dashcast as dashcast

debug = '--show-debug' in sys.argv
if debug:
    logging.basicConfig(level=logging.DEBUG)

casts = pychromecast.get_chromecasts()
if len(casts) == 0:
    print("No Devices Found")
    exit()

cast = casts[0]

d = dashcast.DashCastController()
cast.register_handler(d)

print()
print(cast.device)
time.sleep(1)
print()
print(cast.status)
print()
print(cast.media_controller.status)
print()

if not cast.is_idle:
    print("Killing current running app")
    cast.quit_app()
    time.sleep(5)

time.sleep(1)

# Test that the callback chain works. This should send a message to
# load the first url, but immediately after send a message load the
# second url.
warning_message = 'If you see this on your TV then something is broken'
d.load_url('https://home-assistant.io/? ' + warning_message,
           callback_function=lambda result:
           d.load_url('https://home-assistant.io/'))


# If debugging sleep after running so we can see any error messages.
if debug:
    time.sleep(10)