Exemple #1
0
    def _on_device_state_changed(self, device, new_state, old_state, reason):
        new = NM.DeviceState(new_state)
        old = NM.DeviceState(old_state)
        state_reason = NM.DeviceStateReason(reason)
        logging.debug(
            'New: %s Old: %s Reason: %s' %
            (new.value_nick, old.value_nick, state_reason.value_nick))

        error_msg = None
        reply_msg = None

        if new == NM.DeviceState.FAILED:
            error_msg = 'Connection failed with reason: %s' % state_reason.value_nick
        elif new == NM.DeviceState.ACTIVATED:
            reply_msg = 'Connection sucesfully activated'
        elif (new <= NM.DeviceState.DISCONNECTED or new == NM.DeviceState.DEACTIVATING) and \
                (NM.DeviceState.DISCONNECTED < old <= NM.DeviceState.ACTIVATED):
            error_msg = 'Connection disconnected with reason %s' % state_reason.value_nick
        else:
            return  # Keep checking the state changes

        # We are done with state changes
        device.disconnect(self._statehandler)
        if error_msg is None:
            self._return_or_reply_handler(reply_msg)
        else:
            logging.debug(error_msg)
            self._raise_or_error_handler(NMConnectionError(error_msg))
Exemple #2
0
    def _on_device_state_changed(self, device: NM.Device, new_state: int,
                                 old_state: int, reason: int) -> None:
        new = NM.DeviceState(new_state)
        old = NM.DeviceState(old_state)
        state_reason = NM.DeviceStateReason(reason)
        logging.debug(
            f"New: {new.value_nick} Old: {old.value_nick} Reason: {state_reason.value_nick}"
        )

        error_msg = None

        if new == NM.DeviceState.FAILED:
            error_msg = f"Connection failed with reason: {state_reason.value_nick}"
        elif new == NM.DeviceState.ACTIVATED:
            logging.debug("Connection successfully activated")
        elif (new <= NM.DeviceState.DISCONNECTED or new == NM.DeviceState.DEACTIVATING) and \
                (NM.DeviceState.DISCONNECTED < old <= NM.DeviceState.ACTIVATED):
            error_msg = f"Connection disconnected with reason {state_reason.value_nick}"
        else:
            return  # Keep checking the state changes

        # We are done with state changes
        assert self._statehandler is not None
        GObject.signal_handler_disconnect(device, self._statehandler)
        if error_msg is None:
            self.reply_handler()
        else:
            logging.debug(error_msg)
            self.error_handler(NMConnectionError(error_msg))