mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Support for the AirThings Wave Plus (#1656)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										23
									
								
								esphome/components/airthings_ble/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								esphome/components/airthings_ble/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| import esphome.codegen as cg | ||||
| import esphome.config_validation as cv | ||||
| from esphome.components import esp32_ble_tracker | ||||
| from esphome.const import CONF_ID | ||||
|  | ||||
| DEPENDENCIES = ["esp32_ble_tracker"] | ||||
| CODEOWNERS = ["@jeromelaban"] | ||||
|  | ||||
| airthings_ble_ns = cg.esphome_ns.namespace("airthings_ble") | ||||
| AirthingsListener = airthings_ble_ns.class_( | ||||
|     "AirthingsListener", esp32_ble_tracker.ESPBTDeviceListener | ||||
| ) | ||||
|  | ||||
| CONFIG_SCHEMA = cv.Schema( | ||||
|     { | ||||
|         cv.GenerateID(): cv.declare_id(AirthingsListener), | ||||
|     } | ||||
| ).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     var = cg.new_Pvariable(config[CONF_ID]) | ||||
|     yield esp32_ble_tracker.register_ble_device(var, config) | ||||
							
								
								
									
										33
									
								
								esphome/components/airthings_ble/airthings_listener.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								esphome/components/airthings_ble/airthings_listener.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| #include "airthings_listener.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
|  | ||||
| namespace esphome { | ||||
| namespace airthings_ble { | ||||
|  | ||||
| static const char *TAG = "airthings_ble"; | ||||
|  | ||||
| bool AirthingsListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { | ||||
|   for (auto &it : device.get_manufacturer_datas()) { | ||||
|     if (it.uuid == esp32_ble_tracker::ESPBTUUID::from_uint32(0x0334)) { | ||||
|       if (it.data.size() < 4) | ||||
|         continue; | ||||
|  | ||||
|       uint32_t sn = it.data[0]; | ||||
|       sn |= ((uint32_t) it.data[1] << 8); | ||||
|       sn |= ((uint32_t) it.data[2] << 16); | ||||
|       sn |= ((uint32_t) it.data[3] << 24); | ||||
|  | ||||
|       ESP_LOGD(TAG, "Found AirThings device Serial:%u (MAC: %s)", sn, device.address_str().c_str()); | ||||
|       return true; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace airthings_ble | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										20
									
								
								esphome/components/airthings_ble/airthings_listener.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								esphome/components/airthings_ble/airthings_listener.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| #pragma once | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" | ||||
| #include <BLEDevice.h> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace airthings_ble { | ||||
|  | ||||
| class AirthingsListener : public esp32_ble_tracker::ESPBTDeviceListener { | ||||
|  public: | ||||
|   bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; | ||||
| }; | ||||
|  | ||||
| }  // namespace airthings_ble | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user