2019-05-13 13:11:02 +02:00
|
|
|
from esphome.components import time as time_
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
import esphome.codegen as cg
|
|
|
|
from esphome.const import CONF_ID
|
|
|
|
from .. import gps_ns, GPSListener, CONF_GPS_ID, GPS
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
DEPENDENCIES = ["gps"]
|
2019-05-13 13:11:02 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
GPSTime = gps_ns.class_(
|
|
|
|
"GPSTime", cg.PollingComponent, time_.RealTimeClock, GPSListener
|
|
|
|
)
|
2019-05-13 13:11:02 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(GPSTime),
|
|
|
|
cv.GenerateID(CONF_GPS_ID): cv.use_id(GPS),
|
|
|
|
}
|
|
|
|
).extend(cv.polling_component_schema("5min"))
|
2019-05-13 13:11:02 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2019-05-13 13:11:02 +02:00
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2021-05-24 10:58:29 +02:00
|
|
|
await time_.register_time(var, config)
|
|
|
|
await cg.register_component(var, config)
|
2019-05-13 13:11:02 +02:00
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
paren = await cg.get_variable(config[CONF_GPS_ID])
|
2019-05-13 13:11:02 +02:00
|
|
|
cg.add(paren.register_listener(var))
|