mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
host platform: improvements and bugfixes (#6137)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
0ede4a3095
commit
f3ef05f5c3
7 changed files with 36 additions and 7 deletions
|
@ -4,6 +4,7 @@ from esphome.const import (
|
|||
KEY_TARGET_FRAMEWORK,
|
||||
KEY_TARGET_PLATFORM,
|
||||
PLATFORM_HOST,
|
||||
CONF_MAC_ADDRESS,
|
||||
)
|
||||
from esphome.core import CORE
|
||||
from esphome.helpers import IS_MACOS
|
||||
|
@ -28,13 +29,18 @@ def set_core_data(config):
|
|||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema({}),
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_MAC_ADDRESS, default="98:35:69:ab:f6:79"): cv.mac_address,
|
||||
}
|
||||
),
|
||||
set_core_data,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
cg.add_build_flag("-DUSE_HOST")
|
||||
cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts)
|
||||
cg.add_build_flag("-std=c++17")
|
||||
cg.add_build_flag("-lsodium")
|
||||
if IS_MACOS:
|
||||
|
|
|
@ -212,6 +212,14 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) {
|
|||
return;
|
||||
#endif
|
||||
#ifdef USE_HOST
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer, sizeof buffer, "[%H:%M:%S]", timeinfo);
|
||||
fputs(buffer, stdout);
|
||||
puts(msg);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace sntp {
|
|||
static const char *const TAG = "sntp";
|
||||
|
||||
void SNTPComponent::setup() {
|
||||
#ifndef USE_HOST
|
||||
ESP_LOGCONFIG(TAG, "Setting up SNTP...");
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
if (sntp_enabled()) {
|
||||
|
@ -48,6 +49,7 @@ void SNTPComponent::setup() {
|
|||
#endif
|
||||
|
||||
sntp_init();
|
||||
#endif
|
||||
}
|
||||
void SNTPComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "SNTP Time:");
|
||||
|
@ -57,7 +59,7 @@ void SNTPComponent::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
|
||||
}
|
||||
void SNTPComponent::update() {
|
||||
#ifndef USE_ESP_IDF
|
||||
#if !defined(USE_ESP_IDF) && !defined(USE_HOST)
|
||||
// force resync
|
||||
if (sntp_enabled()) {
|
||||
sntp_stop();
|
||||
|
|
|
@ -28,7 +28,7 @@ class Filter {
|
|||
* @param value The new value.
|
||||
* @return An optional string, the new value that should be pushed out.
|
||||
*/
|
||||
virtual optional<std::string> new_value(std::string value);
|
||||
virtual optional<std::string> new_value(std::string value) = 0;
|
||||
|
||||
/// Initialize this filter, please note this can be called more than once.
|
||||
virtual void initialize(TextSensor *parent, Filter *next);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "esphome/core/optional.h"
|
||||
|
||||
|
|
|
@ -11,6 +11,12 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef USE_HOST
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if defined(USE_ESP8266)
|
||||
#include <osapi.h>
|
||||
#include <user_interface.h>
|
||||
|
@ -415,7 +421,7 @@ std::string value_accuracy_to_string(float value, int8_t accuracy_decimals) {
|
|||
int8_t step_to_accuracy_decimals(float step) {
|
||||
// use printf %g to find number of digits based on temperature step
|
||||
char buf[32];
|
||||
sprintf(buf, "%.5g", step);
|
||||
snprintf(buf, sizeof buf, "%.5g", step);
|
||||
|
||||
std::string str{buf};
|
||||
size_t dot_pos = str.find('.');
|
||||
|
@ -551,7 +557,10 @@ void HighFrequencyLoopRequester::stop() {
|
|||
bool HighFrequencyLoopRequester::is_high_frequency() { return num_requests > 0; }
|
||||
|
||||
void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parameter)
|
||||
#if defined(USE_ESP32)
|
||||
#if defined(USE_HOST)
|
||||
static const uint8_t esphome_host_mac_address[6] = USE_ESPHOME_HOST_MAC_ADDRESS;
|
||||
memcpy(mac, esphome_host_mac_address, sizeof(esphome_host_mac_address));
|
||||
#elif defined(USE_ESP32)
|
||||
#if defined(CONFIG_SOC_IEEE802154_SUPPORTED) || defined(USE_ESP32_IGNORE_EFUSE_MAC_CRC)
|
||||
// When CONFIG_SOC_IEEE802154_SUPPORTED is defined, esp_efuse_mac_get_default
|
||||
// returns the 802.15.4 EUI-64 address. Read directly from eFuse instead.
|
||||
|
@ -569,6 +578,8 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame
|
|||
WiFi.macAddress(mac);
|
||||
#elif defined(USE_LIBRETINY)
|
||||
WiFi.macAddress(mac);
|
||||
#else
|
||||
// this should be an error, but that messes with CI checks. #error No mac address method defined
|
||||
#endif
|
||||
}
|
||||
std::string get_mac_address() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
|
Loading…
Reference in a new issue