mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
atc mithermometer: Add possibility to report signal strength (#3000)
This commit is contained in:
parent
ed5930e934
commit
3067e482fc
4 changed files with 18 additions and 0 deletions
|
@ -45,6 +45,8 @@ bool ATCMiThermometer::parse_device(const esp32_ble_tracker::ESPBTDevice &device
|
|||
this->battery_voltage_->publish_state(*res->battery_voltage);
|
||||
success = true;
|
||||
}
|
||||
if (this->signal_strength_ != nullptr)
|
||||
this->signal_strength_->publish_state(device.get_rssi());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class ATCMiThermometer : public Component, public esp32_ble_tracker::ESPBTDevice
|
|||
void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
|
||||
void set_battery_level(sensor::Sensor *battery_level) { battery_level_ = battery_level; }
|
||||
void set_battery_voltage(sensor::Sensor *battery_voltage) { battery_voltage_ = battery_voltage; }
|
||||
void set_signal_strength(sensor::Sensor *signal_strength) { signal_strength_ = signal_strength; }
|
||||
|
||||
protected:
|
||||
uint64_t address_;
|
||||
|
@ -35,6 +36,7 @@ class ATCMiThermometer : public Component, public esp32_ble_tracker::ESPBTDevice
|
|||
sensor::Sensor *humidity_{nullptr};
|
||||
sensor::Sensor *battery_level_{nullptr};
|
||||
sensor::Sensor *battery_voltage_{nullptr};
|
||||
sensor::Sensor *signal_strength_{nullptr};
|
||||
|
||||
optional<ParseResult> parse_header_(const esp32_ble_tracker::ServiceData &service_data);
|
||||
bool parse_message_(const std::vector<uint8_t> &message, ParseResult &result);
|
||||
|
|
|
@ -6,15 +6,18 @@ from esphome.const import (
|
|||
CONF_BATTERY_VOLTAGE,
|
||||
CONF_MAC_ADDRESS,
|
||||
CONF_HUMIDITY,
|
||||
CONF_SIGNAL_STRENGTH,
|
||||
CONF_TEMPERATURE,
|
||||
CONF_ID,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_DECIBEL_MILLIWATT,
|
||||
UNIT_PERCENT,
|
||||
UNIT_VOLT,
|
||||
)
|
||||
|
@ -59,6 +62,13 @@ CONFIG_SCHEMA = (
|
|||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional(CONF_SIGNAL_STRENGTH): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
|
||||
accuracy_decimals=0,
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
|
||||
|
@ -85,3 +95,6 @@ async def to_code(config):
|
|||
if CONF_BATTERY_VOLTAGE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_BATTERY_VOLTAGE])
|
||||
cg.add(var.set_battery_voltage(sens))
|
||||
if CONF_SIGNAL_STRENGTH in config:
|
||||
sens = await sensor.new_sensor(config[CONF_SIGNAL_STRENGTH])
|
||||
cg.add(var.set_signal_strength(sens))
|
||||
|
|
|
@ -599,6 +599,7 @@ CONF_SHOW_VALUES = "show_values"
|
|||
CONF_SHUNT_RESISTANCE = "shunt_resistance"
|
||||
CONF_SHUNT_VOLTAGE = "shunt_voltage"
|
||||
CONF_SHUTDOWN_MESSAGE = "shutdown_message"
|
||||
CONF_SIGNAL_STRENGTH = "signal_strength"
|
||||
CONF_SINGLE_LIGHT_ID = "single_light_id"
|
||||
CONF_SIZE = "size"
|
||||
CONF_SLEEP_DURATION = "sleep_duration"
|
||||
|
|
Loading…
Reference in a new issue