2018-04-07 01:23:03 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2018-04-18 18:43:13 +02:00
|
|
|
from esphomeyaml import core
|
2018-10-14 19:14:28 +02:00
|
|
|
import esphomeyaml.config_validation as cv
|
2018-04-07 01:23:03 +02:00
|
|
|
from esphomeyaml.const import CONF_ID, CONF_OTA, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE, \
|
2018-04-18 18:43:13 +02:00
|
|
|
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
|
2018-04-07 01:23:03 +02:00
|
|
|
from esphomeyaml.core import ESPHomeYAMLError
|
2018-11-12 23:30:31 +01:00
|
|
|
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, Component
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-11-12 23:30:31 +01:00
|
|
|
OTAComponent = esphomelib_ns.class_('OTAComponent', Component)
|
2018-06-02 22:22:20 +02:00
|
|
|
|
2018-04-18 18:43:13 +02:00
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
2018-06-02 22:22:20 +02:00
|
|
|
cv.GenerateID(): cv.declare_variable_id(OTAComponent),
|
2018-04-07 01:23:03 +02:00
|
|
|
vol.Optional(CONF_SAFE_MODE, default=True): cv.boolean,
|
|
|
|
vol.Optional(CONF_PORT): cv.port,
|
|
|
|
vol.Optional(CONF_PASSWORD): cv.string,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
|
|
|
rhs = App.init_ota()
|
2018-06-02 22:22:20 +02:00
|
|
|
ota = Pvariable(config[CONF_ID], rhs)
|
2018-04-07 01:23:03 +02:00
|
|
|
if CONF_PASSWORD in config:
|
2018-10-14 19:14:28 +02:00
|
|
|
add(ota.set_auth_password(config[CONF_PASSWORD]))
|
2018-06-06 11:12:14 +02:00
|
|
|
if CONF_PORT in config:
|
|
|
|
add(ota.set_port(config[CONF_PORT]))
|
2018-04-07 01:23:03 +02:00
|
|
|
if config[CONF_SAFE_MODE]:
|
|
|
|
add(ota.start_safe_mode())
|
|
|
|
|
|
|
|
|
|
|
|
def get_port(config):
|
|
|
|
if CONF_PORT in config[CONF_OTA]:
|
|
|
|
return config[CONF_OTA][CONF_PORT]
|
2018-04-18 18:43:13 +02:00
|
|
|
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
2018-04-07 01:23:03 +02:00
|
|
|
return 3232
|
2018-04-18 18:43:13 +02:00
|
|
|
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
2018-04-07 01:23:03 +02:00
|
|
|
return 8266
|
|
|
|
raise ESPHomeYAMLError(u"Invalid ESP Platform for ESP OTA port.")
|
|
|
|
|
|
|
|
|
|
|
|
def get_auth(config):
|
|
|
|
return config[CONF_OTA].get(CONF_PASSWORD, '')
|
2018-04-18 18:43:13 +02:00
|
|
|
|
|
|
|
|
2018-05-06 15:56:12 +02:00
|
|
|
BUILD_FLAGS = '-DUSE_OTA'
|
2018-10-14 19:14:28 +02:00
|
|
|
REQUIRED_BUILD_FLAGS = '-DUSE_NEW_OTA'
|
2018-05-14 11:50:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def lib_deps(config):
|
|
|
|
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
|
|
|
return ['ArduinoOTA', 'Update', 'ESPmDNS']
|
|
|
|
return ['Hash', 'ESP8266mDNS', 'ArduinoOTA']
|