def get_switch(self, maxtries=3):
        '''
        Populates the self.switch property

        Unlike other queries, this method has to check if the return matches a
        !X or !Y pattern (indicating open and closed respectively) rather than
        read a value.
        '''
        if self.logger:
            self.logger.info('Getting switch status')
        self.switch = None
        tries = 0
        status = None
        while not status:
            tries += 1
            response = self.send('!F')
            if re.match('!Y            1!', response):
                status = 'OPEN'
            elif re.match('!X            1!', response):
                status = 'CLOSED'
            else:
                status = None
            if not status and tries >= maxtries:
                status = 'UNKNOWN'
        self.switch = status
        if self.logger:
            self.logger.info('  Switch Status = {}'.format(self.switch))
        return self.switch
dataset/ETHPy150Open panoptes/POCS/scripts/read_weather.py/AAGCloudSensor.get_switch/original