mirror of
https://github.com/esphome/esphome.git
synced 2025-09-25 22:52:20 +01:00
add-black (#1593)
* Add black Update pre commit Update pre commit add empty line * Format with black
This commit is contained in:
committed by
GitHub
parent
2b60b0f1fa
commit
69879920eb
@@ -2,31 +2,48 @@ import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.components import mqtt
|
||||
from esphome.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_ON_VALUE, \
|
||||
CONF_TRIGGER_ID, CONF_MQTT_ID, CONF_NAME, CONF_STATE
|
||||
from esphome.const import (
|
||||
CONF_ICON,
|
||||
CONF_ID,
|
||||
CONF_INTERNAL,
|
||||
CONF_ON_VALUE,
|
||||
CONF_TRIGGER_ID,
|
||||
CONF_MQTT_ID,
|
||||
CONF_NAME,
|
||||
CONF_STATE,
|
||||
)
|
||||
from esphome.core import CORE, coroutine, coroutine_with_priority
|
||||
|
||||
IS_PLATFORM_COMPONENT = True
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
text_sensor_ns = cg.esphome_ns.namespace('text_sensor')
|
||||
TextSensor = text_sensor_ns.class_('TextSensor', cg.Nameable)
|
||||
TextSensorPtr = TextSensor.operator('ptr')
|
||||
text_sensor_ns = cg.esphome_ns.namespace("text_sensor")
|
||||
TextSensor = text_sensor_ns.class_("TextSensor", cg.Nameable)
|
||||
TextSensorPtr = TextSensor.operator("ptr")
|
||||
|
||||
TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger',
|
||||
automation.Trigger.template(cg.std_string))
|
||||
TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction', automation.Action)
|
||||
TextSensorStateCondition = text_sensor_ns.class_('TextSensorStateCondition', automation.Condition)
|
||||
TextSensorStateTrigger = text_sensor_ns.class_(
|
||||
"TextSensorStateTrigger", automation.Trigger.template(cg.std_string)
|
||||
)
|
||||
TextSensorPublishAction = text_sensor_ns.class_(
|
||||
"TextSensorPublishAction", automation.Action
|
||||
)
|
||||
TextSensorStateCondition = text_sensor_ns.class_(
|
||||
"TextSensorStateCondition", automation.Condition
|
||||
)
|
||||
|
||||
icon = cv.icon
|
||||
|
||||
TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
|
||||
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_id(mqtt.MQTTTextSensor),
|
||||
cv.Optional(CONF_ICON): icon,
|
||||
cv.Optional(CONF_ON_VALUE): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TextSensorStateTrigger),
|
||||
}),
|
||||
})
|
||||
TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend(
|
||||
{
|
||||
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTTextSensor),
|
||||
cv.Optional(CONF_ICON): icon,
|
||||
cv.Optional(CONF_ON_VALUE): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TextSensorStateTrigger),
|
||||
}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
@@ -39,7 +56,7 @@ def setup_text_sensor_core_(var, config):
|
||||
|
||||
for conf in config.get(CONF_ON_VALUE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
yield automation.build_automation(trigger, [(cg.std_string, 'x')], conf)
|
||||
yield automation.build_automation(trigger, [(cg.std_string, "x")], conf)
|
||||
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
@@ -56,14 +73,20 @@ def register_text_sensor(var, config):
|
||||
|
||||
@coroutine_with_priority(100.0)
|
||||
def to_code(config):
|
||||
cg.add_define('USE_TEXT_SENSOR')
|
||||
cg.add_define("USE_TEXT_SENSOR")
|
||||
cg.add_global(text_sensor_ns.using)
|
||||
|
||||
|
||||
@automation.register_condition('text_sensor.state', TextSensorStateCondition, cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_id(TextSensor),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.string_strict),
|
||||
}))
|
||||
@automation.register_condition(
|
||||
"text_sensor.state",
|
||||
TextSensorStateCondition,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(TextSensor),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.string_strict),
|
||||
}
|
||||
),
|
||||
)
|
||||
def text_sensor_state_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
Reference in New Issue
Block a user