esphome/esphome/components/sntp/time.py
Otto Winter 8e75980ebd
Cleanup dashboard JS (#491)
* Cleanup dashboard JS

* Add vscode

* Save start_mark/end_mark

* Updates

* Updates

* Remove need for cv.nameable

It's a bit hacky but removes so much bloat from integrations

* Add enum helper

* Document APIs, and Improvements

* Fixes

* Fixes

* Update PULL_REQUEST_TEMPLATE.md

* Updates

* Updates

* Updates
2019-04-22 21:56:30 +02:00

29 lines
897 B
Python

from esphome.components import time as time_
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.const import CONF_ID, CONF_SERVERS
DEPENDENCIES = ['network']
sntp_ns = cg.esphome_ns.namespace('sntp')
SNTPComponent = sntp_ns.class_('SNTPComponent', time_.RealTimeClock)
DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(SNTPComponent),
cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS):
cv.All(cv.ensure_list(cv.domain), cv.Length(min=1, max=3)),
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
servers = config[CONF_SERVERS]
servers += [''] * (3 - len(servers))
cg.add(var.set_servers(*servers))
yield cg.register_component(var, config)
yield time_.register_time(var, config)