From 818aeb189c897ed618d6e7e57f25e47dc052ed35 Mon Sep 17 00:00:00 2001 From: Dotsch2005 <3149448+Dotsch2005@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:49:35 +0200 Subject: [PATCH] Change binary sensor to sensor --- .../components/radon_eye_rd200/radon_eye_rd200.cpp | 5 ++--- esphome/components/radon_eye_rd200/radon_eye_rd200.h | 5 ++--- esphome/components/radon_eye_rd200/sensor.py | 12 ++++++++---- tests/components/radon_eye_rd200/common.yaml | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp b/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp index 228e64bd46..637546bf59 100644 --- a/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp +++ b/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp @@ -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!"); diff --git a/esphome/components/radon_eye_rd200/radon_eye_rd200.h b/esphome/components/radon_eye_rd200/radon_eye_rd200.h index 01e2e29934..98f3e04dda 100644 --- a/esphome/components/radon_eye_rd200/radon_eye_rd200.h +++ b/esphome/components/radon_eye_rd200/radon_eye_rd200.h @@ -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}; diff --git a/esphome/components/radon_eye_rd200/sensor.py b/esphome/components/radon_eye_rd200/sensor.py index 7f43e75eda..b7f9ccdd5e 100644 --- a/esphome/components/radon_eye_rd200/sensor.py +++ b/esphome/components/radon_eye_rd200/sensor.py @@ -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]) diff --git a/tests/components/radon_eye_rd200/common.yaml b/tests/components/radon_eye_rd200/common.yaml index ce2d6e0398..442d69dfe9 100644 --- a/tests/components/radon_eye_rd200/common.yaml +++ b/tests/components/radon_eye_rd200/common.yaml @@ -19,5 +19,5 @@ sensor: radon_peak: name: RD200 Radon Peak alarm: - name: Alarm + name: RD200 Radon Alarm update_interval: 10min