diff options
| author | diogo464 <[email protected]> | 2026-01-09 11:28:49 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2026-01-09 11:30:08 +0000 |
| commit | 27779ecf0d7c00ae0acb650c0d75d28edcc3aa89 (patch) | |
| tree | c9312c4baf2f0f1a9e19b80feb0a7637c31ad5e2 /src/constants.rs | |
| parent | 0a1659dbd57180a7c1337d2ec4138f8c29427ce3 (diff) | |
add mqtt helper functions and refactor buffer management
Created helper functions to eliminate code duplication in MQTT operations:
- device_mqtt_subscribe: handles subscription with timeout and error logging
- device_mqtt_publish: handles publishing with optional retain flag
- mqtt_receive_data: handles data receiving with buffer validation and timeout
- publish_entity_discoveries: publishes all entity discoveries
- generate_entity_discovery: generates entity discovery payloads
Refactored buffer management by introducing DeviceBuffersOwned and
DeviceBuffers structures to group related buffers together, making them
easier to pass to helper functions.
Added MQTT_TIMEOUT constant at module level for consistent timeout handling.
Fixed bug where only the last entity's discovery was republished when Home
Assistant came back online. Now correctly republishes all entities by
subscribing to homeassistant/status and using publish_entity_discoveries
when the "online" status is received.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Diffstat (limited to 'src/constants.rs')
| -rw-r--r-- | src/constants.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/constants.rs b/src/constants.rs index 73266f7..c9935b1 100644 --- a/src/constants.rs +++ b/src/constants.rs | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | #![allow(unused)] | 1 | #![allow(unused)] |
| 2 | 2 | ||
| 3 | pub const HA_STATUS_TOPIC: &str = "homeassistant/status"; | ||
| 4 | pub const HA_STATUS_PAYLOAD_ONLINE: &str = "online"; | ||
| 5 | pub const HA_STATUS_PAYLOAD_OFFLINE: &str = "offline"; | ||
| 6 | |||
| 3 | pub const HA_DOMAIN_SENSOR: &str = "sensor"; | 7 | pub const HA_DOMAIN_SENSOR: &str = "sensor"; |
| 4 | pub const HA_DOMAIN_BINARY_SENSOR: &str = "binary_sensor"; | 8 | pub const HA_DOMAIN_BINARY_SENSOR: &str = "binary_sensor"; |
| 5 | pub const HA_DOMAIN_SWITCH: &str = "switch"; | 9 | pub const HA_DOMAIN_SWITCH: &str = "switch"; |
