Skip to content

Commit

Permalink
lint-python, lint-cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Links2004 committed Apr 26, 2024
1 parent 1e1a3ea commit 756c55b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
67 changes: 43 additions & 24 deletions esphome/components/statsd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, binary_sensor
from esphome.const import CONF_ID, CONF_PORT, CONF_NAME, CONF_SENSORS, CONF_BINARY_SENSORS
from esphome.const import (
CONF_ID,
CONF_PORT,
CONF_NAME,
CONF_SENSORS,
CONF_BINARY_SENSORS,
)

CODEOWNERS = ["@Links2004"]

Check failure on line 13 in esphome/components/statsd/__init__.py

View workflow job for this annotation

GitHub Actions / Run script/ci-custom

Constant CONF_STATSD_HOST does not match value host! Please make sure the constant's name matches its value!
CONF_STATSD_HOST = "host"
CONF_STATSD_PREFIX = "prefix"

Check failure on line 15 in esphome/components/statsd/__init__.py

View workflow job for this annotation

GitHub Actions / Run script/ci-custom

Constant CONF_STATSD_PREFIX does not match value prefix! Please make sure the constant's name matches its value!

statsd_component_ns = cg.esphome_ns.namespace('statsd')
statsdComponent = statsd_component_ns.class_('statsdComponent', cg.Component)
statsd_component_ns = cg.esphome_ns.namespace("statsd")
statsdComponent = statsd_component_ns.class_("statsdComponent", cg.Component)


CONFIG_SENSORS_SCHEMA = cv.Schema({
cv.Required(CONF_ID): cv.use_id(sensor.Sensor),
cv.Required(CONF_NAME): cv.string_strict,
})
CONFIG_SENSORS_SCHEMA = cv.Schema(
{
cv.Required(CONF_ID): cv.use_id(sensor.Sensor),
cv.Required(CONF_NAME): cv.string_strict,
}
)

CONFIG_BINARY_SENSORS_SCHEMA = cv.Schema({
cv.Required(CONF_ID): cv.use_id(binary_sensor.BinarySensor),
cv.Required(CONF_NAME): cv.string_strict,
})
CONFIG_BINARY_SENSORS_SCHEMA = cv.Schema(
{
cv.Required(CONF_ID): cv.use_id(binary_sensor.BinarySensor),
cv.Required(CONF_NAME): cv.string_strict,
}
)

CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(statsdComponent),
cv.Required(CONF_STATSD_HOST): cv.string_strict,
cv.Optional(CONF_PORT, default=8125): cv.port,
cv.Optional(CONF_STATSD_PREFIX, default=""): cv.string_strict,
cv.Optional(CONF_SENSORS): cv.ensure_list(CONFIG_SENSORS_SCHEMA),
cv.Optional(CONF_BINARY_SENSORS): cv.ensure_list(CONFIG_BINARY_SENSORS_SCHEMA),
}
).extend(cv.COMPONENT_SCHEMA)

CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(statsdComponent),
cv.Required(CONF_STATSD_HOST): cv.string_strict,
cv.Optional(CONF_PORT, default=8125): cv.port,
cv.Optional(CONF_STATSD_PREFIX, default=""): cv.string_strict,
cv.Optional(CONF_SENSORS): cv.ensure_list(CONFIG_SENSORS_SCHEMA),
cv.Optional(CONF_BINARY_SENSORS): cv.ensure_list(CONFIG_BINARY_SENSORS_SCHEMA),
}).extend(cv.COMPONENT_SCHEMA)

async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
cg.add(var.configure(config.get(CONF_STATSD_HOST), config.get(CONF_PORT), config.get(CONF_STATSD_PREFIX)))
cg.add(
var.configure(
config.get(CONF_STATSD_HOST),
config.get(CONF_PORT),
config.get(CONF_STATSD_PREFIX),
)
)

for sensor_cfg in config.get(CONF_SENSORS, []):
sensor = await cg.get_variable(sensor_cfg[CONF_ID])
cg.add(var.register_sensor(sensor_cfg[CONF_NAME], sensor))
s = await cg.get_variable(sensor_cfg[CONF_ID])
cg.add(var.register_sensor(sensor_cfg[CONF_NAME], s))

for sensor_cfg in config.get(CONF_BINARY_SENSORS, []):
sensor = await cg.get_variable(sensor_cfg[CONF_ID])
cg.add(var.register_binary_sensor(sensor_cfg[CONF_NAME], sensor))
s = await cg.get_variable(sensor_cfg[CONF_ID])
cg.add(var.register_binary_sensor(sensor_cfg[CONF_NAME], s))
4 changes: 4 additions & 0 deletions esphome/components/statsd/statsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
namespace esphome {
namespace statsd {

// send UDP packet if we reach 1Kb packed size
// this is needed since statsD does not support fragmented UDP packets
static const uint16_t SEND_THRESHOLD = 1024;

static const char *TAG = "statsD";

void statsdComponent::setup() {
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/statsd/statsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
namespace esphome {
namespace statsd {

// send UDP packet if we reach 1Kb packed size
// this is needed since statsD does not support fragmented UDP packets
#define SEND_THRESHOLD 1024

typedef enum { TYPE_SENSOR, TYPE_BINARY_SENSOR } sensor_type_t;

typedef struct {
Expand Down

0 comments on commit 756c55b

Please sign in to comment.