Per-entity availability, deferred discovery publish, suggested precision

- Add HAAvailabilityConfig for per-entity availability_topic and payloads
- Defer discovery until MQTT connected; publish availability after discovery
- HASensor/HANumber: optional suggested_display_precision in discovery
- HASerializer/HADictionary: extend for new keys; update device types and mocks
- Docs and examples reflect availability and precision usage
- Tests updated for discovery and availability behavior
- Ignore .cursor/ in repo root
This commit is contained in:
2026-05-05 17:47:55 +10:00
parent 8ba5482892
commit b9f4fd7f4b
62 changed files with 2705 additions and 283 deletions
@@ -42,9 +42,9 @@ void onCommandReceived(bool state, HASwitch* caller)
lastCommandCallbackCall.caller = caller;
}
void onCommandPublishAttempt(bool state, HASwitch* caller)
void onCommandDeferredPublish(bool state, HASwitch* caller)
{
TEST_ASSERT_FALSE(caller->setState(state));
TEST_ASSERT_TRUE(caller->setState(state));
}
void test_SwitchTest_invalid_unique_id(void) {
@@ -393,17 +393,19 @@ void test_SwitchTest_command_off(void) {
assertCommandCallbackCalled(false, &testSwitch)
}
void test_SwitchTest_callback_publish_attempt_is_rejected(void) {
void test_SwitchTest_callback_publish_is_deferred_until_after_dispatch(void) {
prepareTest
mock->connectDummy();
mqtt.resetDeferredPublishTestCounters();
HASwitch testSwitch(testUniqueId);
testSwitch.onCommand(onCommandPublishAttempt);
testSwitch.onCommand(onCommandDeferredPublish);
mock->fakeMessage(AHATOFSTR(CommandTopic), F("ON"));
TEST_ASSERT_EQUAL(1, mock->getPublishCallsFromCallbackNb());
TEST_ASSERT_EQUAL(0, mock->getFlushedMessagesNb());
TEST_ASSERT_EQUAL_UINT16(1, mqtt.getDeferredPublishEnqueueCountForTest());
TEST_ASSERT_EQUAL_UINT8(1, mock->getFlushedMessagesNb());
AHA_ASSERT_MQTT_MESSAGE(mock, 0, AHATOFSTR(StateTopic), "ON", true);
}
void test_SwitchTest_different_switch_command(void) {