A UPnP WeMo Controllee.  Includes socket switch.
518695
function (controlPoint, uuid, location, desc, localAddress) {
    EventEmitter.call(this);

    if (TRACE) {
        logger.info({
            method: "UpnpDevice",
            uuid: uuid,
        }, "new device object");
    }
    this.controlPoint = controlPoint;

    this.uuid = uuid;
    this.udn = desc.UDN[0];

    this.forgotten = false
    this.last_seen = (new Date()).getTime();

    this.location = location;

    this.deviceType = desc.deviceType ? desc.deviceType[0] : null;
    this.friendlyName = desc.friendlyName ? desc.friendlyName[0] : null;
    this.manufacturer = desc.manufacturer ? desc.manufacturer[0] : null;
    this.manufacturerUrl = desc.manufacturerURL ? desc.manufacturerURL[0] : null;
    this.modelNumber = desc.modelNumber ? desc.modelNumber[0] : null;
    this.modelDescription = desc.modelDescription ? desc.modelDescription[0] : null;
    this.modelName = desc.modelName ? desc.modelName[0] : null;
    this.modelUrl = desc.modelURL ? desc.modelURL[0] : null;
    this.softwareVersion = desc.softwareVersion ? desc.softwareVersion[0] : null;
    this.hardwareVersion = desc.hardwareVersion ? desc.hardwareVersion[0] : null;
    this.serialNum = desc.serialNum ? desc.serialNum[0] : null;

    var u = url.parse(this.location);
    this.host = u.hostname;
    this.port = u.port;

    this.localAddress = localAddress;

    this.devices = {}; // sub-devices

    this.services = {};

    this._handleDeviceInfo(desc);

    if (seend[this.uuid] === undefined) {
        seend[this.uuid] = true;
        logger.info({
            method: "UpnpDevice",
            device: {
                loction: this.location,
                uuid: this.uuid,
                deviceType: this.deviceType,
                friendlyName: this.friendlyName,
                manufacturer: this.manufacturer,
                manufacturerUrl: this.manufacturerURL,
                modelNumber: this.modelNumber,
                modelDescription: this.modelDescription,
                modelName: this.modelName,
                modelUrl: this.modelURL,
            }
        }, "previously unseen UPnP device");
    }
    // var self = this;
    // this._getDeviceDetails(function(desc) {
    // self._handleDeviceInfo(desc);
    // });

}
206197
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
    """"""
    # We create a connected TCP socket. Note the trick with setblocking(0)
    # that prevents us from having to create a thread.
    lsock = socket.socket(family, type, proto)
    lsock.bind(('localhost', 0))
    lsock.listen(1)
    addr, port = lsock.getsockname()
    csock = socket.socket(family, type, proto)
    csock.setblocking(False)
    try:
        csock.connect((addr, port))
    except socket.error as e:
        if e.errno != errno.WSAEWOULDBLOCK:
            lsock.close()
            csock.close()
            raise
    ssock, _ = lsock.accept()
    csock.setblocking(True)
    lsock.close()
    return (ssock, csock)
404641
def enable(self):
        """"""
        # Flip on the power and enable bits.
        self._write8(TCS34725_ENABLE, TCS34725_ENABLE_PON)
        time.sleep(0.01)
        self._write8(TCS34725_ENABLE, (TCS34725_ENABLE_PON | TCS34725_ENABLE_AEN))
815236
def set_pwm(self, channel, on, off):
        """"""
        self.i2c.write8(LED0_ON_L+4*channel, on & 0xFF)
        self.i2c.write8(LED0_ON_H+4*channel, on >> 8)
        self.i2c.write8(LED0_OFF_L+4*channel, off & 0xFF)
        self.i2c.write8(LED0_OFF_H+4*channel, off >> 8)
720809
async def async_set_switch_state(
            self, switch_number: SwitchNumber, state: bool) -> None:
        

        await self._protocol.async_execute(
            SetSwitchCommand(
                switch_number,
                SwitchState.On if state else SwitchState.Off))
748432
function bindSocket(io, indicator) {
    Object.keys(indicator.watch).forEach((key) => {
        let eventName = indicator.watch[key];
        indicator.on(eventName, (msg) => io.emit(eventName, msg));
    });
}
1040504
function Socket (io, nsp, opts) {
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  this.receiveBuffer = [];
  this.sendBuffer = [];
  this.connected = false;
  this.disconnected = true;
  if (opts && opts.query) {
    this.query = opts.query;
  }
  if (this.io.autoConnect) this.open();
}
836269
def subscribe(self, socket_id, channel):
        """"""
        con = self._get_connection(socket_id)
        self.subscriptions.setdefault(channel, set()).add(socket_id)
        con.subscriptions.add(channel)
850057
public void switchesFromJSON(Network net, JSONArray a) throws JSONConverterException {
        for (Object o : a) {
            net.newSwitch(requiredInt((JSONObject) o, "id"), readCapacity((JSONObject) o));
        }
    }
68238
private DatagramChannel openUdpChannel(InetAddress localAddress, int port, Selector selector) throws IOException {
		DatagramChannel channel = DatagramChannel.open();
		channel.configureBlocking(false);
		// Register selector for reading operations
		channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
		channel.bind(new InetSocketAddress(localAddress, port));
		return channel;
	}
1220579
def set_power(self, state):
    """"""
    packet = bytearray(16)
    packet[0] = 2
    if self.check_nightlight():
      packet[4] = 3 if state else 2
    else:
      packet[4] = 1 if state else 0
    self.send_packet(0x6a, packet)
336414
function ProxySocket(proxy_port, proxy_addr, meta, proxy_opts) {
    stream.Duplex.call(this);

    this.connected_fn = null;
    this.proxy_addr   = proxy_addr;
    this.proxy_port   = proxy_port;
    this.proxy_opts   = proxy_opts || {};

    this.setMeta(meta || {});

    this.state = 'disconnected';
}
759991
function Socket(options) {
  if (!(this instanceof Socket)) {
    return new Socket(options);
  }
  var tty = process.binding('tty_wrap');
  var guessHandleType = tty.guessHandleType;
  tty.guessHandleType = function() {
    return 'PIPE';
  };
  net.Socket.call(this, options);
  tty.guessHandleType = guessHandleType;
}
1040183
function Socket (type, opts) {

    opts = opts || {};
    this.af_domain = opts.raw ? nn.AF_SP_RAW : nn.AF_SP;
    this.type = type;

    switch(type) {
        case 'req':
            this.protocol = nn.NN_REQ;
            this.sender=true;
            this.receiver=true;
            break;

        case 'rep':
            this.protocol = nn.NN_REP;
            this.sender = true;
            this.receiver = true;
            break;

        case 'pair':
            this.protocol = nn.NN_PAIR;
            this.sender = true;
            this.receiver = true;
            break;

        case 'push':
            this.protocol = nn.NN_PUSH;
            this.sender = true;
            this.receiver = false;
            // nndontwait otherwise defaults true, PUSH socket default is false
            opts.dontwait = opts.dontwait || false;
            break;

        case 'pull':
            this.protocol = nn.NN_PULL;
            this.sender = false;
            this.receiver = true;
            break;

        case 'pub':
            this.protocol = nn.NN_PUB;
            this.sender = true;
            this.receiver = false;
            break;

        case 'sub':
            this.protocol = nn.NN_SUB;
            this.sender = false;
            this.receiver = true;
            break;

        case 'bus':
            this.protocol = nn.NN_BUS;
            this.sender = true;
            this.receiver = true;
            break;

        case 'surveyor':
            this.protocol = nn.NN_SURVEYOR;
            this.sender = true;
            this.receiver = false;
            break;

        case 'respondent':
            this.protocol = nn.NN_RESPONDENT;
            this.sender = true;
            this.receiver = true;
            break;

        default:
            throw new Error('unrecognised socket type ' + type);
            break;
    }

  this.binding = nn.Socket(this.af_domain, this.protocol);
  this.bound = {};
  this.connected = {};
  this.queue = [];

  /* async I/O option */
  this.dontwait('dontwait' in opts ? opts.dontwait : true);

  /*  subscription filter control */
  this.channels     = {};

  /*  subscription handling at initialization  */
  if (opts.hasOwnProperty('chan')) {
    if (Array.isArray(opts.chan)) {
      opts.chan.forEach(this._register.bind(this));
    } else {
      throw new TypeError('chan requires an Array');
    }
  } else if (type === 'sub') {
    this._register(''); //default topic is an empty string
  }

  /* sockopt api handling at initialization */
  for(var sokopt in sol){
    if(opts.hasOwnProperty(sokopt)) this[sokopt](opts[sokopt]);
  }

  /* start listening for inbound messages */
  if (this.af_domain === nn.AF_SP && this.receiver) {
    this._startPollReceive();
  }

  if (!opts.hasOwnProperty('objectMode')) {
    // reduce the highwatermark from 16K msgs to 16msgs
    // would be more useful if we have a backpressure mechanism
    opts.objectMode = true;
  }

  Duplex.call(this, opts);

}
757832
def set_enable(self, channel, value):
        '''
        '''
        try:
            bit = self._ch_map[channel]['GPIOEN']['bit']
        except KeyError:
            raise ValueError('set_enable() not supported for channel %s' % channel)
        self._set_power_gpio_value(bit=bit, value=value)
900866
def _on_power_state(self, header, payload, rest, addr):
        
        with self.lock:
            self.power_state[header.mac] = payload
            if len(self.power_state) >= self.num_bulbs:
                self.power_state_event.set()

        self.callbacks.put(EVENT_POWER_STATE, self.get_bulb(header.mac),
                           is_on=bool(payload['is_on']))
651675
@RequiresPermission(ACCESS_WIFI_STATE)
  public static Observable<WifiInfo> observeWifiAccessPointChanges(final Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    final IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);

    return Observable.create(new ObservableOnSubscribe<WifiInfo>() {
      @Override public void subscribe(final ObservableEmitter<WifiInfo> emitter) throws Exception {
        final BroadcastReceiver receiver =
            createAccessPointChangesReceiver(emitter, wifiManager);

        context.registerReceiver(receiver, filter);

        Disposable disposable = disposeInUiThread(new Action() {
          @Override public void run() {
            tryToUnregisterReceiver(context, receiver);
          }
        });

        emitter.setDisposable(disposable);
      }
    });
  }