From bbf7c926ea639a9dbadc8f1752428bf1d253f076 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 21 Oct 2024 12:20:19 +0200 Subject: [PATCH] Use binary_sensor_schema (#192) --- .../soyosource_display/binary_sensor.py | 19 +++++-------------- .../soyosource_inverter/binary_sensor.py | 11 +++-------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/components/soyosource_display/binary_sensor.py b/components/soyosource_display/binary_sensor.py index 55b9e37..99188ad 100644 --- a/components/soyosource_display/binary_sensor.py +++ b/components/soyosource_display/binary_sensor.py @@ -1,7 +1,7 @@ import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv -from esphome.const import CONF_ICON, CONF_ID +from esphome.const import CONF_ID from . import CONF_SOYOSOURCE_DISPLAY_ID, SoyosourceDisplay @@ -12,9 +12,6 @@ CONF_FAN_RUNNING = "fan_running" CONF_LIMITER_CONNECTED = "limiter_connected" -ICON_FAN_RUNNING = "mdi:fan" -ICON_LIMITER_CONNECTED = "mdi:connection" - BINARY_SENSORS = [ CONF_FAN_RUNNING, CONF_LIMITER_CONNECTED, @@ -23,17 +20,11 @@ CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(CONF_SOYOSOURCE_DISPLAY_ID): cv.use_id(SoyosourceDisplay), - cv.Optional(CONF_FAN_RUNNING): binary_sensor.BINARY_SENSOR_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), - cv.Optional(CONF_ICON, default=ICON_FAN_RUNNING): cv.icon, - } + cv.Optional(CONF_FAN_RUNNING): binary_sensor.binary_sensor_schema( + icon="mdi:fan" ), - cv.Optional(CONF_LIMITER_CONNECTED): binary_sensor.BINARY_SENSOR_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), - cv.Optional(CONF_ICON, default=ICON_LIMITER_CONNECTED): cv.icon, - } + cv.Optional(CONF_LIMITER_CONNECTED): binary_sensor.binary_sensor_schema( + icon="mdi:connection" ), } ) diff --git a/components/soyosource_inverter/binary_sensor.py b/components/soyosource_inverter/binary_sensor.py index 32ba5df..873b7a4 100644 --- a/components/soyosource_inverter/binary_sensor.py +++ b/components/soyosource_inverter/binary_sensor.py @@ -1,7 +1,7 @@ import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv -from esphome.const import CONF_ICON, CONF_ID +from esphome.const import CONF_ID from . import CONF_SOYOSOURCE_INVERTER_ID, SoyosourceInverter @@ -11,8 +11,6 @@ CONF_FAN_RUNNING = "fan_running" -ICON_FAN_RUNNING = "mdi:fan" - BINARY_SENSORS = [ CONF_FAN_RUNNING, ] @@ -20,11 +18,8 @@ CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(CONF_SOYOSOURCE_INVERTER_ID): cv.use_id(SoyosourceInverter), - cv.Optional(CONF_FAN_RUNNING): binary_sensor.BINARY_SENSOR_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), - cv.Optional(CONF_ICON, default=ICON_FAN_RUNNING): cv.icon, - } + cv.Optional(CONF_FAN_RUNNING): binary_sensor.binary_sensor_schema( + icon="mdi:fan" ), } )