From 0c77228421ef5cab673e7b8422ed87e9d78b8d64 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Wed, 6 Jun 2018 08:55:53 +0200 Subject: [PATCH] Improve wrong pin error message --- esphomeyaml/components/binary_sensor/gpio.py | 2 +- esphomeyaml/components/deep_sleep.py | 2 +- esphomeyaml/components/ir_transmitter.py | 2 +- esphomeyaml/components/output/esp8266_pwm.py | 2 +- esphomeyaml/components/output/gpio.py | 2 +- esphomeyaml/components/power_supply.py | 2 +- esphomeyaml/components/sensor/dallas.py | 11 ++------ esphomeyaml/components/sensor/dht.py | 4 +-- esphomeyaml/components/sensor/dht12.py | 4 +-- esphomeyaml/components/sensor/max6675.py | 6 ++-- .../components/sensor/rotary_encoder.py | 6 ++-- esphomeyaml/components/sensor/ultrasonic.py | 4 +-- esphomeyaml/components/switch/gpio.py | 2 +- esphomeyaml/helpers.py | 2 +- esphomeyaml/pins.py | 28 ++++++++++++++++--- 15 files changed, 47 insertions(+), 32 deletions(-) diff --git a/esphomeyaml/components/binary_sensor/gpio.py b/esphomeyaml/components/binary_sensor/gpio.py index 9890970313..478e461d8d 100644 --- a/esphomeyaml/components/binary_sensor/gpio.py +++ b/esphomeyaml/components/binary_sensor/gpio.py @@ -10,7 +10,7 @@ MakeGPIOBinarySensor = Application.MakeGPIOBinarySensor PLATFORM_SCHEMA = binary_sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOBinarySensor), - vol.Required(CONF_PIN): pins.GPIO_INPUT_PIN_SCHEMA + vol.Required(CONF_PIN): pins.gpio_input_pin_schema }).extend(binary_sensor.BINARY_SENSOR_SCHEMA.schema) diff --git a/esphomeyaml/components/deep_sleep.py b/esphomeyaml/components/deep_sleep.py index d374507b80..fba19a37c0 100644 --- a/esphomeyaml/components/deep_sleep.py +++ b/esphomeyaml/components/deep_sleep.py @@ -27,7 +27,7 @@ CONF_WAKEUP_PIN_MODE = 'wakeup_pin_mode' CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(DeepSleepComponent), vol.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds, - vol.Optional(CONF_WAKEUP_PIN): vol.All(cv.only_on_esp32, pins.GPIO_INTERNAL_INPUT_PIN_SCHEMA, + vol.Optional(CONF_WAKEUP_PIN): vol.All(cv.only_on_esp32, pins.internal_gpio_input_pin_schema, validate_pin_number), vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, vol.Upper, cv.one_of(*WAKEUP_PIN_MODES)), diff --git a/esphomeyaml/components/ir_transmitter.py b/esphomeyaml/components/ir_transmitter.py index 9ea5cb3744..e1b6cbd1aa 100644 --- a/esphomeyaml/components/ir_transmitter.py +++ b/esphomeyaml/components/ir_transmitter.py @@ -10,7 +10,7 @@ IRTransmitterComponent = switch.switch_ns.namespace('IRTransmitterComponent') CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({ cv.GenerateID(): cv.declare_variable_id(IRTransmitterComponent), - vol.Required(CONF_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, + vol.Required(CONF_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_CARRIER_DUTY_PERCENT): vol.All(vol.Coerce(int), vol.Range(min=1, max=100)), })]) diff --git a/esphomeyaml/components/output/esp8266_pwm.py b/esphomeyaml/components/output/esp8266_pwm.py index fec86a3ba9..b477d1cb5f 100644 --- a/esphomeyaml/components/output/esp8266_pwm.py +++ b/esphomeyaml/components/output/esp8266_pwm.py @@ -20,7 +20,7 @@ ESP8266PWMOutput = output.output_ns.ESP8266PWMOutput PLATFORM_SCHEMA = output.PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(ESP8266PWMOutput), - vol.Required(CONF_PIN): vol.All(pins.GPIO_INTERNAL_OUTPUT_PIN_SCHEMA, valid_pwm_pin), + vol.Required(CONF_PIN): vol.All(pins.internal_gpio_output_pin_schema, valid_pwm_pin), }).extend(output.FLOAT_OUTPUT_SCHEMA.schema) diff --git a/esphomeyaml/components/output/gpio.py b/esphomeyaml/components/output/gpio.py index 4315d1648c..c082edc5ce 100644 --- a/esphomeyaml/components/output/gpio.py +++ b/esphomeyaml/components/output/gpio.py @@ -10,7 +10,7 @@ GPIOBinaryOutputComponent = output.output_ns.GPIOBinaryOutputComponent PLATFORM_SCHEMA = output.PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(GPIOBinaryOutputComponent), - vol.Required(CONF_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, + vol.Required(CONF_PIN): pins.gpio_output_pin_schema, }).extend(output.BINARY_OUTPUT_SCHEMA.schema) diff --git a/esphomeyaml/components/power_supply.py b/esphomeyaml/components/power_supply.py index 253efedc69..209b729be7 100644 --- a/esphomeyaml/components/power_supply.py +++ b/esphomeyaml/components/power_supply.py @@ -9,7 +9,7 @@ PowerSupplyComponent = esphomelib_ns.PowerSupplyComponent POWER_SUPPLY_SCHEMA = vol.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(PowerSupplyComponent), - vol.Required(CONF_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, + vol.Required(CONF_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_ENABLE_TIME): cv.positive_time_period_milliseconds, vol.Optional(CONF_KEEP_ON_TIME): cv.positive_time_period_milliseconds, }) diff --git a/esphomeyaml/components/sensor/dallas.py b/esphomeyaml/components/sensor/dallas.py index f6a5e6fb59..945e31cdbe 100644 --- a/esphomeyaml/components/sensor/dallas.py +++ b/esphomeyaml/components/sensor/dallas.py @@ -4,7 +4,7 @@ import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.components.dallas import DallasComponent from esphomeyaml.const import CONF_ADDRESS, CONF_DALLAS_ID, CONF_INDEX, CONF_NAME, \ - CONF_RESOLUTION, CONF_UPDATE_INTERVAL + CONF_RESOLUTION from esphomeyaml.helpers import HexIntLiteral, get_variable PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ @@ -19,17 +19,12 @@ def to_code(config): hub = None for hub in get_variable(config[CONF_DALLAS_ID]): yield - update_interval = config.get(CONF_UPDATE_INTERVAL) - if CONF_RESOLUTION in config and update_interval is None: - update_interval = 10000 - if CONF_ADDRESS in config: address = HexIntLiteral(config[CONF_ADDRESS]) - rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address, update_interval, - config.get(CONF_RESOLUTION)) + rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address, config.get(CONF_RESOLUTION)) else: rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX], - update_interval, config.get(CONF_RESOLUTION)) + config.get(CONF_RESOLUTION)) sensor.register_sensor(rhs, config) diff --git a/esphomeyaml/components/sensor/dht.py b/esphomeyaml/components/sensor/dht.py index 6e7eaca881..59871086fd 100644 --- a/esphomeyaml/components/sensor/dht.py +++ b/esphomeyaml/components/sensor/dht.py @@ -5,7 +5,7 @@ from esphomeyaml.components import sensor from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_MODEL, CONF_NAME, CONF_PIN, \ CONF_TEMPERATURE, CONF_UPDATE_INTERVAL from esphomeyaml.helpers import App, Application, add, gpio_output_pin_expression, variable -from esphomeyaml.pins import GPIO_OUTPUT_PIN_SCHEMA +from esphomeyaml.pins import gpio_output_pin_schema DHT_MODELS = { 'AUTO_DETECT': sensor.sensor_ns.DHT_MODEL_AUTO_DETECT, @@ -19,7 +19,7 @@ MakeDHTSensor = Application.MakeDHTSensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeDHTSensor), - vol.Required(CONF_PIN): GPIO_OUTPUT_PIN_SCHEMA, + vol.Required(CONF_PIN): gpio_output_pin_schema, vol.Required(CONF_TEMPERATURE): sensor.SENSOR_SCHEMA, vol.Required(CONF_HUMIDITY): sensor.SENSOR_SCHEMA, vol.Optional(CONF_MODEL): vol.All(vol.Upper, cv.one_of(*DHT_MODELS)), diff --git a/esphomeyaml/components/sensor/dht12.py b/esphomeyaml/components/sensor/dht12.py index 35f668b2cb..f35aafbfd6 100644 --- a/esphomeyaml/components/sensor/dht12.py +++ b/esphomeyaml/components/sensor/dht12.py @@ -24,9 +24,9 @@ def to_code(config): config.get(CONF_UPDATE_INTERVAL)) dht = variable(config[CONF_MAKE_ID], rhs) - sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(), dht.Pmqtt_temperature, + sensor.setup_sensor(dht.Pdht12.Pget_temperature_sensor(), dht.Pmqtt_temperature, config[CONF_TEMPERATURE]) - sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(), dht.Pmqtt_humidity, + sensor.setup_sensor(dht.Pdht12.Pget_humidity_sensor(), dht.Pmqtt_humidity, config[CONF_HUMIDITY]) diff --git a/esphomeyaml/components/sensor/max6675.py b/esphomeyaml/components/sensor/max6675.py index 95ee0e311a..45f98bfbb8 100644 --- a/esphomeyaml/components/sensor/max6675.py +++ b/esphomeyaml/components/sensor/max6675.py @@ -12,9 +12,9 @@ MakeMAX6675Sensor = Application.MakeMAX6675Sensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeMAX6675Sensor), - vol.Required(CONF_PIN_CS): pins.GPIO_OUTPUT_PIN_SCHEMA, - vol.Required(CONF_PIN_CLOCK): pins.GPIO_OUTPUT_PIN_SCHEMA, - vol.Optional(CONF_PIN_MISO): pins.GPIO_INPUT_PIN_SCHEMA, + vol.Required(CONF_PIN_CS): pins.gpio_output_pin_schema, + vol.Required(CONF_PIN_CLOCK): pins.gpio_output_pin_schema, + vol.Required(CONF_PIN_MISO): pins.gpio_input_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, }).extend(sensor.SENSOR_SCHEMA.schema) diff --git a/esphomeyaml/components/sensor/rotary_encoder.py b/esphomeyaml/components/sensor/rotary_encoder.py index c5dfee9bbf..bd4fb77dfc 100644 --- a/esphomeyaml/components/sensor/rotary_encoder.py +++ b/esphomeyaml/components/sensor/rotary_encoder.py @@ -20,9 +20,9 @@ MakeRotaryEncoderSensor = Application.MakeRotaryEncoderSensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeRotaryEncoderSensor), - vol.Required(CONF_PIN_A): pins.GPIO_INTERNAL_INPUT_PIN_SCHEMA, - vol.Required(CONF_PIN_B): pins.GPIO_INTERNAL_INPUT_PIN_SCHEMA, - vol.Optional(CONF_PIN_RESET): pins.GPIO_INTERNAL_INPUT_PIN_SCHEMA, + vol.Required(CONF_PIN_A): pins.internal_gpio_input_pin_schema, + 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(sensor.SENSOR_SCHEMA.schema) diff --git a/esphomeyaml/components/sensor/ultrasonic.py b/esphomeyaml/components/sensor/ultrasonic.py index 5303b6fdab..a3c5850aa8 100644 --- a/esphomeyaml/components/sensor/ultrasonic.py +++ b/esphomeyaml/components/sensor/ultrasonic.py @@ -12,8 +12,8 @@ MakeUltrasonicSensor = Application.MakeUltrasonicSensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeUltrasonicSensor), - vol.Required(CONF_TRIGGER_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, - vol.Required(CONF_ECHO_PIN): pins.GPIO_INTERNAL_INPUT_PIN_SCHEMA, + vol.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema, + vol.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema, vol.Exclusive(CONF_TIMEOUT_METER, 'timeout'): cv.positive_float, vol.Exclusive(CONF_TIMEOUT_TIME, 'timeout'): cv.positive_time_period_microseconds, vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, diff --git a/esphomeyaml/components/switch/gpio.py b/esphomeyaml/components/switch/gpio.py index e54b792e91..5641c21a91 100644 --- a/esphomeyaml/components/switch/gpio.py +++ b/esphomeyaml/components/switch/gpio.py @@ -10,7 +10,7 @@ MakeGPIOSwitch = Application.MakeGPIOSwitch PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch), - vol.Required(CONF_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, + vol.Required(CONF_PIN): pins.gpio_output_pin_schema, }).extend(switch.SWITCH_SCHEMA.schema) diff --git a/esphomeyaml/helpers.py b/esphomeyaml/helpers.py index 5da6e6d406..dc5a350dbc 100644 --- a/esphomeyaml/helpers.py +++ b/esphomeyaml/helpers.py @@ -483,7 +483,7 @@ class MockObj(Expression): obj.requires.append(self) return obj next_op = u'.' - if attr.startswith(u'P') and self.op != '::': + if attr.startswith(u'P') and self.op not in ['::', '']: attr = attr[1:] next_op = u'->' if attr.startswith(u'_'): diff --git a/esphomeyaml/pins.py b/esphomeyaml/pins.py index f94aa512a3..38bb97a9f6 100644 --- a/esphomeyaml/pins.py +++ b/esphomeyaml/pins.py @@ -213,10 +213,30 @@ PCF8574_INPUT_PIN_SCHEMA = PCF8574_OUTPUT_PIN_SCHEMA.extend({ vol.Optional(CONF_MODE): vol.All(vol.Upper, vol.Any("INPUT", "INPUT_PULLUP")), }) -GPIO_INTERNAL_OUTPUT_PIN_SCHEMA = vol.Any(shorthand_output_pin, GPIO_FULL_OUTPUT_PIN_SCHEMA) -GPIO_OUTPUT_PIN_SCHEMA = vol.Any(PCF8574_OUTPUT_PIN_SCHEMA, GPIO_INTERNAL_OUTPUT_PIN_SCHEMA) +def internal_gpio_output_pin_schema(value): + if isinstance(value, dict): + return GPIO_FULL_OUTPUT_PIN_SCHEMA(value) + return shorthand_output_pin(value) -GPIO_INTERNAL_INPUT_PIN_SCHEMA = vol.Any(shorthand_input_pin, GPIO_FULL_INPUT_PIN_SCHEMA) -GPIO_INPUT_PIN_SCHEMA = vol.Any(PCF8574_INPUT_PIN_SCHEMA, GPIO_INTERNAL_INPUT_PIN_SCHEMA) +def gpio_output_pin_schema(value): + if isinstance(value, dict): + if CONF_PCF8574 in value: + return PCF8574_OUTPUT_PIN_SCHEMA(value) + return GPIO_FULL_OUTPUT_PIN_SCHEMA(value) + return shorthand_output_pin(value) + + +def internal_gpio_input_pin_schema(value): + if isinstance(value, dict): + return GPIO_FULL_INPUT_PIN_SCHEMA(value) + return shorthand_input_pin(value) + + +def gpio_input_pin_schema(value): + if isinstance(value, dict): + if CONF_PCF8574 in value: + return PCF8574_INPUT_PIN_SCHEMA(value) + return GPIO_FULL_INPUT_PIN_SCHEMA(value) + return shorthand_input_pin(value)