Set state to the device by ID.

    :param lamp_id:
    :param state:
    :return:
555845
def _set(lamp_id, state, method="state"):
    '''
    
    '''
    try:
        res = _query(lamp_id, state, action=method, method='PUT')
    except Exception as err:
        raise CommandExecutionError(err)

    res = len(res) > 1 and res[-1] or res[0]
    if res.get('success'):
        res = {'result': True}
    elif res.get('error'):
        res = {'result': False,
               'description': res['error']['description'],
               'type': res['error']['type']}

    return res
1161904
def get_thermostat_state_by_id(self, id_):
        
        return next((state for state in self.thermostat_states
                     if state.id == id_), None)
886601
def put(self, deviceId):
        
        device = request.get_json()
        logger.debug("Received /devices/" + deviceId + " - " + str(device))
        self._deviceController.accept(deviceId, device)
        return None, 200
1211061
def set_state(self, state, speed=None):
        
        desired_state = {"powered": state}
        if state:
            brightness = self._to_brightness.get(speed or self.current_fan_speed(), 0.33)
            desired_state.update({'brightness': brightness})

        response = self.api_interface.set_device_state(self, {
            "desired_state": desired_state
        })

        self._update_state_from_response(response)
1043339
def state(self, state: str) -> None:
        """"""
        self._state = state
        for callback in self._callbacks:
            callback()
567400
def set_light_state(self, hue, saturation, brightness, kelvin,
                        bulb=ALL_BULBS, timeout=None):
        
        raw_hue = int((hue % 360) / 360.0 * 0xffff) & 0xffff
        raw_sat = int(saturation * 0xffff) & 0xffff
        raw_bright = int(brightness * 0xffff) & 0xffff
        return self.set_light_state_raw(raw_hue, raw_sat, raw_bright, kelvin,
                                        bulb, timeout)
1280201
def set_state(self, state):
        
        prior_state = self.state
        if state == prior_state:
            return state
        if state == tds_base.TDS_PENDING:
            if prior_state in (tds_base.TDS_READING, tds_base.TDS_QUERYING):
                self.state = tds_base.TDS_PENDING
            else:
                raise tds_base.InterfaceError('logic error: cannot chage query state from {0} to {1}'.
                                              format(tds_base.state_names[prior_state], tds_base.state_names[state]))
        elif state == tds_base.TDS_READING:
            # transition to READING are valid only from PENDING
            if self.state != tds_base.TDS_PENDING:
                raise tds_base.InterfaceError('logic error: cannot change query state from {0} to {1}'.
                                              format(tds_base.state_names[prior_state], tds_base.state_names[state]))
            else:
                self.state = state
        elif state == tds_base.TDS_IDLE:
            if prior_state == tds_base.TDS_DEAD:
                raise tds_base.InterfaceError('logic error: cannot change query state from {0} to {1}'.
                                              format(tds_base.state_names[prior_state], tds_base.state_names[state]))
            self.state = state
        elif state == tds_base.TDS_DEAD:
            self.state = state
        elif state == tds_base.TDS_QUERYING:
            if self.state == tds_base.TDS_DEAD:
                raise tds_base.InterfaceError('logic error: cannot change query state from {0} to {1}'.
                                              format(tds_base.state_names[prior_state], tds_base.state_names[state]))
            elif self.state != tds_base.TDS_IDLE:
                raise tds_base.InterfaceError('logic error: cannot change query state from {0} to {1}'.
                                              format(tds_base.state_names[prior_state], tds_base.state_names[state]))
            else:
                self.rows_affected = tds_base.TDS_NO_COUNT
                self.internal_sp_called = 0
                self.state = state
        else:
            assert False
        return self.state
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']))
1230961
def set_alarm_state(self, state):
        
        values = {"desired_state": {"alarm_enabled": state}}
        response = self.api_interface.set_device_state(self, values)
        self._update_state_from_response(response)
1097800
def _set_current_context(self, device_id):
        
        if device_id not in self._all_index_update_counts:
            self._all_index_update_counts[device_id] = {}
        self._index_update_count = self._all_index_update_counts[device_id]
636335
def set_status(self, status):
        """"""
        if self._json_state['control_url']:
            url = CONST.BASE_URL + self._json_state['control_url']

            status_data = {
                'status': str(status)
            }

            response = self._abode.send_request(
                method="put", url=url, data=status_data)
            response_object = json.loads(response.text)

            _LOGGER.debug("Set Status Response: %s", response.text)

            if response_object['id'] != self.device_id:
                raise AbodeException((ERROR.SET_STATUS_DEV_ID))

            if response_object['status'] != str(status):
                raise AbodeException((ERROR.SET_STATUS_STATE))

            # Note: Status result is of int type, not of new status of device.
            # Seriously, why would you do that?
            # So, can't set status here must be done at device level.

            _LOGGER.info("Set device %s status to: %s", self.device_id, status)

            return True

        return False
1063024
def change_state_id(self, state_id=None):
        
        if state_id is None:
            state_id = state_id_generator(used_state_ids=[self.state_id])
        if not self.is_root_state and not self.is_root_state_of_library:
            used_ids = list(self.parent.states.keys()) + [self.parent.state_id, self.state_id]
            if state_id in used_ids:
                state_id = state_id_generator(used_state_ids=used_ids)

        self._state_id = state_id
1041251
async def set_state(self, parameter):
        """"""
        command_send = CommandSend(pyvlx=self.pyvlx, node_id=self.node_id, parameter=parameter)
        await command_send.do_api_call()
        if not command_send.success:
            raise PyVLXException("Unable to send command")
        self.parameter = parameter
        await self.after_update()
929193
def set_state(self, state):
        
        _field = self.binary_state_name()
        values = {"desired_state": {_field: state}}
        response = self.api_interface.local_set_state(self, values, type_override="binary_switche")
        self._update_state_from_response(response)
454375
def _on_light_state(self, header, payload, rest, addr):
        
        with self.lock:
            label = payload['label'].strip('\x00')
            self.bulbs[header.mac] = bulb = Bulb(label, header.mac)
            if len(self.bulbs) >= self.num_bulbs:
                self.bulbs_found_event.set()

            self.light_state[header.mac] = payload
            if len(self.light_state) >= self.num_bulbs:
                self.light_state_event.set()

        self.callbacks.put(EVENT_LIGHT_STATE, bulb,
                           raw=payload,
                           hue=(payload['hue'] / float(0xffff) * 360) % 360.0,
                           saturation=payload['sat'] / float(0xffff),
                           brightness=payload['bright'] / float(0xffff),
                           kelvin=payload['kelvin'],
                           is_on=bool(payload['power']))
454014
def state(self, state):
        
        allowed_values = ["draft", "scheduled", "allocatingquota", "allocatedquota", "quotaallocationfailed", "checkingmanifest", "checkedmanifest", "devicefetch", "devicecopy", "devicecheck", "publishing", "deploying", "deployed", "manifestremoved", "expired", "stopping", "autostopped", "userstopped", "conflict"]
        if state not in allowed_values:
            raise ValueError(
                "Invalid value for `state` ({0}), must be one of {1}"
                .format(state, allowed_values)
            )

        self._state = state
312038
def _set_or_check_remote_id(self, remote_id):
    """"""
    if not self.remote_id:
      assert self.closed_state == self.ClosedState.PENDING, 'Bad ClosedState!'
      self.remote_id = remote_id
      self.closed_state = self.ClosedState.OPEN
    elif self.remote_id != remote_id:
      raise usb_exceptions.AdbProtocolError(
          '%s remote-id change to %s', self, remote_id)