Beispiel #1
0
    def SendInfluxMIthermo(cls, InfluxDBClient, MAC):

        print("thermo: " + MAC)
        pollerTemp = MiTempBtPoller(MAC,
                                    BluepyBackend,
                                    retries=1,
                                    cache_timeout=30)
        try:
            Thermo = [{
                "measurement": "Thermo",
                "fields": {
                    "Battery": (pollerTemp.parameter_value(MI_BATTERY)),
                    "Temperature":
                    (pollerTemp.parameter_value(MI_TEMPERATURE)),
                    "Humidity": (pollerTemp.parameter_value(MI_HUMIDITY))
                }
            }]
            cls.client.write_points(Thermo)
        except BTLEException as e:
            print(datetime.datetime.now(),
                  "Error connecting to device: error {}".format(e))
        except BrokenPipeError as e:
            print("BrokenPipeError Thermo")
        except Exception as e:
            #availability = 'offline'
            print(
                datetime.datetime.now(),
                "Error polling device. Device might be unreachable or offline."
            )

        pollerTemp.clear_cache()
Beispiel #2
0
    def test_clear_cache(self):
        """Test with negative temperature."""
        poller = MiTempBtPoller(self.TEST_MAC, MockBackend)
        backend = self._get_backend(poller)

        self.assertFalse(poller.cache_available())
        backend.temperature = 1.0
        self.assertAlmostEqual(1.0,
                               poller.parameter_value(MI_TEMPERATURE),
                               delta=0.01)
        self.assertTrue(poller.cache_available())

        # data is taken from cache, new value is ignored
        backend.temperature = 2.0
        self.assertAlmostEqual(1.0,
                               poller.parameter_value(MI_TEMPERATURE),
                               delta=0.01)

        self.assertTrue(poller.cache_available())
        poller.clear_cache()
        self.assertFalse(poller.cache_available())

        backend.temperature = 3.0
        self.assertAlmostEqual(3.0,
                               poller.parameter_value(MI_TEMPERATURE),
                               delta=0.01)
        self.assertTrue(poller.cache_available())
Beispiel #3
0
    def SendInfluxMIthermo(cls, InfluxDBClient, MAC):

        print("thermo: " + MAC)
        for A in range(cls.NofDongles):
            myadapter = 'hci' + str(A)
            print("Polling with: " + myadapter)
            if not cls.ImPolling:
                return

            try:
                pollerTemp = MiTempBtPoller(MAC,
                                            BluepyBackend,
                                            retries=1,
                                            cache_timeout=30,
                                            adapter=myadapter)
                if not cls.ImPolling:
                    return
                Thermo = [{
                    "measurement": "Thermo",
                    "fields": {
                        "Battery": (pollerTemp.parameter_value(MI_BATTERY)),
                        "Temperature":
                        (pollerTemp.parameter_value(MI_TEMPERATURE)),
                        "Humidity": (pollerTemp.parameter_value(MI_HUMIDITY))
                    },
                    "timestamp": time.time()
                }]
                if cls.client.write_points(Thermo):
                    break
            except BTLEException as e:
                print(datetime.datetime.now(),
                      "Error connecting to device: error {}".format(e))
            except BrokenPipeError as e:
                print("BrokenPipeError Thermo")
            except Exception as e:
                #availability = 'offline'
                print(
                    datetime.datetime.now(),
                    "Error polling device. Device might be unreachable or offline."
                )

        pollerTemp.clear_cache()