def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) zone_ignore = config.get(CONF_ZONE_IGNORE) if discovery_info is not None: name = discovery_info[0] model = discovery_info[1] ctrl_url = discovery_info[2] desc_url = discovery_info[3] receivers = rxv.RXV(ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.info("Receivers: %s", receivers) elif host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host) receivers = rxv.RXV(ctrl_url, name).zone_controllers() for receiver in receivers: if receiver.zone not in zone_ignore: add_devices( [YamahaDevice(name, receiver, source_ignore, source_names)])
def scan(): zones = soco.discover() print "SONOS" + "\n" + "-----" for zone in zones: transport_info = zone.get_current_transport_info() # zone.get_speaker_info().get('hardware_version') if True is True: print "{}: {}, {}, {}, {}, IP={}".format( zone.uid, zone.player_name, transport_info['current_transport_status'], transport_info['current_transport_state'], transport_info['current_transport_speed'], zone.ip_address ) print "\n" + "YAMAHA" + "\n" + "------" receivers = rxv.find() for rx in receivers: uri = urlparse(rx.ctrl_url) print "{}: {} ({})\n\t\t{}\n\t\t{}".format( uri.hostname, rx.friendly_name, rx.model_name, rx.ctrl_url, rx.basic_status)
def com_hardware_yamaha_find(): """ Discover Yamaha receivers """ receivers = rxv.find() print(receivers) return receivers
def setup_module(module): receivers = rxv.find() if not receivers: raise RuntimeError("you'll need at least one receiver on your network") module.rx = receivers[0] module.rx.on = False time.sleep(1.0)
def main(): parser = argparse.ArgumentParser( description='automatically turn the amplifier on for sonos.') parser.add_argument('--sonos', default='Living Room', help='sonso devices [Living Room]') parser.add_argument('--amplifier', default=None, help='amplifier to use [discover]') parser.add_argument('--input', default='AV5', help='amplifier input to use [AV4]') parser.add_argument('--volume', type=int, default=55, help='sonos volume to use [55]') args = parser.parse_args() amps = rxv.find() if args.amplifier is not None: lst = list(filter(lambda x: x.model_name == args.amplifier, amps)) if len(lst) != 1: print('Could not find amplifier %s' % args.amplifier, file=sys.stderr) os.exit(1) amp = lst[0] else: amp = amps[0] print('Amplifier is %s' % amp.model_name) devices = soco.discover() for device in devices: print("%21s @ %s" % (device.player_name, device.ip_address)) speaker = find_speakers(devices, args.sonos) if speaker is None: print('Could not find speaker %s' % args.sonso, file=sys.stderr) os.exit(1) print('Speaker is %s @ %s' % (speaker.player_name, speaker.ip_address)) bridge = Bridge(amp, speaker, args.input, args.volume) # set up the unified queue mq, threads = subscribe(devices) keep_running = True while keep_running: try: event = mq.get() handle_event(event, bridge) except queue.Empty: pass except KeyboardInterrupt: keep_running = False event_listener.stop()
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv source_ignore = config.get(CONF_SOURCE_IGNORE, []) source_names = config.get(CONF_SOURCE_NAMES, {}) add_devices( YamahaDevice(config.get("name"), receiver, source_ignore, source_names) for receiver in rxv.find())
async def query(user: User = Depends(get_user)): response_data = { "request_id": uuid4(), "payload": {"user_id": str(user.id), "devices": []}, } for device in rxv.find(): response_data["payload"]["devices"].append( {"id": device.ctrl_url, "capabilities": get_capabilities_with_state(device)} ) return response_data
def get_receiver(ip=None): """Look for a receiver on the local network and grab the first one we find, or exit with a useful message. """ if rxv_ip: return rxv.RXV('http://{}:80/YamahaRemoteControl/ctrl'.format(rxv_ip)) try: return rxv.find()[0] except: print("No receiver found!") sys.exit(1)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Yamaha platform.""" import rxv # keep track of configured receivers so that we don't end up # discovering a receiver dynamically that we have static config # for. if hass.data.get(KNOWN, None) is None: hass.data[KNOWN] = set() name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) zone_ignore = config.get(CONF_ZONE_IGNORE) zone_names = config.get(CONF_ZONE_NAMES) if discovery_info is not None: name = discovery_info.get('name') model = discovery_info.get('model_name') ctrl_url = discovery_info.get('control_url') desc_url = discovery_info.get('description_url') if ctrl_url in hass.data[KNOWN]: _LOGGER.info("%s already manually configured", ctrl_url) return receivers = rxv.RXV( ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.info("Receivers: %s", receivers) # when we are dynamically discovered config is empty zone_ignore = [] elif host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host) receivers = rxv.RXV(ctrl_url, name).zone_controllers() for receiver in receivers: if receiver.zone not in zone_ignore: hass.data[KNOWN].add(receiver.ctrl_url) add_devices([ YamahaDevice(name, receiver, source_ignore, source_names, zone_names) ], True)
def _discovery(config_info): """Discover receivers from configuration in the network.""" if config_info.from_discovery: receivers = rxv.RXV( config_info.ctrl_url, model_name=config_info.model, friendly_name=config_info.name, unit_desc_url=config_info.desc_url, ).zone_controllers() _LOGGER.debug("Receivers: %s", receivers) elif config_info.host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: receivers = rxv.RXV(config_info.ctrl_url, config_info.name).zone_controllers() return receivers
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv # keep track of configured receivers so that we don't end up # discovering a receiver dynamically that we have static config # for. if hass.data.get(KNOWN, None) is None: hass.data[KNOWN] = set() name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) zone_ignore = config.get(CONF_ZONE_IGNORE) if discovery_info is not None: name = discovery_info.get('name') model = discovery_info.get('model_name') ctrl_url = discovery_info.get('control_url') desc_url = discovery_info.get('description_url') if ctrl_url in hass.data[KNOWN]: _LOGGER.info("%s already manually configured", ctrl_url) return receivers = rxv.RXV( ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.info("Receivers: %s", receivers) # when we are dynamically discovered config is empty zone_ignore = [] elif host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host) receivers = rxv.RXV(ctrl_url, name).zone_controllers() for receiver in receivers: if receiver.zone not in zone_ignore: hass.data[KNOWN].add(receiver.ctrl_url) add_devices([ YamahaDevice(name, receiver, source_ignore, source_names)])
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) if host is None: receivers = rxv.find() else: receivers = \ [rxv.RXV("http://{}:80/YamahaRemoteControl/ctrl".format(host), name)] add_devices( YamahaDevice(name, receiver, source_ignore, source_names) for receiver in receivers)
def main(): # Parse arguments parser = argparse.ArgumentParser(description='Monitor chromecast activity to power on Yamaha AV receiver') parser.add_argument('--name', '-n', dest='friendly_name', metavar='<chromecast name>', type=str, required=False, help='Your chromecast name. If not set, will scan and use the first found.', default=None) args = parser.parse_args() # configure logging config.configure_logging() logger = logging.getLogger(__name__) # Get the yamaha receiver logger.info('Looking for yamaha receivers...') receivers = rxv.find(timeout=5) logger.info('Found {} yamaha receivers : {}'.format(len(receivers), receivers)) rx = receivers[0] # Run the loop monitor = Monitor(args.friendly_name, rx, YAMAHA_INPUT, YAMAHA_VOLUME) monitor.loop()
def find_receiver(): """Look for a receiver using rxv's find method. If no receiver is found, print an appropriate error, otherwise return the first (if multiple are found) receiver """ receiver = None print("Looking for receivers...") found_receivers = rxv.find() if len(found_receivers) > 1: print("Found multiple receivers, choosing the first one.") receiver = found_receivers[0] print("Using {}".format(receiver.friendly_name)) elif not found_receivers: print("No reciever found, giving up.") sys.exit(1) else: receiver = found_receivers[0] print("Found receiver:", receiver.friendly_name) return receiver
async def devices(user: User = Depends(get_user)): response_data = { "request_id": uuid4(), "payload": {"user_id": user.id, "devices": []}, } for device in rxv.find(): response_data["payload"]["devices"].append( { "id": device.ctrl_url, "name": "{} {}".format(device.friendly_name, device.model_name), "description": "AV Receiver", "room": "", "type": "devices.types.media_device", "custom_data": {"base_url": device.ctrl_url}, "capabilities": get_all_capabilities(), "device_info": { "manufacturer": "Yamaha Corporation", "model": device.model_name, }, } ) return response_data
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv add_devices( YamahaDevice(config.get("name"), receiver) for receiver in rxv.find())
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Yamaha platform.""" import rxv # Keep track of configured receivers so that we don't end up # discovering a receiver dynamically that we have static config # for. Map each device from its zone_id to an instance since # YamahaDevice is not hashable (thus not possible to add to a set). if hass.data.get(DATA_YAMAHA) is None: hass.data[DATA_YAMAHA] = {} name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) zone_ignore = config.get(CONF_ZONE_IGNORE) zone_names = config.get(CONF_ZONE_NAMES) if discovery_info is not None: name = discovery_info.get("name") model = discovery_info.get("model_name") ctrl_url = discovery_info.get("control_url") desc_url = discovery_info.get("description_url") receivers = rxv.RXV(ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.debug("Receivers: %s", receivers) # when we are dynamically discovered config is empty zone_ignore = [] elif host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host) receivers = rxv.RXV(ctrl_url, name).zone_controllers() devices = [] for receiver in receivers: if receiver.zone in zone_ignore: continue device = YamahaDevice(name, receiver, source_ignore, source_names, zone_names) # Only add device if it's not already added if device.zone_id not in hass.data[DATA_YAMAHA]: hass.data[DATA_YAMAHA][device.zone_id] = device devices.append(device) else: _LOGGER.debug("Ignoring duplicate receiver: %s", name) def service_handler(service): """Handle for services.""" entity_ids = service.data.get(ATTR_ENTITY_ID) devices = [ device for device in hass.data[DATA_YAMAHA].values() if not entity_ids or device.entity_id in entity_ids ] for device in devices: port = service.data[ATTR_PORT] enabled = service.data[ATTR_ENABLED] device.enable_output(port, enabled) device.schedule_update_ha_state(True) hass.services.register(DOMAIN, SERVICE_ENABLE_OUTPUT, service_handler, schema=ENABLE_OUTPUT_SCHEMA) add_entities(devices)
def receiversFind(): receivers = rxv.find() print(receivers) return receivers[0]
def receiversFind(): receivers = rxv.find() return print(receivers)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Yamaha platform.""" import rxv # Keep track of configured receivers so that we don't end up # discovering a receiver dynamically that we have static config # for. Map each device from its unique_id to an instance since # YamahaDevice is not hashable (thus not possible to add to a set). if hass.data.get(DATA_YAMAHA) is None: hass.data[DATA_YAMAHA] = {} name = config.get(CONF_NAME) host = config.get(CONF_HOST) source_ignore = config.get(CONF_SOURCE_IGNORE) source_names = config.get(CONF_SOURCE_NAMES) zone_ignore = config.get(CONF_ZONE_IGNORE) zone_names = config.get(CONF_ZONE_NAMES) if discovery_info is not None: name = discovery_info.get('name') model = discovery_info.get('model_name') ctrl_url = discovery_info.get('control_url') desc_url = discovery_info.get('description_url') receivers = rxv.RXV( ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.info("Receivers: %s", receivers) # when we are dynamically discovered config is empty zone_ignore = [] elif host is None: receivers = [] for recv in rxv.find(): receivers.extend(recv.zone_controllers()) else: ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host) receivers = rxv.RXV(ctrl_url, name).zone_controllers() devices = [] for receiver in receivers: if receiver.zone in zone_ignore: continue device = YamahaDevice(name, receiver, source_ignore, source_names, zone_names) # Only add device if it's not already added if device.unique_id not in hass.data[DATA_YAMAHA]: hass.data[DATA_YAMAHA][device.unique_id] = device devices.append(device) else: _LOGGER.debug('Ignoring duplicate receiver %s', name) def service_handler(service): """Handle for services.""" entity_ids = service.data.get(ATTR_ENTITY_ID) devices = [device for device in hass.data[DATA_YAMAHA].values() if not entity_ids or device.entity_id in entity_ids] for device in devices: port = service.data[ATTR_PORT] enabled = service.data[ATTR_ENABLED] device.enable_output(port, enabled) device.schedule_update_ha_state(True) hass.services.register( DOMAIN, SERVICE_ENABLE_OUTPUT, service_handler, schema=ENABLE_OUTPUT_SCHEMA) add_devices(devices)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yamaha platform.""" import rxv add_devices(YamahaDevice(config.get("name"), receiver) for receiver in rxv.find())
def refresh_receiver_list(self, filter="", valuesDict=None, typeId="", targetId=0): self.receivers = {r.ctrl_url: r for r in rxv.find()} self.logger.debug("receivers list: %s" % unicode(self.receivers))