def bottles(self): """ Return all bottles stored on the connected device. """ if self._bottles is None: # Use the GAPB command to retrieve the details of all bottles # stored in the device data = self._GAPB() self._bottles = [] bottle = '' # Split the response into individual bottles and their head line(s) for line in data.split('\r')[:-1]: if not line.startswith(','): if bottle: self._bottles.append( Bottle.from_string(bottle, logger=self)) bottle = line + '\r' else: bottle += line + '\r' if bottle: self._bottles.append(Bottle.from_string(bottle, logger=self)) return self._bottles
def bottles(self): """ Return all bottles stored on the connected device. """ if self._bottles is None: # Use the GAPB command to retrieve the details of all bottles # stored in the device data = self._GAPB() self._bottles = [] bottle = '' # Split the response into individual bottles and their head line(s) for line in data.split('\r')[:-1]: if not line.startswith(','): if bottle: self._bottles.append( Bottle.from_string(bottle, logger=self)) bottle = line + '\r' else: bottle += line + '\r' if bottle: self._bottles.append( Bottle.from_string(bottle, logger=self)) return self._bottles
def bottle(self, serial): """ Return a bottle with a specific serial number. `serial` : the serial number of the bottle to retrieve """ # Check for the specific serial number without refreshing the entire # list. If it's there, return it from the list. if self._bottles is not None: for bottle in self._bottles: if bottle.serial == serial: return bottle # Otherwise, use the GPRB to retrieve individual bottle details. Note # that we DON'T add it to the list in this case as the list may be # uninitialized at this point. Even if we initialized it, a future call # would have no idea the list was only partially populated data = self._GPRB(serial) return Bottle.from_string(data, logger=self)