mirror of
https://github.com/esphome/esphome.git
synced 2025-09-21 12:42:21 +01:00
Let esphomeyaml know about class inheritance (#229)
* Allow overriding setup priority * Add inheritance tree * Global variables * Tests and better validation * Fix * Lint
This commit is contained in:
@@ -4,20 +4,22 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_RESOLUTION
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_input_pin_expression, variable
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_input_pin_expression, variable, \
|
||||
setup_component, Component
|
||||
|
||||
RotaryEncoderResolution = sensor.sensor_ns.enum('RotaryEncoderResolution')
|
||||
RESOLUTIONS = {
|
||||
'1': sensor.sensor_ns.ROTARY_ENCODER_1_PULSE_PER_CYCLE,
|
||||
'2': sensor.sensor_ns.ROTARY_ENCODER_2_PULSES_PER_CYCLE,
|
||||
'4': sensor.sensor_ns.ROTARY_ENCODER_4_PULSES_PER_CYCLE,
|
||||
'1': RotaryEncoderResolution.ROTARY_ENCODER_1_PULSE_PER_CYCLE,
|
||||
'2': RotaryEncoderResolution.ROTARY_ENCODER_2_PULSES_PER_CYCLE,
|
||||
'4': RotaryEncoderResolution.ROTARY_ENCODER_4_PULSES_PER_CYCLE,
|
||||
}
|
||||
|
||||
CONF_PIN_A = 'pin_a'
|
||||
CONF_PIN_B = 'pin_b'
|
||||
CONF_PIN_RESET = 'pin_reset'
|
||||
|
||||
MakeRotaryEncoderSensor = Application.MakeRotaryEncoderSensor
|
||||
RotaryEncoderSensor = sensor.sensor_ns.RotaryEncoderSensor
|
||||
MakeRotaryEncoderSensor = Application.struct('MakeRotaryEncoderSensor')
|
||||
RotaryEncoderSensor = sensor.sensor_ns.class_('RotaryEncoderSensor', sensor.Sensor, Component)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(RotaryEncoderSensor),
|
||||
@@ -26,19 +28,18 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_PIN_B): pins.internal_gpio_input_pin_schema,
|
||||
vol.Optional(CONF_PIN_RESET): pins.internal_gpio_input_pin_schema,
|
||||
vol.Optional(CONF_RESOLUTION): vol.All(cv.string, cv.one_of(*RESOLUTIONS)),
|
||||
}))
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
pin_a = None
|
||||
for pin_a in gpio_input_pin_expression(config[CONF_PIN_A]):
|
||||
yield
|
||||
pin_b = None
|
||||
for pin_b in gpio_input_pin_expression(config[CONF_PIN_B]):
|
||||
yield
|
||||
rhs = App.make_rotary_encoder_sensor(config[CONF_NAME], pin_a, pin_b)
|
||||
make = variable(config[CONF_MAKE_ID], rhs)
|
||||
encoder = make.Protary_encoder
|
||||
|
||||
if CONF_PIN_RESET in config:
|
||||
pin_i = None
|
||||
for pin_i in gpio_input_pin_expression(config[CONF_PIN_RESET]):
|
||||
@@ -47,7 +48,9 @@ def to_code(config):
|
||||
if CONF_RESOLUTION in config:
|
||||
resolution = RESOLUTIONS[config[CONF_RESOLUTION]]
|
||||
add(encoder.set_resolution(resolution))
|
||||
|
||||
sensor.setup_sensor(encoder, make.Pmqtt, config)
|
||||
setup_component(encoder, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_ROTARY_ENCODER_SENSOR'
|
||||
|
Reference in New Issue
Block a user