Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/embedded-fan-control.
Something went wrong. Try again.
6.4 kB · 131 lines
Rust
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132#![no_std]
pub mod fan_controller { use const_format::formatcp;
pub const OBJECT_ID: &str = "fan-controller"; /// Prefix is "homeassistant", but it can be changed in home assistant configuration const DISCOVERY_PREFIX: &str = "homeassistant"; /// One of the supported MQTT integrations, e.g., binary_sensor, or device in case of a device discovery. /// Must be set to "device" when a device exposes multiple components in one payload const COMPONENT: &str = "device";
pub const DISCOVERY: &str = formatcp!("{DISCOVERY_PREFIX}/{COMPONENT}/{OBJECT_ID}/config");
/// Why the controller last reset, published retained on boot. Retained because the resets /// worth diagnosing are rare and nobody is subscribed when they happen — the answer has to /// still be there whenever someone next looks. pub const RESET_CAUSE: &str = formatcp!("{OBJECT_ID}/reset-cause");
/// The topic to publish the on/off state of the fan controller. pub const STATE: &str = formatcp!("{OBJECT_ID}/on/state"); /// The topic to subscribe to for setting the on/off state of the fan controller. /// This topic is used by Home Assistant to notify the fan controller to turn on or off. pub const COMMAND: &str = formatcp!("{OBJECT_ID}/on/set");
/// The bypass damper, opened and closed by a relay rather than by either fan. It belongs to /// the controller rather than to a fan, so its topics sit next to the controller wide ones /// instead of under [`fan_1`] or [`fan_2`] pub mod bypass { use super::OBJECT_ID; use const_format::formatcp;
pub const UNIQUE_ID: &str = formatcp!("{OBJECT_ID}/bypass");
/// The topic to publish whether the bypass is open, after the relay acknowledged the /// write. Only what the relay confirmed is published here, the same way a fan's speed is pub const STATE: &str = formatcp!("{UNIQUE_ID}/on/state"); /// The topic to subscribe to for opening and closing the bypass. /// This topic is used by Home Assistant to notify the fan controller to drive the relay pub const COMMAND: &str = formatcp!("{UNIQUE_ID}/on/set"); }
pub mod fan_1 { use super::OBJECT_ID; use const_format::formatcp;
pub const UNIQUE_ID: &str = formatcp!("{OBJECT_ID}/fan-1"); /// The on and off state command and state topics for fan 1. pub mod state { use super::UNIQUE_ID; use const_format::formatcp;
/// The topic to publish the on/off state of the fan 1 on the fan controller. pub const STATE: &str = formatcp!("{UNIQUE_ID}/on/state"); /// The topic to subscribe to for setting the on/off state of the fan 1 on the fan controller. /// This topic is used by Home Assistant to notify the fan controller to turn on or off the fan. pub const COMMAND: &str = formatcp!("{UNIQUE_ID}/on/set"); }
pub mod percentage { use super::UNIQUE_ID; use const_format::formatcp;
pub const STATE: &str = formatcp!("{UNIQUE_ID}/speed/percentage_state"); pub const COMMAND: &str = formatcp!("{UNIQUE_ID}/speed/percentage"); }
/// All four sensor values a fan reports arrive as one JSON object on this topic, so a poll /// costs a single publish and Home Assistant picks each value out with a value template pub mod sensor { use super::UNIQUE_ID; use const_format::formatcp;
pub const STATE: &str = formatcp!("{UNIQUE_ID}/sensors/state");
/// The identifiers Home Assistant tells the four sensors apart by. They are not /// topics, but they are composed from the same fan identifier and have to stay unique /// alongside it, so they belong next to it rather than in the build script pub const SPEED: &str = formatcp!("{UNIQUE_ID}/sensors/speed"); pub const MOTOR_TEMPERATURE: &str = formatcp!("{UNIQUE_ID}/sensors/motor-temperature"); pub const ELECTRONICS_TEMPERATURE: &str = formatcp!("{UNIQUE_ID}/sensors/electronics-temperature"); pub const POWER: &str = formatcp!("{UNIQUE_ID}/sensors/power"); } }
pub mod fan_2 { use super::OBJECT_ID; use const_format::formatcp;
pub const UNIQUE_ID: &str = formatcp!("{OBJECT_ID}/fan-2");
/// The on and off state command and state topics for fan 2. pub mod state { use super::UNIQUE_ID; use const_format::formatcp;
/// The topic to publish the on/off state of the fan 2 on the fan controller. pub const STATE: &str = formatcp!("{UNIQUE_ID}/on/state"); /// The topic to subscribe to for setting the on/off state of the fan 2 on the fan controller. /// This topic is used by Home Assistant to notify the fan controller to turn on or off the fan. pub const COMMAND: &str = formatcp!("{UNIQUE_ID}/on/set"); }
pub mod percentage { use super::UNIQUE_ID; use const_format::formatcp;
pub const STATE: &str = formatcp!("{UNIQUE_ID}/speed/percentage_state"); pub const COMMAND: &str = formatcp!("{UNIQUE_ID}/speed/percentage"); }
/// All four sensor values a fan reports arrive as one JSON object on this topic, so a poll /// costs a single publish and Home Assistant picks each value out with a value template pub mod sensor { use super::UNIQUE_ID; use const_format::formatcp;
pub const STATE: &str = formatcp!("{UNIQUE_ID}/sensors/state");
/// The identifiers Home Assistant tells the four sensors apart by. They are not /// topics, but they are composed from the same fan identifier and have to stay unique /// alongside it, so they belong next to it rather than in the build script pub const SPEED: &str = formatcp!("{UNIQUE_ID}/sensors/speed"); pub const MOTOR_TEMPERATURE: &str = formatcp!("{UNIQUE_ID}/sensors/motor-temperature"); pub const ELECTRONICS_TEMPERATURE: &str = formatcp!("{UNIQUE_ID}/sensors/electronics-temperature"); pub const POWER: &str = formatcp!("{UNIQUE_ID}/sensors/power"); } }}