To communicate with custom apps on a Chromecast, you must implement a custom controller by subclassing BaseController. You define the namespace in the constructor, implement receive_message to handle incoming data, and use send_message to send data to the device. Register the controller using cast.register_handler().
from pychromecast.controllers import BaseController
class MyController(BaseController):
def __init__(self):
super(MyController, self).__init__("urn:x-cast:my.super.awesome.namespace")
def receive_message(self, message, data):
print("Wow, I received this message: {}".format(data))
return True # indicate you handled this message
def request_beer(self):
self.send_message({'request': 'beer'})
# Register the controller to a cast instance
cast.register_handler(MyController())