Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_device_name_text_sensor.cpp
Go to the documentation of this file.
1/// @file platform_device_name_text_sensor.cpp
2/// @brief Diagnostic text sensor exposing the stored IO-Homecontrol device name.
3/// @ingroup hioc_platforms
4
6
7#include "hub_internal.h"
8#include "esphome/core/log.h"
9
10namespace esphome {
11namespace home_io_control {
12
13static const char *const TAG = "home_io_control.device_name";
14
16 if (this->parent_ == nullptr)
17 return;
18
19 this->parent_->register_device_callback(
20 [this](const std::string &id, const IoDevice &dev) { this->on_device_update_(id, dev); });
21
22 if (const auto *dev = this->parent_->get_device(this->device_id_); dev != nullptr)
23 this->publish_state(dev->name);
24
25 this->set_timeout("init_name", detail::INITIAL_STATUS_REQUEST_DELAY_MS,
26 [this]() { this->parent_->queue_request_device_name(this->device_id_); });
27}
28
30 LOG_TEXT_SENSOR("", "IO-Homecontrol Device Name", this);
31 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
32}
33
34void IOHomeDeviceNameTextSensor::on_device_update_(const std::string &id, const IoDevice &dev) {
35 if (id != this->device_id_)
36 return;
37
38 this->publish_state(dev.name);
39}
40
41} // namespace home_io_control
42} // namespace esphome
void setup() override
Register callbacks and schedule an initial name fetch.
void on_device_update_(const std::string &id, const IoDevice &dev)
Publish the current cached device name after a hub update.
void dump_config() override
Dump text-sensor configuration to the log.
Internal helpers shared by the hub implementation .cpp files.
constexpr uint32_t INITIAL_STATUS_REQUEST_DELAY_MS
Delay before the first post-boot status request from an entity.
static const char *const TAG
Definition hub_core.cpp:35
Diagnostic text sensor exposing the stored IO-Homecontrol device name.
Runtime state of a paired IO‑Homecontrol device.
char name[DEVICE_NAME_BUFFER_SIZE]
Cached UTF-8 device name decoded from Latin-1 wire payloads.