From cdbbfa47a0bd8cf9fbae4f41bf5c0311b93454c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Koek?= Date: Tue, 26 Mar 2024 18:40:02 +0000 Subject: [PATCH] try this --- esphome/components/lora/__init__.py | 13 ++++++++++--- esphome/components/lora/lora.h | 3 +++ esphome/components/lora/switch/__init__.py | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/esphome/components/lora/__init__.py b/esphome/components/lora/__init__.py index c11fd37506..cf623e1dd9 100644 --- a/esphome/components/lora/__init__.py +++ b/esphome/components/lora/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome import pins -from esphome.components import sensor, text_sensor, uart +from esphome.components import sensor, text_sensor, uart, pcf8574 + from esphome.const import ( DEVICE_CLASS_SIGNAL_STRENGTH, UNIT_DECIBEL_MILLIWATT, @@ -14,17 +15,18 @@ DEPENDENCIES = ["uart"] AUTO_LOAD = ["uart", "sensor", "text_sensor"] lora_ns = cg.esphome_ns.namespace("lora") -Lora = lora_ns.class_("Lora", cg.PollingComponent, uart.UARTDevice) +LoraComponent = lora_ns.class_("Lora", cg.PollingComponent, uart.UARTDevice) CONF_PIN_AUX = "pin_aux" CONF_PIN_M0 = "pin_m0" CONF_PIN_M1 = "pin_m1" +CONF_PCF8574 = "pcf8574" CONF_LORA_MESSAGE = "lora_message" CONF_LORA_RSSI = "lora_rssi" CONF_LORA = "lora" CONFIG_SCHEMA = ( cv.Schema( { - cv.GenerateID(): cv.declare_id(Lora), + cv.GenerateID(): cv.declare_id(LoraComponent), # for communication to let us know that we can receive data cv.Required(CONF_PIN_AUX): pins.gpio_input_pin_schema, # for communication set the mode @@ -35,6 +37,7 @@ CONFIG_SCHEMA = ( cv.Optional(CONF_LORA_MESSAGE): text_sensor.text_sensor_schema( entity_category=ENTITY_CATEGORY_NONE, ), + cv.Optional(CONF_PCF8574): cv.use_id(pcf8574.PCF8574Component), # if you want to see the rssi cv.Optional(CONF_LORA_RSSI): sensor.sensor_schema( device_class=DEVICE_CLASS_SIGNAL_STRENGTH, @@ -66,6 +69,10 @@ async def to_code(config): sens = await text_sensor.new_text_sensor(config[CONF_LORA_MESSAGE]) cg.add(var.set_message_sensor(sens)) + if CONF_LORA_MESSAGE in config: + comp = await cg.get_variable(config[CONF_PCF8574]) + cg.add(var.set_pcf8574(comp)) + if CONF_LORA_RSSI in config: sens = await sensor.new_sensor(config[CONF_LORA_RSSI]) cg.add(var.set_rssi_sensor(sens)) diff --git a/esphome/components/lora/lora.h b/esphome/components/lora/lora.h index 0fb0a8b1e8..2c124f0698 100644 --- a/esphome/components/lora/lora.h +++ b/esphome/components/lora/lora.h @@ -2,6 +2,7 @@ #include #include #include "esphome/core/component.h" +#include "esphome/components/pcf8574/pcf8574.h" #include "esphome/components/sensor/sensor.h" #include "esphome/components/text_sensor/text_sensor.h" #include "esphome/core/helpers.h" @@ -40,6 +41,7 @@ class Lora : public PollingComponent, public uart::UARTDevice { void set_pin_aux(GPIOPin *pin_aux) { pin_aux_ = pin_aux; } void set_pin_m0(GPIOPin *pin_m0) { pin_m0_ = pin_m0; } void set_pin_m1(GPIOPin *pin_m1) { pin_m1_ = pin_m1; } + void set_pcf8574(pcf8574::PCF8574Component *pcf8574) { pcf8574_ = pcf8574; } private: ModeType mode_ = MODE_INIT; @@ -64,6 +66,7 @@ class Lora : public PollingComponent, public uart::UARTDevice { GPIOPin *pin_aux_; GPIOPin *pin_m0_; GPIOPin *pin_m1_; + pcf8574::PCF8574Component *pcf8574_{nullptr}; }; } // namespace lora diff --git a/esphome/components/lora/switch/__init__.py b/esphome/components/lora/switch/__init__.py index 92ae48c22a..1b0230baf1 100644 --- a/esphome/components/lora/switch/__init__.py +++ b/esphome/components/lora/switch/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import switch -from .. import CONF_LORA, Lora, lora_ns +from .. import CONF_LORA, LoraComponent, lora_ns LoraSwitch = lora_ns.class_("LoraSwitch", switch.Switch, cg.Component) @@ -10,7 +10,7 @@ CONFIG_SCHEMA = ( switch.switch_schema(LoraSwitch, block_inverted=True) .extend( { - cv.Required(CONF_LORA): cv.use_id(Lora), + cv.Required(CONF_LORA): cv.use_id(LoraComponent), cv.Required(PIN_TO_SEND): cv.int_range(min=1, max=256), } )