mirror of
https://github.com/esphome/esphome.git
synced 2025-01-05 20:31:44 +01:00
Change binary sensor to sensor
This commit is contained in:
parent
8358235ac5
commit
818aeb189c
4 changed files with 13 additions and 11 deletions
|
@ -91,11 +91,10 @@ void RadonEyeRD200::handle_status_response_(const uint8_t *response, uint16_t le
|
|||
if (alarm_sensor_ != nullptr) {
|
||||
ESP_LOGD(TAG, " Sensor alarm send!");
|
||||
if (data->alarm != 0) {
|
||||
alarm_sensor_->publish_state(true);
|
||||
alarm_sensor_->publish_state(1);
|
||||
} else {
|
||||
alarm_sensor_->publish_state(false);
|
||||
alarm_sensor_->publish_state(0);
|
||||
}
|
||||
|
||||
delay(25);
|
||||
} else {
|
||||
ESP_LOGI(TAG, " Sensor alarm not exists!");
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "esphome/components/ble_client/ble_client.h"
|
||||
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
@ -67,7 +66,7 @@ class RadonEyeRD200 : public PollingComponent, public ble_client::BLEClientNode
|
|||
esp_ble_gattc_cb_param_t *param) override;
|
||||
|
||||
void set_version(int version) { radon_version_ = version; }
|
||||
void set_alarm(binary_sensor::BinarySensor *alarm) { alarm_sensor_ = alarm; }
|
||||
void set_alarm(sensor::Sensor *alarm) { alarm_sensor_ = alarm; }
|
||||
void set_radon(sensor::Sensor *radon) { radon_sensor_ = radon; }
|
||||
void set_radon_day_avg(sensor::Sensor *radon_day_avg) { radon_day_avg_ = radon_day_avg; }
|
||||
void set_radon_long_term(sensor::Sensor *radon_long_term) { radon_long_term_sensor_ = radon_long_term; }
|
||||
|
@ -88,7 +87,7 @@ class RadonEyeRD200 : public PollingComponent, public ble_client::BLEClientNode
|
|||
void request_read_values_();
|
||||
|
||||
int radon_version_{1};
|
||||
binary_sensor::BinarySensor *alarm_sensor_{nullptr};
|
||||
sensor::Sensor *alarm_sensor_{nullptr};
|
||||
sensor::Sensor *radon_sensor_{nullptr};
|
||||
sensor::Sensor *radon_day_avg_{nullptr};
|
||||
sensor::Sensor *radon_long_term_sensor_{nullptr};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor, ble_client, sensor
|
||||
from esphome.components import ble_client, sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_ALARM,
|
||||
|
@ -13,9 +13,10 @@ from esphome.const import (
|
|||
ICON_RADIOACTIVE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_BECQUEREL_PER_CUBIC_METER,
|
||||
UNIT_EMPTY,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["ble_client", "binary_sensor"]
|
||||
DEPENDENCIES = ["ble_client"]
|
||||
|
||||
radon_eye_rd200_ns = cg.esphome_ns.namespace("radon_eye_rd200")
|
||||
RadonEyeRD200 = radon_eye_rd200_ns.class_(
|
||||
|
@ -27,8 +28,11 @@ CONFIG_SCHEMA = cv.All(
|
|||
{
|
||||
cv.GenerateID(): cv.declare_id(RadonEyeRD200),
|
||||
cv.Optional(CONF_VERSION, default=1): cv.int_range(1, 3),
|
||||
cv.Optional(CONF_ALARM, default=0): binary_sensor.binary_sensor_schema(
|
||||
cv.Optional(CONF_ALARM): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_EMPTY,
|
||||
icon=ICON_ALARM_LIGHT,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_RADON): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_BECQUEREL_PER_CUBIC_METER,
|
||||
|
@ -70,7 +74,7 @@ async def to_code(config):
|
|||
cg.add(var.set_version(config[CONF_VERSION]))
|
||||
|
||||
if CONF_ALARM in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_ALARM])
|
||||
sens = await sensor.new_sensor(config[CONF_ALARM])
|
||||
cg.add(var.set_alarm(sens))
|
||||
if CONF_RADON in config:
|
||||
sens = await sensor.new_sensor(config[CONF_RADON])
|
||||
|
|
|
@ -19,5 +19,5 @@ sensor:
|
|||
radon_peak:
|
||||
name: RD200 Radon Peak
|
||||
alarm:
|
||||
name: Alarm
|
||||
name: RD200 Radon Alarm
|
||||
update_interval: 10min
|
||||
|
|
Loading…
Reference in a new issue