From 7dbc20b776c56c6cce910e25fe6f12871e9d9b47 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:59:52 +1200 Subject: [PATCH] [update] Set entity_category to config & Publish state to logs (#6954) --- esphome/components/update/__init__.py | 5 ++++ esphome/components/update/update_entity.cpp | 26 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/esphome/components/update/__init__.py b/esphome/components/update/__init__.py index ea1cf778b6..20a9373a06 100644 --- a/esphome/components/update/__init__.py +++ b/esphome/components/update/__init__.py @@ -4,11 +4,13 @@ import esphome.config_validation as cv import esphome.codegen as cg from esphome.const import ( CONF_DEVICE_CLASS, + CONF_ENTITY_CATEGORY, CONF_ID, CONF_MQTT_ID, CONF_WEB_SERVER_ID, DEVICE_CLASS_EMPTY, DEVICE_CLASS_FIRMWARE, + ENTITY_CATEGORY_CONFIG, ) from esphome.core import CORE, coroutine_with_priority from esphome.cpp_helpers import setup_entity @@ -41,6 +43,9 @@ UPDATE_SCHEMA = ( cv.Optional(CONF_ON_UPDATE_AVAILABLE): automation.validate_automation( single=True ), + cv.Optional( + CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_CONFIG + ): cv.entity_category, } ) ) diff --git a/esphome/components/update/update_entity.cpp b/esphome/components/update/update_entity.cpp index 501cb6635f..ed9a0480d8 100644 --- a/esphome/components/update/update_entity.cpp +++ b/esphome/components/update/update_entity.cpp @@ -1,9 +1,35 @@ #include "update_entity.h" +#include "esphome/core/log.h" + namespace esphome { namespace update { +static const char *const TAG = "update"; + void UpdateEntity::publish_state() { + ESP_LOGD(TAG, "'%s' - Publishing:", this->name_.c_str()); + ESP_LOGD(TAG, " Current Version: %s", this->update_info_.current_version.c_str()); + + if (!this->update_info_.md5.empty()) { + ESP_LOGD(TAG, " Latest Version: %s", this->update_info_.latest_version.c_str()); + } + if (!this->update_info_.firmware_url.empty()) { + ESP_LOGD(TAG, " Firmware URL: %s", this->update_info_.firmware_url.c_str()); + } + + ESP_LOGD(TAG, " Title: %s", this->update_info_.title.c_str()); + if (!this->update_info_.summary.empty()) { + ESP_LOGD(TAG, " Summary: %s", this->update_info_.summary.c_str()); + } + if (!this->update_info_.release_url.empty()) { + ESP_LOGD(TAG, " Release URL: %s", this->update_info_.release_url.c_str()); + } + + if (this->update_info_.has_progress) { + ESP_LOGD(TAG, " Progress: %.0f%%", this->update_info_.progress); + } + this->has_state_ = true; this->state_callback_.call(); }