Formatting

This commit is contained in:
Avishay Orpaz 2024-08-15 12:25:31 +03:00
parent 89fcaa3b40
commit 2b0b875a5e
3 changed files with 13 additions and 20 deletions

View file

@ -48,7 +48,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_MIN_RSSI): cv.All(
cv.decibel, cv.int_range(min=-100, max=-30)
),
cv.Optional(CONF_MIN_RSSI_NUMBER_ID): cv.use_id(Number)
cv.Optional(CONF_MIN_RSSI_NUMBER_ID): cv.use_id(Number),
}
)
.extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
@ -56,9 +56,7 @@ CONFIG_SCHEMA = cv.All(
cv.has_exactly_one_key(
CONF_MAC_ADDRESS, CONF_IRK, CONF_SERVICE_UUID, CONF_IBEACON_UUID
),
cv.has_at_most_one_key(
CONF_MIN_RSSI, CONF_MIN_RSSI_NUMBER_ID
),
cv.has_at_most_one_key(CONF_MIN_RSSI, CONF_MIN_RSSI_NUMBER_ID),
_validate,
)

View file

@ -11,20 +11,19 @@ static const char *const TAG = "ble_presence";
void BLEPresenceDevice::dump_config() { LOG_BINARY_SENSOR("", "BLE Presence", this); }
void BLEPresenceDevice::set_minimum_rssi_input(number::Number *min_rssi_number) {
min_rssi_number->add_on_state_callback([this](float state) {
int rssi = int(state);
if (rssi < -100 || rssi > -30) {
ESP_LOGW(TAG, "Valid RSSI range is -30dB to -100dB");
return;
}
ESP_LOGI(TAG, "Setting minimum rssi to %d", rssi);
this->set_minimum_rssi_(int(state));
});
min_rssi_number->add_on_state_callback([this](float state) {
int rssi = int(state);
if (rssi < -100 || rssi > -30) {
ESP_LOGW(TAG, "Valid RSSI range is -30dB to -100dB");
return;
}
ESP_LOGI(TAG, "Setting minimum rssi to %d", rssi);
this->set_minimum_rssi_(int(state));
});
this->check_minimum_rssi_ = true;
this->check_minimum_rssi_ = true;
}
} // namespace ble_presence
} // namespace esphome

View file

@ -5,7 +5,6 @@
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/components/number/number.h"
#ifdef USE_ESP32
namespace esphome {
@ -113,9 +112,7 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void set_minimum_rssi_(int rssi) {
this->minimum_rssi_ = rssi;
}
void set_minimum_rssi_(int rssi) { this->minimum_rssi_ = rssi; }
void set_found_(bool state) {
this->found_ = state;
@ -144,7 +141,6 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
bool found_{false};
uint32_t last_seen_{};
uint32_t timeout_{};
};
} // namespace ble_presence