def _get_height(self): with timeout( self.SCAN_TIMEOUT, exception=DeviceTimeoutError( "Retrieving the height from {} device {} timed out after {} seconds" .format(repr(self), self.mac, self.SCAN_TIMEOUT)), ): self.desk.read_dpg_data() return self.desk.current_height_with_offset.cm return -1
def _get_data(self): scan_processor = ScanProcessor(self.mac) scanner = btle.Scanner().withDelegate(scan_processor) scanner.scan(self.SCAN_TIMEOUT, passive=True) with timeout( self.SCAN_TIMEOUT, exception=DeviceTimeoutError( "Retrieving data from {} device {} timed out after {} seconds".format( repr(self), self.mac, self.SCAN_TIMEOUT ) ), ): while not scan_processor.ready: time.sleep(1) return scan_processor.results
def _get_weight(self): from bluepy import btle scan_processor = ScanProcessor(self.mac) scanner = btle.Scanner().withDelegate(scan_processor) scanner.scan(self.SCAN_TIMEOUT, passive=True) with timeout( self.SCAN_TIMEOUT, exception=DeviceTimeoutError( "Retrieving the weight from {} device {} timed out after {} seconds".format( repr(self), self.mac, self.SCAN_TIMEOUT ) ), ): while scan_processor.weight is None: time.sleep(1) return scan_processor.weight return -1
def _get_height(self): from bluepy import btle with timeout( self.SCAN_TIMEOUT, exception=DeviceTimeoutError( "Retrieving the height from {} device {} timed out after {} seconds" .format(repr(self), self.mac, self.SCAN_TIMEOUT)), ): try: self.desk.read_dpg_data() return self.desk.current_height_with_offset.cm + self.desk_offset_cm except btle.BTLEException as e: logger.log_exception( _LOGGER, "Error during update of linak desk '%s' (%s): %s", repr(self), self.mac, type(e).__name__, suppress=True, ) raise DeviceTimeoutError