def __init__(self, device=None, manufacturer=None, model=None, device_manager=None): """ Instantiates a Scale object. If no arguments are passed, it wraps itself around whatever device calling `device_manager.find` returns and automatically fills in its `manufacturer` and `model` properties according to what `device_manager.get_manufacturer` and `device_manager.get_model` return, respectively. If a `device` argument is passed, the Scale object wraps it and treats it like a PyUSB device. If a `device` argument is passed and `manufacturer` and/or `model` are omitted, the Scale object will query the `device_manager` object to discover and populate the Scale's `manufacturer` and `model` properties. If `manufacturer`, and/or `model` are passed and `device` is omitted, Scale will wrap the device returned when those arguments are passed to `device_manager.find`. If `manufacturer`, and/or `model`, and `device` are all passed, then the Scale object wraps `device` and sets its own `manufacturer`, `model`, and `name` properties accordingly, regardless of `device`'s *actual* manufacturer and model. If a `device_manager` argument is passed, it uses that object instead of a ScaleManager instance to find the attached scale. """ if not device_manager: device_manager = ScaleManager() device = device_manager.find(manufacturer=manufacturer, model=model) if not manufacturer and device: manufacturer = device_manager.get_manufacturer(device) if not model and device: model = device_manager.get_model(device) self._device = device self._model = model self._manufacturer = manufacturer self._manager = device_manager self._endpoint = None self._last_reading = None # Initialize the USB connection to the scale. if self.device: self.connect()