コード例 #1
0
    def test_no_answer_name(self):
        """Sensor returns None for handle 0x03.

        Check that this triggers the right exception.
        """
        poller = MiTempBtPoller(self.TEST_MAC, MockBackend)
        backend = self._get_backend(poller)
        backend.handle_0x03_raw = None
        with self.assertRaises(BluetoothBackendException):
            poller.name()
コード例 #2
0
 def test_rw_exception(self):
     """Test reaction when getting a BluetoothBackendException."""
     poller = MiTempBtPoller(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_TEMPERATURE)
     with self.assertRaises(BluetoothBackendException):
         poller.parameter_value(MI_HUMIDITY)
コード例 #3
0
def poll(mac):
    """Poll data from the sensor."""
    poller = MiTempBtPoller(mac, BluepyBackend)
    print("Getting data from Mi Temperature and Humidity Sensor with MAC: {}".
          format(mac))
    print("FW: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))

    return jsonify(name=poller.name(),
                   firmware=poller.firmware_version(),
                   battery=poller.parameter_value(MI_BATTERY),
                   temperature=poller.parameter_value(MI_TEMPERATURE),
                   humidity=poller.parameter_value(MI_HUMIDITY))
コード例 #4
0
    def test_name(self):
        """Check reading of the sensor name."""
        poller = MiTempBtPoller(self.TEST_MAC, MockBackend)
        backend = self._get_backend(poller)
        backend.name = 'my sensor name'

        self.assertEqual(backend.name, poller.name())
コード例 #5
0
def poll(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiTempBtPoller(args.mac, backend)
    print("Getting data from Mi Temperature and Humidity Sensor")
    print("FW: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))
コード例 #6
0
def poll():
    """Poll data from the sensor."""
    global mac_address
    backend = BluepyBackend
    poller = MiTempBtPoller(mac_address, backend)
    print("Getting data from Mi Temperature and Humidity Sensor")
    print("FW: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))
コード例 #7
0
ファイル: test_everything.py プロジェクト: vnastis/mitemp
    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 = MiTempBtPoller(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))
コード例 #8
0
ファイル: demo.py プロジェクト: UrielCh/mitemp2prometheus
def poll(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiTempBtPoller(args.mac, backend)
    data = {
        "mac": poller._mac,
        "name": poller.name(),
        "version": poller.firmware_version(),
        "battery": poller.parameter_value(MI_BATTERY),
        "temperature": poller.parameter_value(MI_TEMPERATURE),
        "humidity": poller.parameter_value(MI_HUMIDITY)
    }
    print(json.dumps(data))
コード例 #9
0
ファイル: mi2sheet.py プロジェクト: mtoensing/mi2sheet
def pollData(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiTempBtPoller(args.mac, backend)

    #print("Getting data from Mi Temperature and Humidity Sensor")
    #print("FW: {}".format(poller.firmware_version()))
    #print("Name: {}".format(poller.name()))
    #print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    #print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    #print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))

    name = format(poller.name())
    battery = format(poller.parameter_value(MI_BATTERY))
    temperature = format(poller.parameter_value(MI_TEMPERATURE))
    humidity = format(poller.parameter_value(MI_HUMIDITY))

    data = [temperature, humidity, battery]
    print(data)
    return data
コード例 #10
0
ファイル: mi2sheet.py プロジェクト: mtoensing/mi2sheet
def poll(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiTempBtPoller(args.mac, backend)

    #print("Getting data from Mi Temperature and Humidity Sensor")
    #print("FW: {}".format(poller.firmware_version()))
    #print("Name: {}".format(poller.name()))
    #print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    #print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    #print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))

    name = format(poller.name())
    battery = format(poller.parameter_value(MI_BATTERY))
    temperature = format(poller.parameter_value(MI_TEMPERATURE))
    humidity = format(poller.parameter_value(MI_HUMIDITY))

    #print("Compiling this data")
    now = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
    data = [now, temperature, humidity, battery]
    print(data)
    return data
コード例 #11
0
ファイル: mitemp.py プロジェクト: hassiweb/mitemp
def poll(args):
    """Poll data from the sensor."""
    backend = _get_backend(args)
    poller = MiTempBtPoller(args.mac, backend)
    print("Getting data from Mi Temperature and Humidity Sensor")
    print("FW: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
    print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
    print("Humidity: {}".format(poller.parameter_value(MI_HUMIDITY)))

    dtnow = dt.now(pytz.timezone('Japan'))
    data = { \
                'time': dtnow.strftime('%Y-%m-%dT%H:%M:%S%z'), \
                'mac': args.mac, \
                'battery': poller.parameter_value(MI_BATTERY), \
                'temperature': poller.parameter_value(MI_TEMPERATURE), \
                'humidity': poller.parameter_value(MI_HUMIDITY) \
            }

    data = append_json_to_file(data,
                               args.location + os.sep + args.mac + '.json')
コード例 #12
0
ファイル: mitemp-mqtt.py プロジェクト: yolkhovyy/mitemp
    mitemp_eui64 = mac_to_eui64(mitemp_mac)
    topic_device_info = 'OpenCH/Gw/{}/TeHu/{}/Evt/DeviceInfo'.format(
        SELF_EUI64, mitemp_eui64)
    topic_health = 'OpenCH/Gw/{}/TeHu/{}/Evt/Health'.format(
        SELF_EUI64, mitemp_eui64)
    topic_measurements = 'OpenCH/Gw/{}/TeHu/{}/Evt/Status'.format(
        SELF_EUI64, mitemp_eui64)

    poller = MiTempBtPoller(mitemp_mac, BACKEND)
    msgs = []

    try:
        if ARGS.devinfo:
            payload = '{{"name":"{}","firmware_version":"{}"}}' \
                .format( \
                    poller.name(), \
                    poller.firmware_version())
            msgs.append({'topic': topic_device_info, 'payload': payload})

        if ARGS.health:
            payload = '{{"measurements":[{{"name":"battery","value":{},"units":"%"}}]}}' \
                .format( \
                    poller.parameter_value(MI_BATTERY))
            msgs.append({'topic': topic_health, 'payload': payload})

        if ARGS.measurements:
            payload = '{{"measurements":[{{"name":"temperature","value":{},"units":"℃"}},{{"name":"humidity","value":{},"units":"%"}}]}}' \
                .format( \
                    poller.parameter_value(MI_TEMPERATURE), \
                    poller.parameter_value(MI_HUMIDITY))
            msgs.append({'topic': topic_measurements, 'payload': payload})