mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-03 19:38:30 +02: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
@@ -1,28 +1,35 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
|
||||
CONF_POSITION, CONF_TARGET, CONF_SPEED
|
||||
from esphome.const import (
|
||||
CONF_ACCELERATION,
|
||||
CONF_DECELERATION,
|
||||
CONF_ID,
|
||||
CONF_MAX_SPEED,
|
||||
CONF_POSITION,
|
||||
CONF_TARGET,
|
||||
CONF_SPEED,
|
||||
)
|
||||
from esphome.core import CORE, coroutine, coroutine_with_priority
|
||||
|
||||
IS_PLATFORM_COMPONENT = True
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
stepper_ns = cg.esphome_ns.namespace('stepper')
|
||||
Stepper = stepper_ns.class_('Stepper')
|
||||
stepper_ns = cg.esphome_ns.namespace("stepper")
|
||||
Stepper = stepper_ns.class_("Stepper")
|
||||
|
||||
SetTargetAction = stepper_ns.class_('SetTargetAction', automation.Action)
|
||||
ReportPositionAction = stepper_ns.class_('ReportPositionAction', automation.Action)
|
||||
SetSpeedAction = stepper_ns.class_('SetSpeedAction', automation.Action)
|
||||
SetTargetAction = stepper_ns.class_("SetTargetAction", automation.Action)
|
||||
ReportPositionAction = stepper_ns.class_("ReportPositionAction", automation.Action)
|
||||
SetSpeedAction = stepper_ns.class_("SetSpeedAction", automation.Action)
|
||||
|
||||
|
||||
def validate_acceleration(value):
|
||||
value = cv.string(value)
|
||||
for suffix in ('steps/s^2', 'steps/s*s', 'steps/s/s', 'steps/ss', 'steps/(s*s)'):
|
||||
for suffix in ("steps/s^2", "steps/s*s", "steps/s/s", "steps/ss", "steps/(s*s)"):
|
||||
if value.endswith(suffix):
|
||||
value = value[:-len(suffix)]
|
||||
value = value[: -len(suffix)]
|
||||
|
||||
if value == 'inf':
|
||||
if value == "inf":
|
||||
return 1e6
|
||||
|
||||
try:
|
||||
@@ -39,11 +46,11 @@ def validate_acceleration(value):
|
||||
|
||||
def validate_speed(value):
|
||||
value = cv.string(value)
|
||||
for suffix in ('steps/s', 'steps/s'):
|
||||
for suffix in ("steps/s", "steps/s"):
|
||||
if value.endswith(suffix):
|
||||
value = value[:-len(suffix)]
|
||||
value = value[: -len(suffix)]
|
||||
|
||||
if value == 'inf':
|
||||
if value == "inf":
|
||||
return 1e6
|
||||
|
||||
try:
|
||||
@@ -58,11 +65,13 @@ def validate_speed(value):
|
||||
return value
|
||||
|
||||
|
||||
STEPPER_SCHEMA = cv.Schema({
|
||||
cv.Required(CONF_MAX_SPEED): validate_speed,
|
||||
cv.Optional(CONF_ACCELERATION, default='inf'): validate_acceleration,
|
||||
cv.Optional(CONF_DECELERATION, default='inf'): validate_acceleration,
|
||||
})
|
||||
STEPPER_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_MAX_SPEED): validate_speed,
|
||||
cv.Optional(CONF_ACCELERATION, default="inf"): validate_acceleration,
|
||||
cv.Optional(CONF_DECELERATION, default="inf"): validate_acceleration,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
@@ -82,10 +91,16 @@ def register_stepper(var, config):
|
||||
yield setup_stepper_core_(var, config)
|
||||
|
||||
|
||||
@automation.register_action('stepper.set_target', SetTargetAction, cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_TARGET): cv.templatable(cv.int_),
|
||||
}))
|
||||
@automation.register_action(
|
||||
"stepper.set_target",
|
||||
SetTargetAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_TARGET): cv.templatable(cv.int_),
|
||||
}
|
||||
),
|
||||
)
|
||||
def stepper_set_target_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
@@ -94,10 +109,16 @@ def stepper_set_target_to_code(config, action_id, template_arg, args):
|
||||
yield var
|
||||
|
||||
|
||||
@automation.register_action('stepper.report_position', ReportPositionAction, cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_POSITION): cv.templatable(cv.int_),
|
||||
}))
|
||||
@automation.register_action(
|
||||
"stepper.report_position",
|
||||
ReportPositionAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_POSITION): cv.templatable(cv.int_),
|
||||
}
|
||||
),
|
||||
)
|
||||
def stepper_report_position_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
@@ -106,10 +127,16 @@ def stepper_report_position_to_code(config, action_id, template_arg, args):
|
||||
yield var
|
||||
|
||||
|
||||
@automation.register_action('stepper.set_speed', SetSpeedAction, cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_SPEED): cv.templatable(validate_speed),
|
||||
}))
|
||||
@automation.register_action(
|
||||
"stepper.set_speed",
|
||||
SetSpeedAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(Stepper),
|
||||
cv.Required(CONF_SPEED): cv.templatable(validate_speed),
|
||||
}
|
||||
),
|
||||
)
|
||||
def stepper_set_speed_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
Reference in New Issue
Block a user