mirror of
https://github.com/esphome/esphome.git
synced 2026-08-23 06:36:23 +00:00
[ble_device_base] Advertise runtime scan-mode switching in HubCapabilities (#18079)
This commit is contained in:
@@ -29,7 +29,7 @@ class DefaultHub : public BLEHub {
|
||||
|
||||
class SwitchingHub : public DefaultHub {
|
||||
public:
|
||||
HubCapabilities get_capabilities() const override { return {true, false, false}; }
|
||||
HubCapabilities get_capabilities() const override { return {true, false, false, /* scan_mode_switch = */ true}; }
|
||||
bool request_scan_mode(bool active) override {
|
||||
this->active_ = active;
|
||||
return true;
|
||||
@@ -57,6 +57,7 @@ TEST(BLEHubScanModeRequest, DefaultRefusesAndChangesNothing) {
|
||||
|
||||
TEST(BLEHubScanModeRequest, OverrideHonorsAndApplies) {
|
||||
SwitchingHub hub;
|
||||
EXPECT_TRUE(hub.get_capabilities().scan_mode_switch);
|
||||
EXPECT_TRUE(hub.request_scan_mode(true));
|
||||
EXPECT_TRUE(hub.scan_active());
|
||||
EXPECT_TRUE(hub.request_scan_mode(false));
|
||||
@@ -66,6 +67,8 @@ TEST(BLEHubScanModeRequest, OverrideHonorsAndApplies) {
|
||||
TEST(BLEHubScanModeRequest, CapabilityAndSwitchAreIndependent) {
|
||||
CapableRefusingHub hub;
|
||||
EXPECT_TRUE(hub.get_capabilities().active_scan);
|
||||
// The esp32 shape advertises no runtime switch, and the request refuses.
|
||||
EXPECT_FALSE(hub.get_capabilities().scan_mode_switch);
|
||||
EXPECT_FALSE(hub.request_scan_mode(false));
|
||||
EXPECT_TRUE(hub.scan_active());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user