mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 02:04:13 +01:00
commit
288e3c3e3e
7 changed files with 62 additions and 64 deletions
|
@ -58,7 +58,7 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
|
|||
case MATCH_BY_SERVICE_UUID:
|
||||
for (auto uuid : device.get_service_uuids()) {
|
||||
if (this->uuid_ == uuid) {
|
||||
this->publish_state(device.get_rssi());
|
||||
this->publish_state(true);
|
||||
this->found_ = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
|
|||
return false;
|
||||
}
|
||||
|
||||
this->publish_state(device.get_rssi());
|
||||
this->publish_state(true);
|
||||
this->found_ = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,16 +26,9 @@ bool BluetoothProxy::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
|
|||
device.get_rssi());
|
||||
this->send_api_packet_(device);
|
||||
|
||||
this->address_type_map_[device.address_uint64()] = device.get_address_type();
|
||||
|
||||
if (this->address_ == 0)
|
||||
return true;
|
||||
|
||||
if (this->state_ == espbt::ClientState::DISCOVERED) {
|
||||
ESP_LOGV(TAG, "Connecting to address %s", this->address_str().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
BLEClientBase::parse_device(device);
|
||||
return true;
|
||||
}
|
||||
|
@ -216,20 +209,6 @@ void BluetoothProxy::bluetooth_device_request(const api::BluetoothDeviceRequest
|
|||
switch (msg.request_type) {
|
||||
case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT: {
|
||||
this->address_ = msg.address;
|
||||
if (this->address_type_map_.find(this->address_) != this->address_type_map_.end()) {
|
||||
// Utilise the address type cache
|
||||
this->remote_addr_type_ = this->address_type_map_[this->address_];
|
||||
} else {
|
||||
this->remote_addr_type_ = BLE_ADDR_TYPE_PUBLIC;
|
||||
}
|
||||
this->remote_bda_[0] = (this->address_ >> 40) & 0xFF;
|
||||
this->remote_bda_[1] = (this->address_ >> 32) & 0xFF;
|
||||
this->remote_bda_[2] = (this->address_ >> 24) & 0xFF;
|
||||
this->remote_bda_[3] = (this->address_ >> 16) & 0xFF;
|
||||
this->remote_bda_[4] = (this->address_ >> 8) & 0xFF;
|
||||
this->remote_bda_[5] = (this->address_ >> 0) & 0xFF;
|
||||
this->set_state(espbt::ClientState::DISCOVERED);
|
||||
esp_ble_gap_stop_scanning();
|
||||
break;
|
||||
}
|
||||
case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT: {
|
||||
|
|
|
@ -45,7 +45,6 @@ class BluetoothProxy : public BLEClientBase {
|
|||
protected:
|
||||
void send_api_packet_(const esp32_ble_tracker::ESPBTDevice &device);
|
||||
|
||||
std::map<uint64_t, esp_ble_addr_type_t> address_type_map_;
|
||||
int16_t send_service_{-1};
|
||||
bool active_;
|
||||
};
|
||||
|
|
|
@ -571,24 +571,16 @@ int64_t payload_to_number(const std::vector<uint8_t> &data, SensorValueType sens
|
|||
static_cast<int32_t>(((value & 0x7FFF) << 16 | (value & 0xFFFF0000) >> 16) | sign_bit), bitmask);
|
||||
} break;
|
||||
case SensorValueType::U_QWORD:
|
||||
// Ignore bitmask for U_QWORD
|
||||
value = get_data<uint64_t>(data, offset);
|
||||
break;
|
||||
case SensorValueType::S_QWORD:
|
||||
// Ignore bitmask for S_QWORD
|
||||
value = get_data<int64_t>(data, offset);
|
||||
// Ignore bitmask for QWORD
|
||||
value = get_data<uint64_t>(data, offset);
|
||||
break;
|
||||
case SensorValueType::U_QWORD_R:
|
||||
// Ignore bitmask for U_QWORD
|
||||
value = get_data<uint64_t>(data, offset);
|
||||
value = static_cast<uint64_t>(value & 0xFFFF) << 48 | (value & 0xFFFF000000000000) >> 48 |
|
||||
static_cast<uint64_t>(value & 0xFFFF0000) << 32 | (value & 0x0000FFFF00000000) >> 32 |
|
||||
static_cast<uint64_t>(value & 0xFFFF00000000) << 16 | (value & 0x00000000FFFF0000) >> 16;
|
||||
break;
|
||||
case SensorValueType::S_QWORD_R:
|
||||
// Ignore bitmask for S_QWORD
|
||||
value = get_data<int64_t>(data, offset);
|
||||
break;
|
||||
case SensorValueType::S_QWORD_R: {
|
||||
// Ignore bitmask for QWORD
|
||||
uint64_t tmp = get_data<uint64_t>(data, offset);
|
||||
value = (tmp << 48) | (tmp >> 48) | ((tmp & 0xFFFF0000) << 16) | ((tmp >> 16) & 0xFFFF0000);
|
||||
} break;
|
||||
case SensorValueType::RAW:
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -974,9 +974,19 @@ void ThermostatClimate::change_preset_(climate::ClimatePreset preset) {
|
|||
auto config = this->preset_config_.find(preset);
|
||||
|
||||
if (config != this->preset_config_.end()) {
|
||||
ESP_LOGI(TAG, "Switching to preset %s", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
|
||||
this->change_preset_internal_(config->second);
|
||||
ESP_LOGI(TAG, "Preset %s requested", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
|
||||
if (this->change_preset_internal_(config->second) || (!this->preset.has_value()) ||
|
||||
this->preset.value() != preset) {
|
||||
// Fire any preset changed trigger if defined
|
||||
Trigger<> *trig = this->preset_change_trigger_;
|
||||
assert(trig != nullptr);
|
||||
trig->trigger();
|
||||
|
||||
this->refresh();
|
||||
ESP_LOGI(TAG, "Preset %s applied", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
|
||||
} else {
|
||||
ESP_LOGI(TAG, "No changes required to apply preset %s", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
|
||||
}
|
||||
this->custom_preset.reset();
|
||||
this->preset = preset;
|
||||
} else {
|
||||
|
@ -988,9 +998,19 @@ void ThermostatClimate::change_custom_preset_(const std::string &custom_preset)
|
|||
auto config = this->custom_preset_config_.find(custom_preset);
|
||||
|
||||
if (config != this->custom_preset_config_.end()) {
|
||||
ESP_LOGI(TAG, "Switching to custom preset %s", custom_preset.c_str());
|
||||
this->change_preset_internal_(config->second);
|
||||
ESP_LOGI(TAG, "Custom preset %s requested", custom_preset.c_str());
|
||||
if (this->change_preset_internal_(config->second) || (!this->custom_preset.has_value()) ||
|
||||
this->custom_preset.value() != custom_preset) {
|
||||
// Fire any preset changed trigger if defined
|
||||
Trigger<> *trig = this->preset_change_trigger_;
|
||||
assert(trig != nullptr);
|
||||
trig->trigger();
|
||||
|
||||
this->refresh();
|
||||
ESP_LOGI(TAG, "Custom preset %s applied", custom_preset.c_str());
|
||||
} else {
|
||||
ESP_LOGI(TAG, "No changes required to apply custom preset %s", custom_preset.c_str());
|
||||
}
|
||||
this->preset.reset();
|
||||
this->custom_preset = custom_preset;
|
||||
} else {
|
||||
|
@ -998,39 +1018,46 @@ void ThermostatClimate::change_custom_preset_(const std::string &custom_preset)
|
|||
}
|
||||
}
|
||||
|
||||
void ThermostatClimate::change_preset_internal_(const ThermostatClimateTargetTempConfig &config) {
|
||||
bool ThermostatClimate::change_preset_internal_(const ThermostatClimateTargetTempConfig &config) {
|
||||
bool something_changed = false;
|
||||
|
||||
if (this->supports_two_points_) {
|
||||
this->target_temperature_low = config.default_temperature_low;
|
||||
this->target_temperature_high = config.default_temperature_high;
|
||||
if (this->target_temperature_low != config.default_temperature_low) {
|
||||
this->target_temperature_low = config.default_temperature_low;
|
||||
something_changed = true;
|
||||
}
|
||||
if (this->target_temperature_high != config.default_temperature_high) {
|
||||
this->target_temperature_high = config.default_temperature_high;
|
||||
something_changed = true;
|
||||
}
|
||||
} else {
|
||||
this->target_temperature = config.default_temperature;
|
||||
if (this->target_temperature != config.default_temperature) {
|
||||
this->target_temperature = config.default_temperature;
|
||||
something_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Note: The mode, fan_mode, and swing_mode can all be defined on the preset but if the climate.control call
|
||||
// also specifies them then the control's version will override these for that call
|
||||
if (config.mode_.has_value()) {
|
||||
this->mode = *config.mode_;
|
||||
// Note: The mode, fan_mode and swing_mode can all be defined in the preset but if the climate.control call
|
||||
// also specifies them then the climate.control call's values will override the preset's values for that call
|
||||
if (config.mode_.has_value() && (this->mode != config.mode_.value())) {
|
||||
ESP_LOGV(TAG, "Setting mode to %s", LOG_STR_ARG(climate::climate_mode_to_string(*config.mode_)));
|
||||
this->mode = *config.mode_;
|
||||
something_changed = true;
|
||||
}
|
||||
|
||||
if (config.fan_mode_.has_value()) {
|
||||
this->fan_mode = *config.fan_mode_;
|
||||
if (config.fan_mode_.has_value() && (this->fan_mode != config.fan_mode_.value())) {
|
||||
ESP_LOGV(TAG, "Setting fan mode to %s", LOG_STR_ARG(climate::climate_fan_mode_to_string(*config.fan_mode_)));
|
||||
this->fan_mode = *config.fan_mode_;
|
||||
something_changed = true;
|
||||
}
|
||||
|
||||
if (config.swing_mode_.has_value()) {
|
||||
if (config.swing_mode_.has_value() && (this->swing_mode != config.swing_mode_.value())) {
|
||||
ESP_LOGV(TAG, "Setting swing mode to %s", LOG_STR_ARG(climate::climate_swing_mode_to_string(*config.swing_mode_)));
|
||||
this->swing_mode = *config.swing_mode_;
|
||||
something_changed = true;
|
||||
}
|
||||
|
||||
// Fire any preset changed trigger if defined
|
||||
if (this->preset != preset) {
|
||||
Trigger<> *trig = this->preset_change_trigger_;
|
||||
assert(trig != nullptr);
|
||||
trig->trigger();
|
||||
}
|
||||
|
||||
this->refresh();
|
||||
return something_changed;
|
||||
}
|
||||
|
||||
void ThermostatClimate::set_preset_config(climate::ClimatePreset preset,
|
||||
|
|
|
@ -168,7 +168,8 @@ class ThermostatClimate : public climate::Climate, public Component {
|
|||
|
||||
/// Applies the temperature, mode, fan, and swing modes of the provided config.
|
||||
/// This is agnostic of custom vs built in preset
|
||||
void change_preset_internal_(const ThermostatClimateTargetTempConfig &config);
|
||||
/// Returns true if something was changed
|
||||
bool change_preset_internal_(const ThermostatClimateTargetTempConfig &config);
|
||||
|
||||
/// Return the traits of this controller.
|
||||
climate::ClimateTraits traits() override;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2022.10.0b1"
|
||||
__version__ = "2022.10.0b2"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
|
||||
|
|
Loading…
Reference in a new issue