Fix pulse-meter with device_class and black (#1621)

This commit is contained in:
Jesse Hills 2021-03-19 21:40:11 +13:00 committed by GitHub
parent 251240cc90
commit dedf343bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,18 +2,27 @@ import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import pins from esphome import pins
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_ID, CONF_INTERNAL_FILTER, \ from esphome.const import (
CONF_PIN, CONF_NUMBER, CONF_TIMEOUT, CONF_TOTAL, \ CONF_ID,
ICON_PULSE, UNIT_PULSES, UNIT_PULSES_PER_MINUTE CONF_INTERNAL_FILTER,
CONF_PIN,
CONF_NUMBER,
CONF_TIMEOUT,
CONF_TOTAL,
ICON_PULSE,
UNIT_PULSES,
UNIT_PULSES_PER_MINUTE,
DEVICE_CLASS_EMPTY,
)
from esphome.core import CORE from esphome.core import CORE
CODEOWNERS = ['@stevebaxter'] CODEOWNERS = ["@stevebaxter"]
pulse_meter_ns = cg.esphome_ns.namespace('pulse_meter') pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter")
PulseMeterSensor = pulse_meter_ns.class_('PulseMeterSensor', PulseMeterSensor = pulse_meter_ns.class_(
sensor.Sensor, "PulseMeterSensor", sensor.Sensor, cg.Component
cg.Component) )
def validate_internal_filter(value): def validate_internal_filter(value):
@ -30,17 +39,25 @@ def validate_timeout(value):
def validate_pulse_meter_pin(value): def validate_pulse_meter_pin(value):
value = pins.internal_gpio_input_pin_schema(value) value = pins.internal_gpio_input_pin_schema(value)
if CORE.is_esp8266 and value[CONF_NUMBER] >= 16: if CORE.is_esp8266 and value[CONF_NUMBER] >= 16:
raise cv.Invalid("Pins GPIO16 and GPIO17 cannot be used as pulse counters on ESP8266.") raise cv.Invalid(
"Pins GPIO16 and GPIO17 cannot be used as pulse counters on ESP8266."
)
return value return value
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2).extend({ CONFIG_SCHEMA = sensor.sensor_schema(
cv.GenerateID(): cv.declare_id(PulseMeterSensor), UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2, DEVICE_CLASS_EMPTY
cv.Required(CONF_PIN): validate_pulse_meter_pin, ).extend(
cv.Optional(CONF_INTERNAL_FILTER, default='13us'): validate_internal_filter, {
cv.Optional(CONF_TIMEOUT, default='5min'): validate_timeout, cv.GenerateID(): cv.declare_id(PulseMeterSensor),
cv.Optional(CONF_TOTAL): sensor.sensor_schema(UNIT_PULSES, ICON_PULSE, 0) cv.Required(CONF_PIN): validate_pulse_meter_pin,
}) cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter,
cv.Optional(CONF_TIMEOUT, default="5min"): validate_timeout,
cv.Optional(CONF_TOTAL): sensor.sensor_schema(
UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY
),
}
)
def to_code(config): def to_code(config):