def __init__(self, config=None): cec.init() device_list = cec.list_devices() self.roku_dev = None for dev in device_list: print(device_list[dev].osd_string) if device_list[dev].osd_string == 'Roku' and 'rokuName' in config: print("Finding address for Roku %s" % config['rokuName']) all_devices = RokuDevice.RokuDevices() try: self.roku_dev = all_devices.get_device(config['rokuName']) except: print("Did not find Roku Device %s" % config['rokuName']) self.television = None if 0 in device_list: self.television = {"address": "0", "powerState": "standby"} self.receiver = None if 5 in device_list: self.receiver = { "address": "5", "powerState": "standby", "mute": False, "volume": None } self.acquire_all_status()
def __init__(self): cec.init() self.devices = cec.list_devices() self.rec_controller = ReceiverController(self.devices) self.tv_controller = TvController(self.devices[0], self.rec_controller) self.player_callback = None cec.add_callback(self.__event_callback, cec.EVENT_COMMAND) cec.add_callback(log_cb, cec.EVENT_LOG)
def init_cec(self): """Method to init cec adapter. Return True if cec initiated successfully""" if (self.initiated): return adapter = cec.list_adapters() if len(adapter) >= 1: try: cec.init() self.adapter = adapter.pop() self.devices = cec.list_devices() self.initiated = True cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG) cec.add_callback(log_cb, cec.EVENT_LOG) except: self.initiated = False
def init_cec(self): """Method to init cec adapter. Return True if cec initiated successfully""" if self.initiated: return adapter = cec.list_adapters() if len(adapter) >= 1: try: cec.init() self.adapter = adapter.pop() self.devices = cec.list_devices() self.initiated = True cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG) cec.add_callback(log_cb, cec.EVENT_LOG) except: self.initiated = False
receiver = cec.Device(config['cec_output']) if request.path == "/vol_up": cec.volume_up() elif request.path == "/vol_down": cec.volume_down() elif request.path == "/power_on": receiver.power_on() elif request.path == "/power_off": receiver.standby() elif request.prepath[0] == "input": receiver.set_av_input(int(request.postpath[0])) else: response_data = "unknown command" request.setResponseCode(404) request.responseHeaders.addRawHeader(b"content-type", b"text/plain") return response_data if __name__ == '__main__': log.startLogging(sys.stdout) cec.init() cec.list_devices() # necessary for volume to work reactor.connectTCP(config['lms_server'], config['lms_port'], LMSClientFactory()) root = resource.Resource() root.putChild("vol_up", Simple()) root.putChild("vol_down", Simple()) root.putChild("power_on", Simple()) root.putChild("power_off", Simple()) root.putChild("input", Simple()) site = server.Site(root) reactor.listenTCP(8080, site) reactor.run()
import time import cec adapters = cec.list_adapters() test_power = False print adapters if len(adapters) > 0: adapter = adapters[0] print "Using Adapter %s" % (adapter) cec.init(adapter) print "Devices:", cec.list_devices() d = cec.Device(0) # print fields print "Address:", d.address print "Physical Address:", d.physical_address print "Vendor ID:", d.vendor print "OSD:", d.osd_string print "CEC Version:", d.cec_version print "Language:", d.language # call functions print "ON:", d.is_on() if test_power:
) args = parser.parse_args() if args.setup: if os.geteuid() == 0: # we have root/sudo pass else: print( f"To set up, please run as root:\n sudo ./{sys.argv[0].split('/')[-1]} --setup" ) print("Getting CEC Devices") cec.init() cec_devs = [] all_devs = cec.list_devices() [print(i, all_devs[i].osd_string) for i in all_devs] cec_dev = input( "Select a CEC Device to control (don't select Chromecast here): ") while True: try: if int(cec_dev) in all_devs: break except ValueError: pass cec_dev = input("Type the number of a listed device: ") #TODO - allow multi devices cec_devs.append(cec_dev) print("\nGetting Chromecasts on network") chromecasts = pychromecast.get_chromecasts()
import time import cec adapters = cec.list_adapters() test_power = False print adapters if len(adapters) > 0: adapter = adapters[0] print "Using Adapter %s"%(adapter) cec.init(adapter) print "Devices:", cec.list_devices() d = cec.Device(0) # print fields print "Address:", d.address print "Physical Address:", d.physical_address print "Vendor ID:", d.vendor print "OSD:", d.osd_string print "CEC Version:", d.cec_version print "Language:", d.language # call functions print "ON:", d.is_on() if test_power:
app.register_blueprint(swaggerui_blueprint) # try to import and use CEC if its installed use_cec = True try: import cec logging.info("using cec") except ModuleNotFoundError: print("cec not found, not using") use_cec = False if use_cec: cec.init() cec_devices = cec.list_devices() logging.info(f"found {cec_devices}") CEC_SEQUENCES = { # chromecast concatenates the device name "Living Room T": SEQUENCES["chromecast"], "NintendoSwitch": SEQUENCES["switch"], } # callback for HDMI-CEC def cec_cb(*args): if len(args) != 2: return # only respond to the right command source = args[0]