mirror of
https://github.com/nekorevend/esphome-emporia-vue-utility.git
synced 2026-01-09 13:00:38 -07:00
MVP: Works for me! Not idiomatic yet.
This commit is contained in:
@@ -4,10 +4,6 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace emporia_vue_utility {
|
namespace emporia_vue_utility {
|
||||||
|
|
||||||
void EmporiaVueUtility::set_update_interval(uint32_t update_interval) {
|
|
||||||
this->update_interval_ = update_interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmporiaVueUtility::setup() {
|
void EmporiaVueUtility::setup() {
|
||||||
#if USE_LED_PINS
|
#if USE_LED_PINS
|
||||||
pinMode(LED_PIN_LINK, OUTPUT);
|
pinMode(LED_PIN_LINK, OUTPUT);
|
||||||
@@ -19,12 +15,14 @@ void EmporiaVueUtility::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmporiaVueUtility::update() {
|
void EmporiaVueUtility::update() {
|
||||||
// send_meter_request();
|
// This seems to be called incessantly instead of at the set update interval...
|
||||||
|
// ESP_LOGD(TAG, "Got update call with an instructed interval of %d sec", this->update_interval_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmporiaVueUtility::loop() {
|
void EmporiaVueUtility::loop() {
|
||||||
static time_t next_meter_request;
|
static time_t next_meter_request;
|
||||||
static time_t next_meter_join;
|
static time_t next_meter_join;
|
||||||
|
static time_t next_version_request = 0;
|
||||||
static uint8_t startup_step;
|
static uint8_t startup_step;
|
||||||
char msg_type = 0;
|
char msg_type = 0;
|
||||||
size_t msg_len = 0;
|
size_t msg_len = 0;
|
||||||
@@ -33,20 +31,19 @@ void EmporiaVueUtility::loop() {
|
|||||||
msg_len = read_msg();
|
msg_len = read_msg();
|
||||||
now = ::time(&now);
|
now = ::time(&now);
|
||||||
|
|
||||||
// /* sanity checks! */
|
/* sanity checks! */
|
||||||
// if (next_meter_request >
|
if (next_meter_request >
|
||||||
// now + (INITIAL_STARTUP_DELAY + METER_REJOIN_INTERVAL)) {
|
now + (INITIAL_STARTUP_DELAY + METER_REJOIN_INTERVAL)) {
|
||||||
// ESP_LOGD(TAG,
|
ESP_LOGD(TAG,
|
||||||
// "Time jumped back (%lld > %lld + %lld); resetting",
|
"Time jumped back (%lld > %lld + %lld); resetting",
|
||||||
// (long long) next_meter_request,
|
(long long) next_meter_request,
|
||||||
// (long long) now,
|
(long long) now,
|
||||||
// (long long) (INITIAL_STARTUP_DELAY +
|
(long long) (INITIAL_STARTUP_DELAY +
|
||||||
// METER_REJOIN_INTERVAL));
|
METER_REJOIN_INTERVAL));
|
||||||
// next_meter_request = next_meter_join = 0;
|
next_meter_request = next_meter_join = 0;
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (msg_len != 0) {
|
if (msg_len != 0) {
|
||||||
|
|
||||||
msg_type = input_buffer.data[2];
|
msg_type = input_buffer.data[2];
|
||||||
|
|
||||||
switch (msg_type) {
|
switch (msg_type) {
|
||||||
@@ -117,10 +114,11 @@ void EmporiaVueUtility::loop() {
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mgm_firmware_ver < 1) {
|
if (mgm_firmware_ver < 1 && now >= next_version_request) {
|
||||||
// Something's wrong, do the startup sequence again.
|
// Something's wrong, do the startup sequence again.
|
||||||
startup_step = 0;
|
startup_step = 0;
|
||||||
send_version_req();
|
send_version_req();
|
||||||
|
next_version_request = now + 1; // Wait a second.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now >= next_meter_request) {
|
if (now >= next_meter_request) {
|
||||||
@@ -150,7 +148,7 @@ void EmporiaVueUtility::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmporiaVueUtility::dump_config() {
|
void EmporiaVueUtility::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "Stubbed Emporia Vue Utility");
|
ESP_LOGCONFIG(TAG, "Emporia Vue Utility config dump WIP");
|
||||||
}
|
}
|
||||||
} // namespace emporia_vue_utility
|
} // namespace emporia_vue_utility
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
@@ -42,7 +42,7 @@ static const char *TAG = "emporia_vue_utility";
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace emporia_vue_utility {
|
namespace emporia_vue_utility {
|
||||||
|
|
||||||
class EmporiaVueUtility : public sensor::Sensor, public PollingComponent, public uart::UARTDevice {
|
class EmporiaVueUtility : public PollingComponent, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Format known from MGM Firmware version 2.
|
* Format known from MGM Firmware version 2.
|
||||||
@@ -128,7 +128,7 @@ class EmporiaVueUtility : public sensor::Sensor, public PollingComponent, public
|
|||||||
// The most recent cost unit
|
// The most recent cost unit
|
||||||
uint16_t cost_unit = 0;
|
uint16_t cost_unit = 0;
|
||||||
|
|
||||||
void set_update_interval(uint32_t update_interval);
|
void set_update_interval(uint32_t update_interval) { update_interval_ = update_interval / 1000; }
|
||||||
void set_power_sensor(sensor::Sensor *sensor) { power_sensor_ = sensor; }
|
void set_power_sensor(sensor::Sensor *sensor) { power_sensor_ = sensor; }
|
||||||
void set_power_export_sensor(sensor::Sensor *sensor) { power_export_sensor_ = sensor; }
|
void set_power_export_sensor(sensor::Sensor *sensor) { power_export_sensor_ = sensor; }
|
||||||
void set_power_import_sensor(sensor::Sensor *sensor) { power_import_sensor_ = sensor; }
|
void set_power_import_sensor(sensor::Sensor *sensor) { power_import_sensor_ = sensor; }
|
||||||
|
|||||||
Reference in New Issue
Block a user