mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Add host time platform; remove host support from sntp. (#6854)
This commit is contained in:
parent
78b48209aa
commit
cdf83c5d8c
8 changed files with 69 additions and 22 deletions
|
@ -167,7 +167,8 @@ esphome/components/homeassistant/* @OttoWinter
|
||||||
esphome/components/honeywell_hih_i2c/* @Benichou34
|
esphome/components/honeywell_hih_i2c/* @Benichou34
|
||||||
esphome/components/honeywellabp/* @RubyBailey
|
esphome/components/honeywellabp/* @RubyBailey
|
||||||
esphome/components/honeywellabp2_i2c/* @jpfaff
|
esphome/components/honeywellabp2_i2c/* @jpfaff
|
||||||
esphome/components/host/* @esphome/core
|
esphome/components/host/* @clydebarrow @esphome/core
|
||||||
|
esphome/components/host/time/* @clydebarrow
|
||||||
esphome/components/hrxl_maxsonar_wr/* @netmikey
|
esphome/components/hrxl_maxsonar_wr/* @netmikey
|
||||||
esphome/components/hte501/* @Stock-M
|
esphome/components/hte501/* @Stock-M
|
||||||
esphome/components/htu31d/* @betterengineering
|
esphome/components/htu31d/* @betterengineering
|
||||||
|
|
|
@ -16,7 +16,7 @@ from .const import KEY_HOST
|
||||||
# force import gpio to register pin schema
|
# force import gpio to register pin schema
|
||||||
from .gpio import host_pin_to_code # noqa
|
from .gpio import host_pin_to_code # noqa
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core", "@clydebarrow"]
|
||||||
AUTO_LOAD = ["network"]
|
AUTO_LOAD = ["network"]
|
||||||
|
|
||||||
|
|
||||||
|
|
20
esphome/components/host/time/__init__.py
Normal file
20
esphome/components/host/time/__init__.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
|
from esphome.const import CONF_ID
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.components import time as time_
|
||||||
|
|
||||||
|
CODEOWNERS = ["@clydebarrow"]
|
||||||
|
|
||||||
|
time_ns = cg.esphome_ns.namespace("host")
|
||||||
|
HostTime = time_ns.class_("HostTime", time_.RealTimeClock)
|
||||||
|
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(HostTime),
|
||||||
|
}
|
||||||
|
).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
await time_.register_time(var, config)
|
15
esphome/components/host/time/host_time.h
Normal file
15
esphome/components/host/time/host_time.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/components/time/real_time_clock.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace host {
|
||||||
|
|
||||||
|
class HostTime : public time::RealTimeClock {
|
||||||
|
public:
|
||||||
|
void update() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace host
|
||||||
|
} // namespace esphome
|
|
@ -20,7 +20,6 @@ namespace sntp {
|
||||||
static const char *const TAG = "sntp";
|
static const char *const TAG = "sntp";
|
||||||
|
|
||||||
void SNTPComponent::setup() {
|
void SNTPComponent::setup() {
|
||||||
#ifndef USE_HOST
|
|
||||||
ESP_LOGCONFIG(TAG, "Setting up SNTP...");
|
ESP_LOGCONFIG(TAG, "Setting up SNTP...");
|
||||||
#if defined(USE_ESP_IDF)
|
#if defined(USE_ESP_IDF)
|
||||||
if (esp_sntp_enabled()) {
|
if (esp_sntp_enabled()) {
|
||||||
|
@ -44,7 +43,6 @@ void SNTPComponent::setup() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sntp_init();
|
sntp_init();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
void SNTPComponent::dump_config() {
|
void SNTPComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "SNTP Time:");
|
ESP_LOGCONFIG(TAG, "SNTP Time:");
|
||||||
|
@ -54,7 +52,7 @@ void SNTPComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
|
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
|
||||||
}
|
}
|
||||||
void SNTPComponent::update() {
|
void SNTPComponent::update() {
|
||||||
#if !defined(USE_ESP_IDF) && !defined(USE_HOST)
|
#if !defined(USE_ESP_IDF)
|
||||||
// force resync
|
// force resync
|
||||||
if (sntp_enabled()) {
|
if (sntp_enabled()) {
|
||||||
sntp_stop();
|
sntp_stop();
|
||||||
|
|
|
@ -2,24 +2,41 @@ from esphome.components import time as time_
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
from esphome.const import CONF_ID, CONF_SERVERS
|
from esphome.const import (
|
||||||
|
CONF_ID,
|
||||||
|
CONF_SERVERS,
|
||||||
|
PLATFORM_ESP32,
|
||||||
|
PLATFORM_ESP8266,
|
||||||
|
PLATFORM_RP2040,
|
||||||
|
PLATFORM_RTL87XX,
|
||||||
|
PLATFORM_BK72XX,
|
||||||
|
)
|
||||||
|
|
||||||
DEPENDENCIES = ["network"]
|
DEPENDENCIES = ["network"]
|
||||||
sntp_ns = cg.esphome_ns.namespace("sntp")
|
sntp_ns = cg.esphome_ns.namespace("sntp")
|
||||||
SNTPComponent = sntp_ns.class_("SNTPComponent", time_.RealTimeClock)
|
SNTPComponent = sntp_ns.class_("SNTPComponent", time_.RealTimeClock)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]
|
DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]
|
||||||
|
|
||||||
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
|
CONFIG_SCHEMA = cv.All(
|
||||||
{
|
time_.TIME_SCHEMA.extend(
|
||||||
cv.GenerateID(): cv.declare_id(SNTPComponent),
|
{
|
||||||
cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS): cv.All(
|
cv.GenerateID(): cv.declare_id(SNTPComponent),
|
||||||
cv.ensure_list(cv.Any(cv.domain, cv.hostname)), cv.Length(min=1, max=3)
|
cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS): cv.All(
|
||||||
),
|
cv.ensure_list(cv.Any(cv.domain, cv.hostname)), cv.Length(min=1, max=3)
|
||||||
}
|
),
|
||||||
).extend(cv.COMPONENT_SCHEMA)
|
}
|
||||||
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
|
cv.only_on(
|
||||||
|
[
|
||||||
|
PLATFORM_ESP32,
|
||||||
|
PLATFORM_ESP8266,
|
||||||
|
PLATFORM_RP2040,
|
||||||
|
PLATFORM_BK72XX,
|
||||||
|
PLATFORM_RTL87XX,
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
time:
|
time:
|
||||||
- platform: sntp
|
- platform: host
|
||||||
id: esptime
|
id: esptime
|
||||||
timezone: Australia/Sydney
|
timezone: Australia/Sydney
|
||||||
|
|
||||||
logger:
|
logger:
|
||||||
level: VERBOSE
|
level: VERBOSE
|
||||||
logs:
|
|
||||||
lvgl: INFO
|
|
||||||
display: DEBUG
|
|
||||||
sensor: INFO
|
|
||||||
vnc: DEBUG
|
|
||||||
|
|
||||||
host:
|
host:
|
||||||
mac_address: "62:23:45:AF:B3:DD"
|
mac_address: "62:23:45:AF:B3:DD"
|
||||||
|
|
1
tests/components/sntp/test.bk72xx.yaml
Normal file
1
tests/components/sntp/test.bk72xx.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
Loading…
Reference in a new issue