mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 07:58:09 +01:00
removed the component from Sensor, making it top level
This commit is contained in:
parent
de51ae76f4
commit
3a8c7a6d13
3 changed files with 86 additions and 86 deletions
|
@ -1 +1,86 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome import automation, pins
|
||||||
|
from esphome.components import sensor
|
||||||
|
from esphome.components import spi
|
||||||
|
from esphome.automation import maybe_simple_id
|
||||||
|
from esphome.const import (
|
||||||
|
CONF_ID,
|
||||||
|
CONF_FREQUENCY,
|
||||||
|
UNIT_EMPTY,
|
||||||
|
UNIT_DECIBEL_MILLIWATT,
|
||||||
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
)
|
||||||
|
|
||||||
|
DEPENDENCIES = ["spi"]
|
||||||
|
|
||||||
CODEOWNERS = ["@gabest11"]
|
CODEOWNERS = ["@gabest11"]
|
||||||
|
|
||||||
|
CONF_GDO0 = "gdo0"
|
||||||
|
CONF_BANDWIDTH = "bandwidth"
|
||||||
|
# CONF_FREQUENCY = "frequency"
|
||||||
|
CONF_RSSI = "rssi"
|
||||||
|
CONF_LQI = "lqi"
|
||||||
|
|
||||||
|
cc1101_ns = cg.esphome_ns.namespace("cc1101")
|
||||||
|
CC1101 = cc1101_ns.class_("CC1101", cg.PollingComponent, spi.SPIDevice)
|
||||||
|
|
||||||
|
BeginTxAction = cc1101_ns.class_("BeginTxAction", automation.Action)
|
||||||
|
EndTxAction = cc1101_ns.class_("EndTxAction", automation.Action)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = (
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(CC1101),
|
||||||
|
cv.Optional(CONF_GDO0): pins.gpio_output_pin_schema,
|
||||||
|
cv.Optional(CONF_BANDWIDTH, default=200): cv.uint32_t,
|
||||||
|
cv.Optional(CONF_FREQUENCY, default=433920): cv.uint32_t,
|
||||||
|
cv.Optional(CONF_RSSI): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
|
||||||
|
accuracy_decimals=0,
|
||||||
|
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_LQI): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_EMPTY,
|
||||||
|
accuracy_decimals=0,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.extend(cv.polling_component_schema("60s"))
|
||||||
|
.extend(spi.spi_device_schema(cs_pin_required=True))
|
||||||
|
)
|
||||||
|
|
||||||
|
CC1101_ACTION_SCHEMA = maybe_simple_id(
|
||||||
|
{
|
||||||
|
cv.Required(CONF_ID): cv.use_id(CC1101),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action("cc1101.begin_tx", BeginTxAction, CC1101_ACTION_SCHEMA)
|
||||||
|
@automation.register_action("cc1101.end_tx", EndTxAction, CC1101_ACTION_SCHEMA)
|
||||||
|
async def cc1101_action_to_code(config, action_id, template_arg, args):
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
return var
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
await spi.register_spi_device(var, config)
|
||||||
|
|
||||||
|
if CONF_GDO0 in config:
|
||||||
|
gdo0 = await cg.gpio_pin_expression(config[CONF_GDO0])
|
||||||
|
cg.add(var.set_config_gdo0(gdo0))
|
||||||
|
cg.add(var.set_config_bandwidth(config[CONF_BANDWIDTH]))
|
||||||
|
cg.add(var.set_config_frequency(config[CONF_FREQUENCY]))
|
||||||
|
if CONF_RSSI in config:
|
||||||
|
rssi = await sensor.new_sensor(config[CONF_RSSI])
|
||||||
|
cg.add(var.set_config_rssi_sensor(rssi))
|
||||||
|
if CONF_LQI in config:
|
||||||
|
lqi = await sensor.new_sensor(config[CONF_LQI])
|
||||||
|
cg.add(var.set_config_lqi_sensor(lqi))
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace cc1101 {
|
namespace cc1101 {
|
||||||
|
|
||||||
class CC1101 : public sensor::Sensor,
|
class CC1101 : public PollingComponent,
|
||||||
public PollingComponent,
|
|
||||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||||
spi::DATA_RATE_1KHZ> {
|
spi::DATA_RATE_1KHZ> {
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome import automation, pins
|
|
||||||
from esphome.components import sensor
|
|
||||||
from esphome.components import spi
|
|
||||||
from esphome.automation import maybe_simple_id
|
|
||||||
from esphome.const import (
|
|
||||||
CONF_ID,
|
|
||||||
CONF_FREQUENCY,
|
|
||||||
UNIT_EMPTY,
|
|
||||||
UNIT_DECIBEL_MILLIWATT,
|
|
||||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
|
||||||
STATE_CLASS_MEASUREMENT,
|
|
||||||
)
|
|
||||||
|
|
||||||
DEPENDENCIES = ["spi"]
|
|
||||||
|
|
||||||
CONF_GDO0 = "gdo0"
|
|
||||||
CONF_BANDWIDTH = "bandwidth"
|
|
||||||
# CONF_FREQUENCY = "frequency"
|
|
||||||
CONF_RSSI = "rssi"
|
|
||||||
CONF_LQI = "lqi"
|
|
||||||
|
|
||||||
cc1101_ns = cg.esphome_ns.namespace("cc1101")
|
|
||||||
CC1101 = cc1101_ns.class_("CC1101", sensor.Sensor, cg.PollingComponent, spi.SPIDevice)
|
|
||||||
|
|
||||||
BeginTxAction = cc1101_ns.class_("BeginTxAction", automation.Action)
|
|
||||||
EndTxAction = cc1101_ns.class_("EndTxAction", automation.Action)
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
|
||||||
cv.Schema(
|
|
||||||
{
|
|
||||||
cv.GenerateID(): cv.declare_id(CC1101),
|
|
||||||
cv.Optional(CONF_GDO0): pins.gpio_output_pin_schema,
|
|
||||||
cv.Optional(CONF_BANDWIDTH, default=200): cv.uint32_t,
|
|
||||||
cv.Optional(CONF_FREQUENCY, default=433920): cv.uint32_t,
|
|
||||||
cv.Optional(CONF_RSSI): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
|
|
||||||
accuracy_decimals=0,
|
|
||||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_LQI): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_EMPTY,
|
|
||||||
accuracy_decimals=0,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.extend(cv.polling_component_schema("60s"))
|
|
||||||
.extend(spi.spi_device_schema(cs_pin_required=True))
|
|
||||||
)
|
|
||||||
|
|
||||||
CC1101_ACTION_SCHEMA = maybe_simple_id(
|
|
||||||
{
|
|
||||||
cv.Required(CONF_ID): cv.use_id(CC1101),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action("cc1101.begin_tx", BeginTxAction, CC1101_ACTION_SCHEMA)
|
|
||||||
@automation.register_action("cc1101.end_tx", EndTxAction, CC1101_ACTION_SCHEMA)
|
|
||||||
async def cc1101_action_to_code(config, action_id, template_arg, args):
|
|
||||||
var = cg.new_Pvariable(action_id, template_arg)
|
|
||||||
await cg.register_parented(var, config[CONF_ID])
|
|
||||||
return var
|
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
|
||||||
await cg.register_component(var, config)
|
|
||||||
await spi.register_spi_device(var, config)
|
|
||||||
|
|
||||||
if CONF_GDO0 in config:
|
|
||||||
gdo0 = await cg.gpio_pin_expression(config[CONF_GDO0])
|
|
||||||
cg.add(var.set_config_gdo0(gdo0))
|
|
||||||
cg.add(var.set_config_bandwidth(config[CONF_BANDWIDTH]))
|
|
||||||
cg.add(var.set_config_frequency(config[CONF_FREQUENCY]))
|
|
||||||
if CONF_RSSI in config:
|
|
||||||
rssi = await sensor.new_sensor(config[CONF_RSSI])
|
|
||||||
cg.add(var.set_config_rssi_sensor(rssi))
|
|
||||||
if CONF_LQI in config:
|
|
||||||
lqi = await sensor.new_sensor(config[CONF_LQI])
|
|
||||||
cg.add(var.set_config_lqi_sensor(lqi))
|
|
Loading…
Reference in a new issue