This commit is contained in:
iranl
2024-02-09 20:38:54 +01:00
parent cc252f6e8b
commit db5e66196c
6 changed files with 35 additions and 10 deletions

View File

@@ -10,6 +10,7 @@
#define mqtt_topic_battery_keypad_critical "/battery/keypadCritical"
#define mqtt_topic_lock_state "/lock/state"
#define mqtt_topic_lock_ha_state "/lock/hastate"
#define mqtt_topic_query_config "/lock/query/config"
#define mqtt_topic_query_lockstate "/lock/query/lockstate"
#define mqtt_topic_query_keypad "/lock/query/keypad"

View File

@@ -740,7 +740,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
json["pl_lock"] = lockAction;
json["pl_unlk"] = unlockAction;
json["pl_open"] = openAction;
json["stat_t"] = String("~") + mqtt_topic_lock_state;
json["stat_t"] = String("~") + mqtt_topic_lock_ha_state;
json["stat_jammed"] = "jammed";
json["stat_locked"] = "locked";
json["stat_locking"] = "locking";

View File

@@ -218,7 +218,7 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne
if(_haEnabled)
{
publishBinaryState(keyTurnerState.lockState);
publishState(keyTurnerState.lockState);
}
}
@@ -276,21 +276,35 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne
_firstTunerStatePublish = false;
}
void NetworkLock::publishBinaryState(NukiLock::LockState lockState)
void NetworkLock::publishState(NukiLock::LockState lockState)
{
switch(lockState)
{
case NukiLock::LockState::Locked:
case NukiLock::LockState::Locking:
publishString(mqtt_topic_lock_ha_state, "locked");
publishString(mqtt_topic_lock_binary_state, "locked");
break;
case NukiLock::LockState::Locking:
publishString(mqtt_topic_lock_ha_state, "locking");
publishString(mqtt_topic_lock_binary_state, "locked");
break;
case NukiLock::LockState::Unlocked:
case NukiLock::LockState::Unlocking:
publishString(mqtt_topic_lock_ha_state, "unlocking");
publishString(mqtt_topic_lock_binary_state, "unlocked");
break;
case NukiLock::LockState::Unlocked:
case NukiLock::LockState::Unlatched:
case NukiLock::LockState::Unlatching:
case NukiLock::LockState::UnlockedLnga:
publishString(mqtt_topic_lock_ha_state, "unlocked");
publishString(mqtt_topic_lock_binary_state, "unlocked");
break;
case NukiLock::LockState::Uncalibrated:
case NukiLock::LockState::Calibration:
case NukiLock::LockState::BootRun:
case NukiLock::LockState::MotorBlocked:
publishString(mqtt_topic_lock_ha_state, "jammed");
break;
default:
break;
}

View File

@@ -23,7 +23,7 @@ public:
void initialize();
void publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurnerState, const NukiLock::KeyTurnerState& lastKeyTurnerState);
void publishBinaryState(NukiLock::LockState lockState);
void publishState(NukiLock::LockState lockState);
void publishAuthorizationInfo(const std::list<NukiLock::LogEntry>& logEntries);
void clearAuthorizationInfo();
void publishCommandResult(const char* resultStr);

View File

@@ -219,7 +219,7 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
if(_haEnabled)
{
publishBinaryState(keyTurnerState);
publishState(keyTurnerState);
}
}
@@ -260,10 +260,11 @@ void NetworkOpener::publishRing()
_resetLockStateTs = millis() + 2000;
}
void NetworkOpener::publishBinaryState(NukiOpener::OpenerState lockState)
void NetworkOpener::publishState(NukiOpener::OpenerState lockState)
{
if(lockState.nukiState == NukiOpener::State::ContinuousMode)
{
publishString(mqtt_topic_lock_ha_state, "unlocked");
publishString(mqtt_topic_lock_binary_state, "unlocked");
}
else
@@ -271,12 +272,21 @@ void NetworkOpener::publishBinaryState(NukiOpener::OpenerState lockState)
switch (lockState.lockState)
{
case NukiOpener::LockState::Locked:
publishString(mqtt_topic_lock_ha_state, "locked");
publishString(mqtt_topic_lock_binary_state, "locked");
break;
case NukiOpener::LockState::RTOactive:
case NukiOpener::LockState::Open:
case NukiOpener::LockState::Opening:
publishString(mqtt_topic_lock_ha_state, "unlocked");
publishString(mqtt_topic_lock_binary_state, "unlocked");
break;
case NukiOpener::LockState::Opening:
publishString(mqtt_topic_lock_ha_state, "unlocking");
publishString(mqtt_topic_lock_binary_state, "unlocked");
break;
case NukiOpener::LockState::Undefined:
case NukiOpener::LockState::Uncalibrated:
publishString(mqtt_topic_lock_ha_state, "jammed");
break;
default:
break;

View File

@@ -20,7 +20,7 @@ public:
void publishKeyTurnerState(const NukiOpener::OpenerState& keyTurnerState, const NukiOpener::OpenerState& lastKeyTurnerState);
void publishRing();
void publishBinaryState(NukiOpener::OpenerState lockState);
void publishState(NukiOpener::OpenerState lockState);
void publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries);
void clearAuthorizationInfo();
void publishCommandResult(const char* resultStr);