mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 04:12:23 +01:00
Simplify coroutine syntax (#503)
* Simplify coroutine syntax * More * Lint * Fix * More * Lint
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from esphome.const import CONF_INVERTED, CONF_MODE, CONF_NUMBER, CONF_PCF8574, \
|
||||
CONF_SETUP_PRIORITY, CONF_MCP23017
|
||||
from esphome.core import CORE, EsphomeError
|
||||
from esphome.core import CORE, EsphomeError, coroutine
|
||||
from esphome.cpp_generator import IntLiteral, RawExpression
|
||||
from esphome.cpp_types import GPIOInputPin, GPIOOutputPin
|
||||
|
||||
|
||||
@coroutine
|
||||
def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
if conf is None:
|
||||
return
|
||||
@@ -13,8 +14,7 @@ def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
if CONF_PCF8574 in conf:
|
||||
from esphome.components import pcf8574
|
||||
|
||||
for hub in CORE.get_variable(conf[CONF_PCF8574]):
|
||||
yield None
|
||||
hub = yield CORE.get_variable(conf[CONF_PCF8574])
|
||||
|
||||
if default_mode == u'INPUT':
|
||||
mode = pcf8574.PCF8675_GPIO_MODES[conf.get(CONF_MODE, u'INPUT')]
|
||||
@@ -28,8 +28,7 @@ def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
if CONF_MCP23017 in conf:
|
||||
from esphome.components import mcp23017
|
||||
|
||||
for hub in CORE.get_variable(conf[CONF_MCP23017]):
|
||||
yield None
|
||||
hub = yield CORE.get_variable(conf[CONF_MCP23017])
|
||||
|
||||
if default_mode == u'INPUT':
|
||||
mode = mcp23017.MCP23017_GPIO_MODES[conf.get(CONF_MODE, u'INPUT')]
|
||||
@@ -47,16 +46,14 @@ def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
yield mock_obj(number, mode, inverted)
|
||||
|
||||
|
||||
@coroutine
|
||||
def gpio_output_pin_expression(conf):
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOOutputPin, 'OUTPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
yield generic_gpio_pin_expression_(conf, GPIOOutputPin, 'OUTPUT')
|
||||
|
||||
|
||||
@coroutine
|
||||
def gpio_input_pin_expression(conf):
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOInputPin, 'INPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
yield generic_gpio_pin_expression_(conf, GPIOInputPin, 'INPUT')
|
||||
|
||||
|
||||
def setup_component(obj, config):
|
||||
|
Reference in New Issue
Block a user