mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Merge branch 'dev' into rc
This commit is contained in:
commit
d4c7e6c634
10 changed files with 179 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "esphomeyaml-beta",
|
||||
"version": "1.9.0b4",
|
||||
"version": "1.9.0b5",
|
||||
"slug": "esphomeyaml-beta",
|
||||
"description": "Beta version of esphomeyaml HassIO add-on.",
|
||||
"url": "https://beta.esphomelib.com/esphomeyaml/index.html",
|
||||
|
|
|
@ -3,9 +3,10 @@ import voluptuous as vol
|
|||
from esphomeyaml import config_validation as cv, pins
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_RUN_CYCLES, CONF_RUN_DURATION, \
|
||||
CONF_SLEEP_DURATION, CONF_WAKEUP_PIN
|
||||
CONF_SLEEP_DURATION, CONF_WAKEUP_PIN, CONF_MODE, CONF_PINS
|
||||
from esphomeyaml.helpers import Action, App, Component, Pvariable, TemplateArguments, add, \
|
||||
esphomelib_ns, get_variable, gpio_input_pin_expression, setup_component
|
||||
esphomelib_ns, get_variable, gpio_input_pin_expression, setup_component, global_ns, \
|
||||
StructInitializer
|
||||
|
||||
|
||||
def validate_pin_number(value):
|
||||
|
@ -27,7 +28,15 @@ WAKEUP_PIN_MODES = {
|
|||
'INVERT_WAKEUP': WakeupPinMode.WAKEUP_PIN_MODE_INVERT_WAKEUP,
|
||||
}
|
||||
|
||||
esp_sleep_ext1_wakeup_mode_t = global_ns.enum('esp_sleep_ext1_wakeup_mode_t')
|
||||
Ext1Wakeup = esphomelib_ns.struct('Ext1Wakeup')
|
||||
EXT1_WAKEUP_MODES = {
|
||||
'ALL_LOW': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ALL_LOW,
|
||||
'ANY_HIGH': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_HIGH,
|
||||
}
|
||||
|
||||
CONF_WAKEUP_PIN_MODE = 'wakeup_pin_mode'
|
||||
CONF_ESP32_EXT1_WAKEUP = 'esp32_ext1_wakeup'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(DeepSleepComponent),
|
||||
|
@ -36,6 +45,11 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
validate_pin_number),
|
||||
vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, vol.Upper,
|
||||
cv.one_of(*WAKEUP_PIN_MODES)),
|
||||
vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All(cv.only_on_esp32, vol.Schema({
|
||||
vol.Required(CONF_PINS): vol.All(cv.ensure_list, [pins.shorthand_input_pin],
|
||||
[validate_pin_number]),
|
||||
vol.Required(CONF_MODE): vol.All(vol.Upper, cv.one_of(*EXT1_WAKEUP_MODES)),
|
||||
})),
|
||||
vol.Optional(CONF_RUN_CYCLES): cv.positive_int,
|
||||
vol.Optional(CONF_RUN_DURATION): cv.positive_time_period_milliseconds,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
@ -57,6 +71,18 @@ def to_code(config):
|
|||
if CONF_RUN_DURATION in config:
|
||||
add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION]))
|
||||
|
||||
if CONF_ESP32_EXT1_WAKEUP in config:
|
||||
conf = config[CONF_ESP32_EXT1_WAKEUP]
|
||||
mask = 0
|
||||
for pin in conf[CONF_PINS]:
|
||||
mask |= 1 << pin[CONF_NUMBER]
|
||||
struct = StructInitializer(
|
||||
Ext1Wakeup,
|
||||
('mask', mask),
|
||||
('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]])
|
||||
)
|
||||
add(deep_sleep.set_ext1_wakeup(struct))
|
||||
|
||||
setup_component(deep_sleep, config)
|
||||
|
||||
|
||||
|
|
52
esphomeyaml/components/my9231.py
Normal file
52
esphomeyaml/components/my9231.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.const import (CONF_DATA_PIN, CONF_CLOCK_PIN, CONF_NUM_CHANNELS,
|
||||
CONF_NUM_CHIPS, CONF_BIT_DEPTH, CONF_ID,
|
||||
CONF_UPDATE_ON_BOOT)
|
||||
from esphomeyaml.helpers import (gpio_output_pin_expression, App, Pvariable,
|
||||
add, setup_component, Component)
|
||||
|
||||
MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component)
|
||||
|
||||
|
||||
MY9231_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent),
|
||||
vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_NUM_CHANNELS): vol.All(vol.Coerce(int),
|
||||
vol.Range(3, 1020)),
|
||||
vol.Optional(CONF_NUM_CHIPS): vol.All(vol.Coerce(int),
|
||||
vol.Range(1, 255)),
|
||||
vol.Optional(CONF_BIT_DEPTH): vol.All(vol.Coerce(int),
|
||||
cv.one_of(8, 12, 14, 16)),
|
||||
vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [MY9231_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
di = None
|
||||
for di in gpio_output_pin_expression(conf[CONF_DATA_PIN]):
|
||||
yield
|
||||
dcki = None
|
||||
for dcki in gpio_output_pin_expression(conf[CONF_CLOCK_PIN]):
|
||||
yield
|
||||
rhs = App.make_my9231_component(di, dcki)
|
||||
my9231 = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_NUM_CHANNELS in conf:
|
||||
add(my9231.set_num_channels(conf[CONF_NUM_CHANNELS]))
|
||||
if CONF_NUM_CHIPS in conf:
|
||||
add(my9231.set_num_chips(conf[CONF_NUM_CHIPS]))
|
||||
if CONF_BIT_DEPTH in conf:
|
||||
add(my9231.set_bit_depth(conf[CONF_BIT_DEPTH]))
|
||||
if CONF_UPDATE_ON_BOOT in conf:
|
||||
add(my9231.set_update(conf[CONF_UPDATE_ON_BOOT]))
|
||||
setup_component(my9231, conf)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
|
@ -1,19 +1,18 @@
|
|||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression, setup_component, \
|
||||
Component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266, CONF_FREQUENCY
|
||||
from esphomeyaml.helpers import App, Component, Pvariable, gpio_output_pin_expression, \
|
||||
setup_component, add
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]
|
||||
|
||||
|
||||
def valid_pwm_pin(value):
|
||||
if value[CONF_NUMBER] > 16:
|
||||
raise ESPHomeYAMLError(u"ESP8266: Only pins 0-16 support PWM.")
|
||||
num = value[CONF_NUMBER]
|
||||
cv.one_of(0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16)(num)
|
||||
return value
|
||||
|
||||
|
||||
|
@ -22,6 +21,7 @@ ESP8266PWMOutput = output.output_ns.class_('ESP8266PWMOutput', output.FloatOutpu
|
|||
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(ESP8266PWMOutput),
|
||||
vol.Required(CONF_PIN): vol.All(pins.internal_gpio_output_pin_schema, valid_pwm_pin),
|
||||
vol.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=1.0e-6)),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
|
@ -30,6 +30,10 @@ def to_code(config):
|
|||
yield
|
||||
rhs = App.make_esp8266_pwm_output(pin)
|
||||
gpio = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
if CONF_FREQUENCY in config:
|
||||
add(gpio.set_frequency(config[CONF_FREQUENCY]))
|
||||
|
||||
output.setup_output_platform(gpio, config)
|
||||
setup_component(gpio, config)
|
||||
|
||||
|
|
35
esphomeyaml/components/output/my9231.py
Normal file
35
esphomeyaml/components/output/my9231.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.components.my9231 import MY9231OutputComponent
|
||||
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_MY9231_ID, CONF_POWER_SUPPLY
|
||||
from esphomeyaml.helpers import Pvariable, get_variable, setup_component
|
||||
|
||||
DEPENDENCIES = ['my9231']
|
||||
|
||||
Channel = MY9231OutputComponent.class_('Channel', output.FloatOutput)
|
||||
|
||||
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(Channel),
|
||||
vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int),
|
||||
vol.Range(min=0, max=65535)),
|
||||
cv.GenerateID(CONF_MY9231_ID): cv.use_variable_id(MY9231OutputComponent),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
power_supply = None
|
||||
if CONF_POWER_SUPPLY in config:
|
||||
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
|
||||
yield
|
||||
my9231 = None
|
||||
for my9231 in get_variable(config[CONF_MY9231_ID]):
|
||||
yield
|
||||
rhs = my9231.create_channel(config[CONF_CHANNEL], power_supply)
|
||||
out = Pvariable(config[CONF_ID], rhs)
|
||||
output.setup_output_platform(out, config, skip_power_supply=True)
|
||||
setup_component(out, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
|
@ -562,7 +562,7 @@ def percentage(value):
|
|||
if value > 1:
|
||||
msg = "Percentage must not be higher than 100%."
|
||||
if not has_percent_sign:
|
||||
msg += " Please don't put to put a percent sign after the number!"
|
||||
msg += " Please put a percent sign after the number!"
|
||||
raise vol.Invalid(msg)
|
||||
return zero_to_one_float(value)
|
||||
|
||||
|
|
|
@ -365,8 +365,12 @@ CONF_TIME_ID = 'time_id'
|
|||
CONF_RESTORE_STATE = 'restore_state'
|
||||
CONF_TIMING = 'timing'
|
||||
CONF_INVALID_COOLDOWN = 'invalid_cooldown'
|
||||
CONF_MY9231_ID = 'my9231_id'
|
||||
CONF_NUM_CHANNELS = 'num_channels'
|
||||
CONF_UPDATE_ON_BOOT = 'update_on_boot'
|
||||
CONF_INITIAL_VALUE = 'initial_value'
|
||||
CONF_RESTORE_VALUE = 'restore_value'
|
||||
CONF_PINS = 'pins'
|
||||
|
||||
|
||||
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
|
||||
|
|
|
@ -16,6 +16,7 @@ from esphomeyaml.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266
|
|||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, NoArg, Pvariable, RawExpression, add, const_char_p, \
|
||||
esphomelib_ns, relative_path
|
||||
from esphomeyaml.util import safe_print
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -232,10 +233,16 @@ def update_esphomelib_repo(config):
|
|||
# local changes, cannot update
|
||||
_LOGGER.warn("Local changes in esphomelib copy from git. Will not auto-update.")
|
||||
return
|
||||
rc, _, _ = run_command('git', '-C', esphomelib_path, 'pull')
|
||||
_LOGGER.info("Updating esphomelib copy from git (%s)", esphomelib_path)
|
||||
rc, stdout, _ = run_command('git', '-c', 'color.ui=always', '-C', esphomelib_path,
|
||||
'pull', '--stat')
|
||||
if rc != 0:
|
||||
_LOGGER.warn("Couldn't auto-update local git copy of esphomelib.")
|
||||
return
|
||||
stdout = stdout.strip()
|
||||
if 'Already up to date' in stdout:
|
||||
return
|
||||
safe_print(stdout)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
|
|
|
@ -3,7 +3,6 @@ import logging
|
|||
import random
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
|
||||
|
@ -95,7 +94,8 @@ def check_error(data, expect):
|
|||
if dat == RESPONSE_ERROR_MAGIC:
|
||||
raise OTAError("Error: Invalid magic byte")
|
||||
if dat == RESPONSE_ERROR_UPDATE_PREPARE:
|
||||
raise OTAError("Error: Couldn't prepare flash memory for update. Is the binary too big?")
|
||||
raise OTAError("Error: Couldn't prepare flash memory for update. Is the binary too big? "
|
||||
"Please try restarting the ESP.")
|
||||
if dat == RESPONSE_ERROR_AUTH_INVALID:
|
||||
raise OTAError("Error: Authentication invalid. Is the password correct?")
|
||||
if dat == RESPONSE_ERROR_WRITING_FLASH:
|
||||
|
@ -121,7 +121,7 @@ def send_check(sock, data, msg):
|
|||
data = ''.join([chr(x) for x in data])
|
||||
elif isinstance(data, int):
|
||||
data = chr(data)
|
||||
sock.send(data)
|
||||
sock.sendall(data)
|
||||
except socket.error as err:
|
||||
raise OTAError("Error sending {}: {}".format(msg, err))
|
||||
|
||||
|
@ -133,6 +133,8 @@ def perform_ota(sock, password, file_handle, filename):
|
|||
file_handle.seek(0)
|
||||
_LOGGER.debug("MD5 of binary is %s", file_md5)
|
||||
|
||||
# Enable nodelay, we need it for phase 1
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
send_check(sock, MAGIC_BYTES, 'magic bytes')
|
||||
|
||||
_, version = receive_exactly(sock, 2, 'version', RESPONSE_OK)
|
||||
|
@ -179,7 +181,12 @@ def perform_ota(sock, password, file_handle, filename):
|
|||
send_check(sock, file_md5, 'file checksum')
|
||||
receive_exactly(sock, 1, 'file checksum', RESPONSE_BIN_MD5_OK)
|
||||
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 4096)
|
||||
# Disable nodelay for transfer
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 0)
|
||||
# Limit send buffer (usually around 100kB) in order to have progress bar
|
||||
# show the actual progress
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192)
|
||||
|
||||
offset = 0
|
||||
update_progress(0.0)
|
||||
while True:
|
||||
|
@ -196,13 +203,15 @@ def perform_ota(sock, password, file_handle, filename):
|
|||
|
||||
update_progress(offset / float(file_size))
|
||||
|
||||
# Enable nodelay for last checks
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
|
||||
sys.stderr.write('\n')
|
||||
_LOGGER.info("Waiting for result...")
|
||||
|
||||
receive_exactly(sock, 1, 'receive OK', RESPONSE_RECEIVE_OK)
|
||||
receive_exactly(sock, 1, 'Update end', RESPONSE_UPDATE_END_OK)
|
||||
send_check(sock, RESPONSE_OK, 'end acknowledgement')
|
||||
time.sleep(0.25)
|
||||
|
||||
_LOGGER.info("OTA successful")
|
||||
|
||||
|
|
|
@ -571,6 +571,13 @@ pca9685:
|
|||
frequency: 500
|
||||
address: 0x0
|
||||
|
||||
my9231:
|
||||
data_pin: GPIO12
|
||||
clock_pin: GPIO14
|
||||
num_channels: 6
|
||||
num_chips: 2
|
||||
bit_depth: 16
|
||||
|
||||
output:
|
||||
- platform: gpio
|
||||
pin: GPIO26
|
||||
|
@ -615,6 +622,24 @@ output:
|
|||
number: 0
|
||||
mode: OUTPUT
|
||||
inverted: False
|
||||
- platform: my9231
|
||||
id: my_0
|
||||
channel: 0
|
||||
- platform: my9231
|
||||
id: my_1
|
||||
channel: 1
|
||||
- platform: my9231
|
||||
id: my_2
|
||||
channel: 2
|
||||
- platform: my9231
|
||||
id: my_3
|
||||
channel: 3
|
||||
- platform: my9231
|
||||
id: my_4
|
||||
channel: 4
|
||||
- platform: my9231
|
||||
id: my_5
|
||||
channel: 5
|
||||
|
||||
light:
|
||||
- platform: binary
|
||||
|
|
Loading…
Reference in a new issue