mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
15331edb78
* Allow overriding setup priority * Add inheritance tree * Global variables * Tests and better validation * Fix * Lint
90 lines
3.7 KiB
Python
90 lines
3.7 KiB
Python
import voluptuous as vol
|
|
|
|
import esphomeyaml.config_validation as cv
|
|
from esphomeyaml import pins
|
|
from esphomeyaml.components import display, spi
|
|
from esphomeyaml.components.spi import SPIComponent
|
|
from esphomeyaml.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_FULL_UPDATE_EVERY, \
|
|
CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID
|
|
from esphomeyaml.helpers import App, Pvariable, add, get_variable, gpio_input_pin_expression, \
|
|
gpio_output_pin_expression, process_lambda, setup_component, PollingComponent
|
|
|
|
DEPENDENCIES = ['spi']
|
|
|
|
WaveshareEPaperTypeA = display.display_ns.WaveshareEPaperTypeA
|
|
WaveshareEPaper = display.display_ns.class_('WaveshareEPaper',
|
|
PollingComponent, spi.SPIDevice, display.DisplayBuffer)
|
|
|
|
|
|
WaveshareEPaperTypeAModel = display.display_ns.enum('WaveshareEPaperTypeAModel')
|
|
WaveshareEPaperTypeBModel = display.display_ns.enum('WaveshareEPaperTypeBModel')
|
|
|
|
MODELS = {
|
|
'1.54in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_1_54_IN),
|
|
'2.13in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_13_IN),
|
|
'2.90in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
|
|
'2.70in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_2_7_IN),
|
|
'4.20in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_4_2_IN),
|
|
'7.50in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_7_5_IN),
|
|
}
|
|
|
|
|
|
def validate_full_update_every_only_type_a(value):
|
|
if CONF_FULL_UPDATE_EVERY not in value:
|
|
return value
|
|
if MODELS[value[CONF_MODEL]][0] != 'a':
|
|
raise vol.Invalid("The 'full_update_every' option is only available for models "
|
|
"'1.54in', '2.13in' and '2.90in'.")
|
|
return value
|
|
|
|
|
|
PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_variable_id(WaveshareEPaper),
|
|
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
|
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
|
vol.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
|
vol.Required(CONF_MODEL): vol.All(vol.Lower, cv.one_of(*MODELS)),
|
|
vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
|
vol.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
|
|
vol.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
|
|
}).extend(cv.COMPONENT_SCHEMA.schema), validate_full_update_every_only_type_a)
|
|
|
|
|
|
def to_code(config):
|
|
for spi_ in get_variable(config[CONF_SPI_ID]):
|
|
yield
|
|
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
|
|
yield
|
|
for dc in gpio_output_pin_expression(config[CONF_DC_PIN]):
|
|
yield
|
|
|
|
model_type, model = MODELS[config[CONF_MODEL]]
|
|
if model_type == 'a':
|
|
rhs = App.make_waveshare_epaper_type_a(spi_, cs, dc, model)
|
|
epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaperTypeA)
|
|
elif model_type == 'b':
|
|
rhs = App.make_waveshare_epaper_type_b(spi_, cs, dc, model)
|
|
epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaper)
|
|
else:
|
|
raise NotImplementedError()
|
|
|
|
if CONF_LAMBDA in config:
|
|
for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')]):
|
|
yield
|
|
add(epaper.set_writer(lambda_))
|
|
if CONF_RESET_PIN in config:
|
|
for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
|
|
yield
|
|
add(epaper.set_reset_pin(reset))
|
|
if CONF_BUSY_PIN in config:
|
|
for reset in gpio_input_pin_expression(config[CONF_BUSY_PIN]):
|
|
yield
|
|
add(epaper.set_busy_pin(reset))
|
|
if CONF_FULL_UPDATE_EVERY in config:
|
|
add(epaper.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))
|
|
|
|
display.setup_display(epaper, config)
|
|
setup_component(epaper, config)
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_WAVESHARE_EPAPER'
|