From 98f4854ecde764feb376ad05cf63924491477971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Filistovi=C4=8D?= Date: Sat, 8 Aug 2026 09:01:24 +0300 Subject: [PATCH] [ble_device_base] Migrate BLE sensor platforms to the neutral layer (batch 11: xiaomi_lywsdcgq, xiaomi_mhoc303, xiaomi_mhoc401) (#18178) --- esphome/components/xiaomi_lywsdcgq/sensor.py | 14 +++++------ .../xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp | 6 +---- .../xiaomi_lywsdcgq/xiaomi_lywsdcgq.h | 10 +++----- esphome/components/xiaomi_mhoc303/sensor.py | 14 +++++------ .../xiaomi_mhoc303/xiaomi_mhoc303.cpp | 6 +---- .../xiaomi_mhoc303/xiaomi_mhoc303.h | 10 +++----- esphome/components/xiaomi_mhoc401/sensor.py | 14 +++++------ .../xiaomi_mhoc401/xiaomi_mhoc401.cpp | 6 +---- .../xiaomi_mhoc401/xiaomi_mhoc401.h | 10 +++----- .../components/xiaomi_lywsdcgq/common-ln.yaml | 9 +++++++ tests/components/xiaomi_lywsdcgq/common.yaml | 3 +++ .../xiaomi_lywsdcgq/test.ln882x-ard.yaml | 3 +++ .../xiaomi_lywsdcgq/validate.bk72xx-ard.yaml | 22 +++++++++++++++++ .../components/xiaomi_mhoc303/common-ln.yaml | 9 +++++++ tests/components/xiaomi_mhoc303/common.yaml | 3 +++ .../xiaomi_mhoc303/test.ln882x-ard.yaml | 3 +++ .../xiaomi_mhoc303/validate.bk72xx-ard.yaml | 22 +++++++++++++++++ .../components/xiaomi_mhoc401/common-ln.yaml | 10 ++++++++ tests/components/xiaomi_mhoc401/common.yaml | 9 ++++--- .../xiaomi_mhoc401/test.ln882x-ard.yaml | 3 +++ .../xiaomi_mhoc401/validate.bk72xx-ard.yaml | 24 +++++++++++++++++++ 21 files changed, 150 insertions(+), 60 deletions(-) create mode 100644 tests/components/xiaomi_lywsdcgq/common-ln.yaml create mode 100644 tests/components/xiaomi_lywsdcgq/test.ln882x-ard.yaml create mode 100644 tests/components/xiaomi_lywsdcgq/validate.bk72xx-ard.yaml create mode 100644 tests/components/xiaomi_mhoc303/common-ln.yaml create mode 100644 tests/components/xiaomi_mhoc303/test.ln882x-ard.yaml create mode 100644 tests/components/xiaomi_mhoc303/validate.bk72xx-ard.yaml create mode 100644 tests/components/xiaomi_mhoc401/common-ln.yaml create mode 100644 tests/components/xiaomi_mhoc401/test.ln882x-ard.yaml create mode 100644 tests/components/xiaomi_mhoc401/validate.bk72xx-ard.yaml diff --git a/esphome/components/xiaomi_lywsdcgq/sensor.py b/esphome/components/xiaomi_lywsdcgq/sensor.py index 5d964ea22a..0fbe4fcda9 100644 --- a/esphome/components/xiaomi_lywsdcgq/sensor.py +++ b/esphome/components/xiaomi_lywsdcgq/sensor.py @@ -1,5 +1,5 @@ import esphome.codegen as cg -from esphome.components import esp32_ble_tracker, sensor +from esphome.components import ble_device_base, sensor import esphome.config_validation as cv from esphome.const import ( CONF_BATTERY_LEVEL, @@ -16,15 +16,15 @@ from esphome.const import ( UNIT_PERCENT, ) -DEPENDENCIES = ["esp32_ble_tracker"] -AUTO_LOAD = ["xiaomi_ble"] +AUTO_LOAD = ["ble_device_base", "xiaomi_ble"] xiaomi_lywsdcgq_ns = cg.esphome_ns.namespace("xiaomi_lywsdcgq") XiaomiLYWSDCGQ = xiaomi_lywsdcgq_ns.class_( - "XiaomiLYWSDCGQ", esp32_ble_tracker.ESPBTDeviceListener, cg.Component + "XiaomiLYWSDCGQ", ble_device_base.ESPBTDeviceListener, cg.Component ) -CONFIG_SCHEMA = ( +CONFIG_SCHEMA = cv.All( + ble_device_base.rename_legacy_hub_id("xiaomi_lywsdcgq"), cv.Schema( { cv.GenerateID(): cv.declare_id(XiaomiLYWSDCGQ), @@ -50,15 +50,15 @@ CONFIG_SCHEMA = ( ), } ) - .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) .extend(cv.COMPONENT_SCHEMA) + .extend(ble_device_base.BLE_DEVICE_SCHEMA), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - await esp32_ble_tracker.register_ble_device(var, config) + await ble_device_base.register_ble_device(var, config) cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex)) diff --git a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp index 56efaaef51..1ddf7ec235 100644 --- a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp +++ b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp @@ -1,8 +1,6 @@ #include "xiaomi_lywsdcgq.h" #include "esphome/core/log.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_lywsdcgq { static const char *const TAG = "xiaomi_lywsdcgq"; @@ -14,7 +12,7 @@ void XiaomiLYWSDCGQ::dump_config() { LOG_SENSOR(" ", "Battery Level", this->battery_level_); } -bool XiaomiLYWSDCGQ::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { +bool XiaomiLYWSDCGQ::parse_device(const ble_device_base::ESPBTDevice &device) { if (device.address_uint64() != this->address_) { ESP_LOGVV(TAG, "parse_device(): unknown MAC address."); return false; @@ -55,5 +53,3 @@ bool XiaomiLYWSDCGQ::parse_device(const esp32_ble_tracker::ESPBTDevice &device) } } // namespace esphome::xiaomi_lywsdcgq - -#endif diff --git a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h index 86afef4571..5cecc2f78a 100644 --- a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h +++ b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h @@ -2,18 +2,16 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" +#include "esphome/components/ble_device_base/ble_device.h" #include "esphome/components/xiaomi_ble/xiaomi_ble.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_lywsdcgq { -class XiaomiLYWSDCGQ final : public Component, public esp32_ble_tracker::ESPBTDeviceListener { +class XiaomiLYWSDCGQ final : public Component, public ble_device_base::ESPBTDeviceListener { public: void set_address(uint64_t address) { address_ = address; } - bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; + bool parse_device(const ble_device_base::ESPBTDevice &device) override; void dump_config() override; void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; } @@ -28,5 +26,3 @@ class XiaomiLYWSDCGQ final : public Component, public esp32_ble_tracker::ESPBTDe }; } // namespace esphome::xiaomi_lywsdcgq - -#endif diff --git a/esphome/components/xiaomi_mhoc303/sensor.py b/esphome/components/xiaomi_mhoc303/sensor.py index 86c4d6699f..de1b3ea4b8 100644 --- a/esphome/components/xiaomi_mhoc303/sensor.py +++ b/esphome/components/xiaomi_mhoc303/sensor.py @@ -1,5 +1,5 @@ import esphome.codegen as cg -from esphome.components import esp32_ble_tracker, sensor +from esphome.components import ble_device_base, sensor import esphome.config_validation as cv from esphome.const import ( CONF_BATTERY_LEVEL, @@ -16,15 +16,15 @@ from esphome.const import ( UNIT_PERCENT, ) -DEPENDENCIES = ["esp32_ble_tracker"] -AUTO_LOAD = ["xiaomi_ble"] +AUTO_LOAD = ["ble_device_base", "xiaomi_ble"] xiaomi_mhoc303_ns = cg.esphome_ns.namespace("xiaomi_mhoc303") XiaomiMHOC303 = xiaomi_mhoc303_ns.class_( - "XiaomiMHOC303", esp32_ble_tracker.ESPBTDeviceListener, cg.Component + "XiaomiMHOC303", ble_device_base.ESPBTDeviceListener, cg.Component ) -CONFIG_SCHEMA = ( +CONFIG_SCHEMA = cv.All( + ble_device_base.rename_legacy_hub_id("xiaomi_mhoc303"), cv.Schema( { cv.GenerateID(): cv.declare_id(XiaomiMHOC303), @@ -50,15 +50,15 @@ CONFIG_SCHEMA = ( ), } ) - .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) .extend(cv.COMPONENT_SCHEMA) + .extend(ble_device_base.BLE_DEVICE_SCHEMA), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - await esp32_ble_tracker.register_ble_device(var, config) + await ble_device_base.register_ble_device(var, config) cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex)) diff --git a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp index 74626ed0a5..9706e50861 100644 --- a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp +++ b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp @@ -1,8 +1,6 @@ #include "xiaomi_mhoc303.h" #include "esphome/core/log.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_mhoc303 { static const char *const TAG = "xiaomi_mhoc303"; @@ -14,7 +12,7 @@ void XiaomiMHOC303::dump_config() { LOG_SENSOR(" ", "Battery Level", this->battery_level_); } -bool XiaomiMHOC303::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { +bool XiaomiMHOC303::parse_device(const ble_device_base::ESPBTDevice &device) { if (device.address_uint64() != this->address_) { ESP_LOGVV(TAG, "parse_device(): unknown MAC address."); return false; @@ -55,5 +53,3 @@ bool XiaomiMHOC303::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { } } // namespace esphome::xiaomi_mhoc303 - -#endif diff --git a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h index 042a5034f1..a15b58f8ed 100644 --- a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h +++ b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h @@ -2,18 +2,16 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" +#include "esphome/components/ble_device_base/ble_device.h" #include "esphome/components/xiaomi_ble/xiaomi_ble.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_mhoc303 { -class XiaomiMHOC303 final : public Component, public esp32_ble_tracker::ESPBTDeviceListener { +class XiaomiMHOC303 final : public Component, public ble_device_base::ESPBTDeviceListener { public: void set_address(uint64_t address) { address_ = address; } - bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; + bool parse_device(const ble_device_base::ESPBTDevice &device) override; void dump_config() override; void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; } @@ -28,5 +26,3 @@ class XiaomiMHOC303 final : public Component, public esp32_ble_tracker::ESPBTDev }; } // namespace esphome::xiaomi_mhoc303 - -#endif diff --git a/esphome/components/xiaomi_mhoc401/sensor.py b/esphome/components/xiaomi_mhoc401/sensor.py index 7161e88da5..4604af218e 100644 --- a/esphome/components/xiaomi_mhoc401/sensor.py +++ b/esphome/components/xiaomi_mhoc401/sensor.py @@ -1,5 +1,5 @@ import esphome.codegen as cg -from esphome.components import esp32_ble_tracker, sensor +from esphome.components import ble_device_base, sensor import esphome.config_validation as cv from esphome.const import ( CONF_BATTERY_LEVEL, @@ -18,15 +18,15 @@ from esphome.const import ( ) CODEOWNERS = ["@vevsvevs"] -DEPENDENCIES = ["esp32_ble_tracker"] -AUTO_LOAD = ["xiaomi_ble"] +AUTO_LOAD = ["ble_device_base", "xiaomi_ble"] xiaomi_mhoc401_ns = cg.esphome_ns.namespace("xiaomi_mhoc401") XiaomiMHOC401 = xiaomi_mhoc401_ns.class_( - "XiaomiMHOC401", esp32_ble_tracker.ESPBTDeviceListener, cg.Component + "XiaomiMHOC401", ble_device_base.ESPBTDeviceListener, cg.Component ) -CONFIG_SCHEMA = ( +CONFIG_SCHEMA = cv.All( + ble_device_base.rename_legacy_hub_id("xiaomi_mhoc401"), cv.Schema( { cv.GenerateID(): cv.declare_id(XiaomiMHOC401), @@ -53,15 +53,15 @@ CONFIG_SCHEMA = ( ), } ) - .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) .extend(cv.COMPONENT_SCHEMA) + .extend(ble_device_base.BLE_DEVICE_SCHEMA), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - await esp32_ble_tracker.register_ble_device(var, config) + await ble_device_base.register_ble_device(var, config) cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex)) cg.add(var.set_bindkey(config[CONF_BINDKEY])) diff --git a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp index 958ac59bde..d725978418 100644 --- a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp +++ b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp @@ -2,8 +2,6 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_mhoc401 { static const char *const TAG = "xiaomi_mhoc401"; @@ -21,7 +19,7 @@ void XiaomiMHOC401::dump_config() { LOG_SENSOR(" ", "Battery Level", this->battery_level_); } -bool XiaomiMHOC401::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { +bool XiaomiMHOC401::parse_device(const ble_device_base::ESPBTDevice &device) { if (device.address_uint64() != this->address_) { ESP_LOGVV(TAG, "parse_device(): unknown MAC address."); return false; @@ -69,5 +67,3 @@ bool XiaomiMHOC401::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiMHOC401::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } } // namespace esphome::xiaomi_mhoc401 - -#endif diff --git a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h index 3570f70a16..3978e557f0 100644 --- a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h +++ b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h @@ -2,19 +2,17 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" +#include "esphome/components/ble_device_base/ble_device.h" #include "esphome/components/xiaomi_ble/xiaomi_ble.h" -#ifdef USE_ESP32 - namespace esphome::xiaomi_mhoc401 { -class XiaomiMHOC401 final : public Component, public esp32_ble_tracker::ESPBTDeviceListener { +class XiaomiMHOC401 final : public Component, public ble_device_base::ESPBTDeviceListener { public: void set_address(uint64_t address) { address_ = address; }; void set_bindkey(const char *bindkey); - bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; + bool parse_device(const ble_device_base::ESPBTDevice &device) override; void dump_config() override; void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; } void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; } @@ -29,5 +27,3 @@ class XiaomiMHOC401 final : public Component, public esp32_ble_tracker::ESPBTDev }; } // namespace esphome::xiaomi_mhoc401 - -#endif diff --git a/tests/components/xiaomi_lywsdcgq/common-ln.yaml b/tests/components/xiaomi_lywsdcgq/common-ln.yaml new file mode 100644 index 0000000000..6a458a5b2a --- /dev/null +++ b/tests/components/xiaomi_lywsdcgq/common-ln.yaml @@ -0,0 +1,9 @@ +sensor: + - platform: xiaomi_lywsdcgq + mac_address: 7A:80:8E:19:36:BA + temperature: + name: Xiaomi LYWSDCGQ Temperature + humidity: + name: Xiaomi LYWSDCGQ Humidity + battery_level: + name: Xiaomi LYWSDCGQ Battery Level diff --git a/tests/components/xiaomi_lywsdcgq/common.yaml b/tests/components/xiaomi_lywsdcgq/common.yaml index d8422b4c0c..147b77c2d1 100644 --- a/tests/components/xiaomi_lywsdcgq/common.yaml +++ b/tests/components/xiaomi_lywsdcgq/common.yaml @@ -1,7 +1,10 @@ esp32_ble_tracker: + id: ble_tracker_hub sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. - platform: xiaomi_lywsdcgq + ble_hub_id: ble_tracker_hub mac_address: 7A:80:8E:19:36:BA temperature: name: Xiaomi LYWSDCGQ Temperature diff --git a/tests/components/xiaomi_lywsdcgq/test.ln882x-ard.yaml b/tests/components/xiaomi_lywsdcgq/test.ln882x-ard.yaml new file mode 100644 index 0000000000..48aa38be38 --- /dev/null +++ b/tests/components/xiaomi_lywsdcgq/test.ln882x-ard.yaml @@ -0,0 +1,3 @@ +packages: + ln882h_ble_tracker: !include ../ln882h_ble_tracker/common.yaml + xiaomi_lywsdcgq: !include common-ln.yaml diff --git a/tests/components/xiaomi_lywsdcgq/validate.bk72xx-ard.yaml b/tests/components/xiaomi_lywsdcgq/validate.bk72xx-ard.yaml new file mode 100644 index 0000000000..030f74afa3 --- /dev/null +++ b/tests/components/xiaomi_lywsdcgq/validate.bk72xx-ard.yaml @@ -0,0 +1,22 @@ +# Config-only: the CI base board (generic-bk7252, BLE 4.2) cannot compile the +# BLE 5.x tracker, so this fixture proves validation (schema + neutral binding) +# on a non-esp32 platform; codegen and compilation are not exercised here. +bk72xx_ble_tracker: + id: ble_tracker_hub + +sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. + - platform: xiaomi_lywsdcgq + ble_hub_id: ble_tracker_hub + mac_address: 7A:80:8E:19:36:BA + temperature: + name: Xiaomi LYWSDCGQ Temperature + humidity: + name: Xiaomi LYWSDCGQ Humidity + battery_level: + name: Xiaomi LYWSDCGQ Battery Level + # No ble_hub_id: exercises the generated binding real configs use. + - platform: xiaomi_lywsdcgq + mac_address: 7A:80:8E:19:36:BB + temperature: + name: BK Xiaomi LYWSDCGQ Implicit Temperature diff --git a/tests/components/xiaomi_mhoc303/common-ln.yaml b/tests/components/xiaomi_mhoc303/common-ln.yaml new file mode 100644 index 0000000000..ca89047a68 --- /dev/null +++ b/tests/components/xiaomi_mhoc303/common-ln.yaml @@ -0,0 +1,9 @@ +sensor: + - platform: xiaomi_mhoc303 + mac_address: E7:50:59:32:A0:1C + temperature: + name: MHO-C303 Temperature + humidity: + name: MHO-C303 Humidity + battery_level: + name: MHO-C303 Battery Level diff --git a/tests/components/xiaomi_mhoc303/common.yaml b/tests/components/xiaomi_mhoc303/common.yaml index e4353d3c6a..74c96fc26d 100644 --- a/tests/components/xiaomi_mhoc303/common.yaml +++ b/tests/components/xiaomi_mhoc303/common.yaml @@ -1,7 +1,10 @@ esp32_ble_tracker: + id: ble_tracker_hub sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. - platform: xiaomi_mhoc303 + ble_hub_id: ble_tracker_hub mac_address: E7:50:59:32:A0:1C temperature: name: MHO-C303 Temperature diff --git a/tests/components/xiaomi_mhoc303/test.ln882x-ard.yaml b/tests/components/xiaomi_mhoc303/test.ln882x-ard.yaml new file mode 100644 index 0000000000..6e927dafe8 --- /dev/null +++ b/tests/components/xiaomi_mhoc303/test.ln882x-ard.yaml @@ -0,0 +1,3 @@ +packages: + ln882h_ble_tracker: !include ../ln882h_ble_tracker/common.yaml + xiaomi_mhoc303: !include common-ln.yaml diff --git a/tests/components/xiaomi_mhoc303/validate.bk72xx-ard.yaml b/tests/components/xiaomi_mhoc303/validate.bk72xx-ard.yaml new file mode 100644 index 0000000000..5c7f29c98e --- /dev/null +++ b/tests/components/xiaomi_mhoc303/validate.bk72xx-ard.yaml @@ -0,0 +1,22 @@ +# Config-only: the CI base board (generic-bk7252, BLE 4.2) cannot compile the +# BLE 5.x tracker, so this fixture proves validation (schema + neutral binding) +# on a non-esp32 platform; codegen and compilation are not exercised here. +bk72xx_ble_tracker: + id: ble_tracker_hub + +sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. + - platform: xiaomi_mhoc303 + ble_hub_id: ble_tracker_hub + mac_address: E7:50:59:32:A0:1C + temperature: + name: MHO-C303 Temperature + humidity: + name: MHO-C303 Humidity + battery_level: + name: MHO-C303 Battery Level + # No ble_hub_id: exercises the generated binding real configs use. + - platform: xiaomi_mhoc303 + mac_address: E7:50:59:32:A0:1D + temperature: + name: BK MHO-C303 Implicit Temperature diff --git a/tests/components/xiaomi_mhoc401/common-ln.yaml b/tests/components/xiaomi_mhoc401/common-ln.yaml new file mode 100644 index 0000000000..43641f66d1 --- /dev/null +++ b/tests/components/xiaomi_mhoc401/common-ln.yaml @@ -0,0 +1,10 @@ +sensor: + - platform: xiaomi_mhoc401 + mac_address: E7:50:59:32:A0:1C + bindkey: eef418daf699a0c188f3bfd17e4565d9 + temperature: + name: MHO-C401 Temperature + humidity: + name: MHO-C401 Humidity + battery_level: + name: MHO-C401 Battery Level diff --git a/tests/components/xiaomi_mhoc401/common.yaml b/tests/components/xiaomi_mhoc401/common.yaml index ae378f5604..646961b3b6 100644 --- a/tests/components/xiaomi_mhoc401/common.yaml +++ b/tests/components/xiaomi_mhoc401/common.yaml @@ -1,12 +1,15 @@ esp32_ble_tracker: + id: ble_tracker_hub sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. - platform: xiaomi_mhoc401 + ble_hub_id: ble_tracker_hub mac_address: E7:50:59:32:A0:1C bindkey: "eef418daf699a0c188f3bfd17e4565d9" temperature: - name: MHO-C303 Temperature + name: MHO-C401 Temperature humidity: - name: MHO-C303 Humidity + name: MHO-C401 Humidity battery_level: - name: MHO-C303 Battery Level + name: MHO-C401 Battery Level diff --git a/tests/components/xiaomi_mhoc401/test.ln882x-ard.yaml b/tests/components/xiaomi_mhoc401/test.ln882x-ard.yaml new file mode 100644 index 0000000000..a20f24671d --- /dev/null +++ b/tests/components/xiaomi_mhoc401/test.ln882x-ard.yaml @@ -0,0 +1,3 @@ +packages: + ln882h_ble_tracker: !include ../ln882h_ble_tracker/common.yaml + xiaomi_mhoc401: !include common-ln.yaml diff --git a/tests/components/xiaomi_mhoc401/validate.bk72xx-ard.yaml b/tests/components/xiaomi_mhoc401/validate.bk72xx-ard.yaml new file mode 100644 index 0000000000..f7a2bd3e4f --- /dev/null +++ b/tests/components/xiaomi_mhoc401/validate.bk72xx-ard.yaml @@ -0,0 +1,24 @@ +# Config-only: the CI base board (generic-bk7252, BLE 4.2) cannot compile the +# BLE 5.x tracker, so this fixture proves validation (schema + neutral binding) +# on a non-esp32 platform; codegen and compilation are not exercised here. +bk72xx_ble_tracker: + id: ble_tracker_hub + +sensor: + # Explicit ble_hub_id: pins the neutral binding as a declared key. + - platform: xiaomi_mhoc401 + ble_hub_id: ble_tracker_hub + mac_address: E7:50:59:32:A0:1C + bindkey: "eef418daf699a0c188f3bfd17e4565d9" + temperature: + name: MHO-C401 Temperature + humidity: + name: MHO-C401 Humidity + battery_level: + name: MHO-C401 Battery Level + # No ble_hub_id: exercises the generated binding real configs use. + - platform: xiaomi_mhoc401 + mac_address: E7:50:59:32:A0:1D + bindkey: eef418daf699a0c188f3bfd17e4565d9 + temperature: + name: BK MHO-C401 Implicit Temperature