mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
parent
f52136338d
commit
dda27d9de4
@ -64,47 +64,47 @@ uint16_t shelly_dimmer_checksum(const uint8_t *buf, int len) {
|
|||||||
return std::accumulate<decltype(buf), uint16_t>(buf, buf + len, 0);
|
return std::accumulate<decltype(buf), uint16_t>(buf, buf + len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellyDimmer::setup() {
|
bool ShellyDimmer::is_running_configured_version() const {
|
||||||
this->pin_nrst_->setup();
|
return this->version_major_ == USE_SHD_FIRMWARE_MAJOR_VERSION &&
|
||||||
this->pin_boot0_->setup();
|
this->version_minor_ == USE_SHD_FIRMWARE_MINOR_VERSION;
|
||||||
|
}
|
||||||
ESP_LOGI(TAG, "Initializing Shelly Dimmer...");
|
|
||||||
|
|
||||||
|
void ShellyDimmer::handle_firmware() {
|
||||||
// Reset the STM32 and check the firmware version.
|
// Reset the STM32 and check the firmware version.
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
this->reset_normal_boot_();
|
this->reset_normal_boot_();
|
||||||
this->send_command_(SHELLY_DIMMER_PROTO_CMD_VERSION, nullptr, 0);
|
this->send_command_(SHELLY_DIMMER_PROTO_CMD_VERSION, nullptr, 0);
|
||||||
ESP_LOGI(TAG, "STM32 current firmware version: %d.%d, desired version: %d.%d", this->version_major_,
|
ESP_LOGI(TAG, "STM32 current firmware version: %d.%d, desired version: %d.%d", this->version_major_,
|
||||||
this->version_minor_, USE_SHD_FIRMWARE_MAJOR_VERSION, USE_SHD_FIRMWARE_MINOR_VERSION);
|
this->version_minor_, USE_SHD_FIRMWARE_MAJOR_VERSION, USE_SHD_FIRMWARE_MINOR_VERSION);
|
||||||
if (this->version_major_ != USE_SHD_FIRMWARE_MAJOR_VERSION ||
|
|
||||||
this->version_minor_ != USE_SHD_FIRMWARE_MINOR_VERSION) {
|
|
||||||
#ifdef USE_SHD_FIRMWARE_DATA
|
|
||||||
// Update firmware if needed.
|
|
||||||
ESP_LOGW(TAG, "Unsupported STM32 firmware version, flashing");
|
|
||||||
if (i > 0) {
|
|
||||||
// Upgrade was already performed but the reported version is still not right.
|
|
||||||
ESP_LOGE(TAG, "STM32 firmware upgrade already performed, but version is still incorrect");
|
|
||||||
this->mark_failed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!is_running_configured_version()) {
|
||||||
|
#ifdef USE_SHD_FIRMWARE_DATA
|
||||||
if (!this->upgrade_firmware_()) {
|
if (!this->upgrade_firmware_()) {
|
||||||
ESP_LOGW(TAG, "Failed to upgrade firmware");
|
ESP_LOGW(TAG, "Failed to upgrade firmware");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Firmware upgrade completed, do the checks again.
|
this->reset_normal_boot_();
|
||||||
continue;
|
this->send_command_(SHELLY_DIMMER_PROTO_CMD_VERSION, nullptr, 0);
|
||||||
#else
|
if (!is_running_configured_version()) {
|
||||||
ESP_LOGW(TAG, "Firmware version mismatch, put 'update: true' in the yaml to flash an update.");
|
ESP_LOGE(TAG, "STM32 firmware upgrade already performed, but version is still incorrect");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ESP_LOGW(TAG, "Firmware version mismatch, put 'update: true' in the yaml to flash an update.");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShellyDimmer::setup() {
|
||||||
|
this->pin_nrst_->setup();
|
||||||
|
this->pin_boot0_->setup();
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Initializing Shelly Dimmer...");
|
||||||
|
|
||||||
|
this->handle_firmware();
|
||||||
|
|
||||||
this->send_settings_();
|
this->send_settings_();
|
||||||
// Do an immediate poll to refresh current state.
|
// Do an immediate poll to refresh current state.
|
||||||
this->send_command_(SHELLY_DIMMER_PROTO_CMD_POLL, nullptr, 0);
|
this->send_command_(SHELLY_DIMMER_PROTO_CMD_POLL, nullptr, 0);
|
||||||
|
@ -20,6 +20,8 @@ class ShellyDimmer : public PollingComponent, public light::LightOutput, public
|
|||||||
public:
|
public:
|
||||||
float get_setup_priority() const override { return setup_priority::LATE; }
|
float get_setup_priority() const override { return setup_priority::LATE; }
|
||||||
|
|
||||||
|
bool is_running_configured_version() const;
|
||||||
|
void handle_firmware();
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user