mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
make time components polling components (#1443)
* make real time clock components polling components * add test
This commit is contained in:
@@ -6,12 +6,12 @@ from .. import gps_ns, GPSListener, CONF_GPS_ID, GPS
|
||||
|
||||
DEPENDENCIES = ['gps']
|
||||
|
||||
GPSTime = gps_ns.class_('GPSTime', time_.RealTimeClock, GPSListener)
|
||||
GPSTime = gps_ns.class_('GPSTime', cg.PollingComponent, time_.RealTimeClock, GPSListener)
|
||||
|
||||
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(GPSTime),
|
||||
cv.GenerateID(CONF_GPS_ID): cv.use_id(GPS),
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
}).extend(cv.polling_component_schema('5min'))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
|
||||
@@ -9,13 +9,11 @@ namespace gps {
|
||||
|
||||
class GPSTime : public time::RealTimeClock, public GPSListener {
|
||||
public:
|
||||
void update() override { this->from_tiny_gps_(this->get_tiny_gps()); };
|
||||
void on_update(TinyGPSPlus &tiny_gps) override {
|
||||
if (!this->has_time_)
|
||||
this->from_tiny_gps_(tiny_gps);
|
||||
}
|
||||
void setup() override {
|
||||
this->set_interval(5 * 60 * 1000, [this]() { this->from_tiny_gps_(this->get_tiny_gps()); });
|
||||
}
|
||||
|
||||
protected:
|
||||
void from_tiny_gps_(TinyGPSPlus &tiny_gps);
|
||||
|
||||
Reference in New Issue
Block a user