Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_last_contact_sensor.h
Go to the documentation of this file.
1#pragma once
2
3/// @file platform_last_contact_sensor.h
4/// @brief Diagnostic sensor exposing seconds elapsed since a device's last received frame.
5/// @ingroup hioc_platforms
6
7#include "esphome/components/sensor/sensor.h"
8#include "esphome/core/component.h"
10
11namespace esphome {
12namespace home_io_control {
13
14/// @brief Diagnostic sensor that publishes seconds elapsed since the last frame received from a
15/// device (see detail::update_link_health() in hub_internal.h).
16///
17/// This is an age, not a timestamp: it resets to ~0 on every frame from the device — including
18/// replies to the hub's own status polls and commands, not just traffic the device sends
19/// unprompted — and counts up from there. A periodic heartbeat (see HEARTBEAT_INTERVAL_MS in the
20/// .cpp) re-publishes it even when the device stays quiet, so the value keeps advancing in Home
21/// Assistant instead of freezing at whatever it was at the last frame. Publishes nothing until
22/// the first frame is seen.
23/// @ingroup hioc_platforms
24class IOHomeLastContactSensor : public sensor::Sensor, public Component, public DeviceBoundCompanion {
25 public:
26 /// @brief Register the device-update subscription, start the heartbeat, and publish the
27 /// initial cached state.
28 void setup() override;
29
30 /// @brief Dump sensor configuration to the log.
31 void dump_config() override;
32
33 /// @brief Get setup priority so the parent hub is available first.
34 /// @return setup_priority::DATA.
35 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
36
37 protected:
38 /// @brief Compute and publish seconds since `dev.last_seen_ms`; no-op before the first frame.
39 /// @param dev Device to read `last_seen_ms` from.
40 void publish_age_(const IoDevice &dev);
41};
42
43} // namespace home_io_control
44} // namespace esphome
Mixin holding the hub/device binding shared by the auto-generated per-device companion diagnostic sen...
Diagnostic sensor that publishes seconds elapsed since the last frame received from a device (see det...
void dump_config() override
Dump sensor configuration to the log.
void publish_age_(const IoDevice &dev)
Compute and publish seconds since dev.last_seen_ms; no-op before the first frame.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
void setup() override
Register the device-update subscription, start the heartbeat, and publish the initial cached state.
Shared device-binding mixins for IO-Homecontrol entity platforms.
Runtime state of a paired IO‑Homecontrol device.