Exemple #1
0
def connect(config):
    # Connect to SBS
    sbs = Server(hostname=config['host'], 
                 port=config['port'], 
                 username=config['user'], 
                 password=config['passwd'] )

    # Check connection
    try:
        sbs.connect()
        if sbs.logged_in:
            logging.info("Connected to Squeezebox Server v%s on %s:%s", sbs.get_version(), config['host'], config['port'])
        else:
            logging.critical("Could not connect to server, possible wrong credentials")
            exit(1)
    except socketerror:
        logging.critical("Network is unreachable (check network connection and/or IP/port settings of your SB server)")
        p = Popen(["play", "noconnection.wav"], stdout=nulfp.fileno(), stderr=nulfp.fileno())
        return None, None

    # Additional info
    sq = sbs.get_player(config['mac'])
    logging.info("Copying behaviour of SB '%s'", sq.get_name())
    logging.info("Mode: %s | Time: %s | Connected: %s | WiFi: %s", 
                 sq.get_mode(), sq.get_time_elapsed(), 
                 sq.is_connected, sq.get_wifi_signal_strength())

    # All the magic: in this request we subscribe to all playlist events,
    # time changes, and volume changes
    sbs.request(quote("subscribe time,playlist,mixer volume", safe=" "))

    return sbs, sq