mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
try this
This commit is contained in:
parent
bf59739ebf
commit
cdbbfa47a0
3 changed files with 15 additions and 5 deletions
|
@ -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))
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
#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
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue