1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00

Rename esphomeyaml to esphome (#426)

* Rename

* Update

* Add migration

* Fix

* Fix dashboard

* Change test

* Fixes

* Code cleanup

* Fix import order

* Update

* Automate docker builds

* Shellcheck
This commit is contained in:
Otto Winter
2019-02-13 16:54:02 +01:00
committed by GitHub
parent 1b8d242505
commit 3d9301a0f7
234 changed files with 1869 additions and 2000 deletions

View File

@@ -0,0 +1,124 @@
import voluptuous as vol
from esphome.automation import ACTION_REGISTRY
import esphome.config_validation as cv
from esphome.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
CONF_POSITION, CONF_TARGET
from esphome.core import CORE
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
from esphome.cpp_types import Action, esphome_ns, int32
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
})
# pylint: disable=invalid-name
stepper_ns = esphome_ns.namespace('stepper')
Stepper = stepper_ns.class_('Stepper')
SetTargetAction = stepper_ns.class_('SetTargetAction', Action)
ReportPositionAction = stepper_ns.class_('ReportPositionAction', 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)'):
if value.endswith(suffix):
value = value[:-len(suffix)]
if value == 'inf':
return 1e6
try:
value = float(value)
except ValueError:
raise vol.Invalid("Expected acceleration as floating point number, got {}".format(value))
if value <= 0:
raise vol.Invalid("Acceleration must be larger than 0 steps/s^2!")
return value
def validate_speed(value):
value = cv.string(value)
for suffix in ('steps/s', 'steps/s'):
if value.endswith(suffix):
value = value[:-len(suffix)]
if value == 'inf':
return 1e6
try:
value = float(value)
except ValueError:
raise vol.Invalid("Expected speed as floating point number, got {}".format(value))
if value <= 0:
raise vol.Invalid("Speed must be larger than 0 steps/s!")
return value
STEPPER_SCHEMA = vol.Schema({
vol.Required(CONF_MAX_SPEED): validate_speed,
vol.Optional(CONF_ACCELERATION): validate_acceleration,
vol.Optional(CONF_DECELERATION): validate_acceleration,
})
STEPPER_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(STEPPER_SCHEMA.schema)
def setup_stepper_core_(stepper_var, config):
if CONF_ACCELERATION in config:
add(stepper_var.set_acceleration(config[CONF_ACCELERATION]))
if CONF_DECELERATION in config:
add(stepper_var.set_deceleration(config[CONF_DECELERATION]))
if CONF_MAX_SPEED in config:
add(stepper_var.set_max_speed(config[CONF_MAX_SPEED]))
def setup_stepper(stepper_var, config):
CORE.add_job(setup_stepper_core_, stepper_var, config)
BUILD_FLAGS = '-DUSE_STEPPER'
CONF_STEPPER_SET_TARGET = 'stepper.set_target'
STEPPER_SET_TARGET_ACTION_SCHEMA = vol.Schema({
vol.Required(CONF_ID): cv.use_variable_id(Stepper),
vol.Required(CONF_TARGET): cv.templatable(cv.int_),
})
@ACTION_REGISTRY.register(CONF_STEPPER_SET_TARGET, STEPPER_SET_TARGET_ACTION_SCHEMA)
def stepper_set_target_to_code(config, action_id, arg_type, template_arg):
for var in get_variable(config[CONF_ID]):
yield None
rhs = var.make_set_target_action(template_arg)
type = SetTargetAction.template(arg_type)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TARGET], arg_type, int32):
yield None
add(action.set_target(template_))
yield action
CONF_STEPPER_REPORT_POSITION = 'stepper.report_position'
STEPPER_REPORT_POSITION_ACTION_SCHEMA = vol.Schema({
vol.Required(CONF_ID): cv.use_variable_id(Stepper),
vol.Required(CONF_POSITION): cv.templatable(cv.int_),
})
@ACTION_REGISTRY.register(CONF_STEPPER_REPORT_POSITION, STEPPER_REPORT_POSITION_ACTION_SCHEMA)
def stepper_report_position_to_code(config, action_id, arg_type, template_arg):
for var in get_variable(config[CONF_ID]):
yield None
rhs = var.make_report_position_action(template_arg)
type = ReportPositionAction.template(arg_type)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_POSITION], arg_type, int32):
yield None
add(action.set_position(template_))
yield action

View File

@@ -0,0 +1,38 @@
import voluptuous as vol
from esphome import pins
from esphome.components import stepper
import esphome.config_validation as cv
from esphome.const import CONF_DIR_PIN, CONF_ID, CONF_SLEEP_PIN, CONF_STEP_PIN
from esphome.cpp_generator import Pvariable, add
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
from esphome.cpp_types import App, Component
A4988 = stepper.stepper_ns.class_('A4988', stepper.Stepper, Component)
PLATFORM_SCHEMA = stepper.STEPPER_PLATFORM_SCHEMA.extend({
vol.Required(CONF_ID): cv.declare_variable_id(A4988),
vol.Required(CONF_STEP_PIN): pins.gpio_output_pin_schema,
vol.Required(CONF_DIR_PIN): pins.gpio_output_pin_schema,
vol.Optional(CONF_SLEEP_PIN): pins.gpio_output_pin_schema,
}).extend(cv.COMPONENT_SCHEMA.schema)
def to_code(config):
for step_pin in gpio_output_pin_expression(config[CONF_STEP_PIN]):
yield
for dir_pin in gpio_output_pin_expression(config[CONF_DIR_PIN]):
yield
rhs = App.make_a4988(step_pin, dir_pin)
a4988 = Pvariable(config[CONF_ID], rhs)
if CONF_SLEEP_PIN in config:
for sleep_pin in gpio_output_pin_expression(config[CONF_SLEEP_PIN]):
yield
add(a4988.set_sleep_pin(sleep_pin))
stepper.setup_stepper(a4988, config)
setup_component(a4988, config)
BUILD_FLAGS = '-DUSE_A4988'

View File

@@ -0,0 +1,55 @@
import voluptuous as vol
from esphome import pins
from esphome.components import stepper
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_PIN_A, CONF_PIN_B, CONF_PIN_C, CONF_PIN_D, \
CONF_SLEEP_WHEN_DONE, CONF_STEP_MODE
from esphome.cpp_generator import Pvariable, add
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
from esphome.cpp_types import App, Component
ULN2003StepMode = stepper.stepper_ns.enum('ULN2003StepMode')
STEP_MODES = {
'FULL_STEP': ULN2003StepMode.ULN2003_STEP_MODE_FULL_STEP,
'HALF_STEP': ULN2003StepMode.ULN2003_STEP_MODE_HALF_STEP,
'WAVE_DRIVE': ULN2003StepMode.ULN2003_STEP_MODE_WAVE_DRIVE,
}
ULN2003 = stepper.stepper_ns.class_('ULN2003', stepper.Stepper, Component)
PLATFORM_SCHEMA = stepper.STEPPER_PLATFORM_SCHEMA.extend({
vol.Required(CONF_ID): cv.declare_variable_id(ULN2003),
vol.Required(CONF_PIN_A): pins.gpio_output_pin_schema,
vol.Required(CONF_PIN_B): pins.gpio_output_pin_schema,
vol.Required(CONF_PIN_C): pins.gpio_output_pin_schema,
vol.Required(CONF_PIN_D): pins.gpio_output_pin_schema,
vol.Optional(CONF_SLEEP_WHEN_DONE): cv.boolean,
vol.Optional(CONF_STEP_MODE): cv.one_of(*STEP_MODES, upper=True, space='_')
}).extend(cv.COMPONENT_SCHEMA.schema)
def to_code(config):
for pin_a in gpio_output_pin_expression(config[CONF_PIN_A]):
yield
for pin_b in gpio_output_pin_expression(config[CONF_PIN_B]):
yield
for pin_c in gpio_output_pin_expression(config[CONF_PIN_C]):
yield
for pin_d in gpio_output_pin_expression(config[CONF_PIN_D]):
yield
rhs = App.make_uln2003(pin_a, pin_b, pin_c, pin_d)
uln = Pvariable(config[CONF_ID], rhs)
if CONF_SLEEP_WHEN_DONE in config:
add(uln.set_sleep_when_done(config[CONF_SLEEP_WHEN_DONE]))
if CONF_STEP_MODE in config:
add(uln.set_step_mode(STEP_MODES[config[CONF_STEP_MODE]]))
stepper.setup_stepper(uln, config)
setup_component(uln, config)
BUILD_FLAGS = '-DUSE_ULN2003'