initial commit.
This commit is contained in:
47
components/truma_inetbox/time/TrumaTime.cpp
Normal file
47
components/truma_inetbox/time/TrumaTime.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "TrumaTime.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/truma_inetbox/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace truma_inetbox {
|
||||
|
||||
static const char *const TAG = "truma_inetbox.time";
|
||||
|
||||
void TrumaTime::setup() {
|
||||
this->parent_->register_listener([this](const StatusFrameClock *status_clock) {
|
||||
if (this->auto_disable_count_ > 0) {
|
||||
if (this->read_time() && this->auto_disable_) {
|
||||
this->auto_disable_count_--;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TrumaTime::update() {}
|
||||
|
||||
void TrumaTime::dump_config() { ESP_LOGCONFIG(TAG, "Truma Time", this); }
|
||||
|
||||
bool TrumaTime::read_time() {
|
||||
if (!this->parent_->get_status_clock_valid()) {
|
||||
return false;
|
||||
}
|
||||
auto status_clock = this->parent_->get_status_clock();
|
||||
|
||||
time::ESPTime rtc_time{.second = status_clock->clock_second,
|
||||
.minute = status_clock->clock_minute,
|
||||
.hour = status_clock->clock_hour,
|
||||
.day_of_week = 1,
|
||||
.day_of_month = 1,
|
||||
.day_of_year = 1, // ignored by recalc_timestamp_utc(false)
|
||||
.month = 1,
|
||||
.year = 2020};
|
||||
if (!rtc_time.is_valid()) {
|
||||
ESP_LOGE(TAG, "Invalid RTC time, not syncing to system clock.");
|
||||
return false;
|
||||
}
|
||||
time::RealTimeClock::synchronize_epoch_(rtc_time.timestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace truma_inetbox
|
||||
} // namespace esphome
|
||||
26
components/truma_inetbox/time/TrumaTime.h
Normal file
26
components/truma_inetbox/time/TrumaTime.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/time/real_time_clock.h"
|
||||
#include "esphome/components/truma_inetbox/TrumaiNetBoxApp.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace truma_inetbox {
|
||||
|
||||
class TrumaTime : public time::RealTimeClock, public Parented<TrumaiNetBoxApp> {
|
||||
public:
|
||||
void setup() override;
|
||||
void update() override;
|
||||
void dump_config() override;
|
||||
|
||||
bool read_time();
|
||||
|
||||
void set_auto_disable(bool val) { this->auto_disable_ = val; }
|
||||
|
||||
protected:
|
||||
bool auto_disable_ = false;
|
||||
u_int8_t auto_disable_count_ = 3;
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace truma_inetbox
|
||||
} // namespace esphome
|
||||
34
components/truma_inetbox/time/__init__.py
Normal file
34
components/truma_inetbox/time/__init__.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from esphome.components import time
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_TYPE,
|
||||
)
|
||||
from .. import truma_inetbox_ns, CONF_TRUMA_INETBOX_ID, TrumaINetBoxApp
|
||||
|
||||
DEPENDENCIES = ["truma_inetbox"]
|
||||
CODEOWNERS = ["@Fabian-Schmidt"]
|
||||
|
||||
CONF_AUTO_DISABLE = "auto_disable"
|
||||
|
||||
TrumaTime = truma_inetbox_ns.class_(
|
||||
"TrumaTime", time.RealTimeClock, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = time.TIME_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(TrumaTime),
|
||||
cv.GenerateID(CONF_TRUMA_INETBOX_ID): cv.use_id(TrumaINetBoxApp),
|
||||
cv.Optional(CONF_AUTO_DISABLE, default=True): cv.boolean,
|
||||
}
|
||||
).extend(cv.polling_component_schema("never"))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await time.register_time(var, config)
|
||||
await cg.register_parented(var, config[CONF_TRUMA_INETBOX_ID])
|
||||
|
||||
if config[CONF_AUTO_DISABLE]:
|
||||
cg.add(var.set_auto_disable(config[CONF_AUTO_DISABLE]))
|
||||
Reference in New Issue
Block a user