Example #1
0
    def test_no_answer_version(self):
        """Sensor returns None for handle 0x03.

        Check that this triggers the right exception.
        """
        poller = MiThermometerPoller(self.TEST_MAC, MockBackend)
        backend = self._get_backend(poller)
        backend.handle_0x38_raw = None
        with self.assertRaises(BluetoothBackendException):
            poller.name()
Example #2
0
 def test_rw_exception(self):
     """Test reaction when getting a BluetoothBackendException."""
     poller = MiThermometerPoller(self.TEST_MAC,
                                  RWExceptionBackend,
                                  retries=0)
     with self.assertRaises(BluetoothBackendException):
         poller.firmware_version()
     with self.assertRaises(BluetoothBackendException):
         poller.name()
     with self.assertRaises(BluetoothBackendException):
         poller.parameter_value(MI_HUMIDITY)
     with self.assertRaises(BluetoothBackendException):
         poller.parameter_value(MI_HUMIDITY)
Example #3
0
    def test_name(self):
        """Check reading of the sensor name."""
        poller = MiThermometerPoller(self.TEST_MAC, MockBackend)
        backend = self._get_backend(poller)
        backend.name = 'my sensor name'

        self.assertEqual(backend.name, poller.name())
Example #4
0
def poll(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiThermometerPoller(args.mac, backend)
    print("Getting data from Mi Flora")
    print("FW: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))
    print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    def test_everything(self):
        """Test reading data from a sensor

        This check if we can successfully get some data from a real sensor. This test requires bluetooth hardware and a
        real sensor close by.
        """
        assert hasattr(self, "mac")
        poller = MiThermometerPoller(self.mac, self.backend_type)
        self.assertIsNotNone(poller.firmware_version())
        self.assertIsNotNone(poller.name())
        self.assertIsNotNone(poller.parameter_value(MI_TEMPERATURE))
        self.assertIsNotNone(poller.parameter_value(MI_HUMIDITY))
        self.assertIsNotNone(poller.parameter_value(MI_BATTERY))