Set the state of the switch. If the armed state is set to False,
        the function does nothing.

        :param val: Boolean. The value to set the switch state to. When None,
            the switch will be set to the opposite of its current state.
        :return: Boolean. Returns True if operation was successful (i.e. the
            switch was armed before this was called)

def switch(self, val=None):
        """
        Set the state of the switch. If the armed state is set to False,
        the function does nothing.

        :param val: Boolean. The value to set the switch state to. When None,
            the switch will be set to the opposite of its current state.
        :return: Boolean. Returns True if operation was successful (i.e. the
            switch was armed before this was called)
        """
        if self._armed:
            if val is None:
                val = not self._switched
            self._switched = val
            self._armed = False
            return True
        else:
            return False