def on_message(client, userdata, msg): global SONY_IP global SONY_PIN # global CURRENT_POSITION tokenized_topic = str(msg.topic).split("/") type = tokenized_topic[1] element = tokenized_topic[2] command = msg.payload.decode("utf-8") logger.info("Message type:{} element:{} command:{}".format( type, element, command)) try: braviarc = BraviaRC(SONY_IP) pin = SONY_PIN braviarc.connect(pin, 'sony', 'sonyrc') if (braviarc.is_connected()): if (element == "RTV_TV_Input"): playing_content = braviarc.get_playing_info() if (command.startswith("HDMI")): source = command.replace("__", " ") source = source.replace("_", "/") braviarc.select_source(source) logger.info("sent: {}".format(source)) elif (command.startswith("NETFLIX")): braviarc.start_app("Netflix") elif (command.startswith("YOUTUBE")): braviarc.start_app("YouTube") if (element.startswith("Command_Netflix")): braviarc.start_app("Netflix") if (element.startswith("Command_YouTube")): braviarc.start_app("YouTube") if (element.startswith("Command_TV")): braviarc.select_source("HDMI 1/MHL") if (element.startswith("Command_XBOX")): braviarc.select_source("HDMI 3") if (element.startswith("Command_Confirm")): braviarc.enter() else: logger.error("TV not connected") except Exception as e: logger.info("ERR Message type:{} element:{} command:{}".format( type, element, command)) logger.error(e)
if braviarc.is_connected(): #get power status power_status = braviarc.get_power_status() print (power_status) #get playing info playing_content = braviarc.get_playing_info() #print current playing channel print (playing_content.get('title')) #get volume info volume_info = braviarc.get_volume_info() #print current volume print (volume_info.get('volume')) #change channel braviarc.play_content('https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4') #get app list app_info = braviarc.load_app_list() print (app_info) #start a given app braviarc.start_app("Kodi") #turn off the TV #braviarc.turn_off()