Skip to content

Commit

Permalink
process lock/unlock requests without state validation (useful for hom…
Browse files Browse the repository at this point in the history
…ekit automations)
  • Loading branch information
rednblkx committed Nov 17, 2024
1 parent df3bc49 commit f7cb016
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions data/routes/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ <h3 style="margin: 0;width: fit-content;padding: 0.5rem;cursor: pointer;" onclic
<option value="1">Enabled</option>
</select>
</div>
<div style="display: flex;gap: 8px;">
<label for="homekit-dumb-switch-mode">Dumb Switch Mode</label>
<select name="homekit-dumb-switch-mode" id="homekit-dumb-switch-mode">
<option value="0">Disabled</option>
<option value="1">Enabled</option>
</select>
</div>
<div style="display: flex;gap: 8px;">
<label for="prox-bat-enable">SmartLock battery reporting</label>
<select name="prox-bat-enable" id="prox-bat-enable">
Expand Down Expand Up @@ -180,6 +187,7 @@ <h3 class="webui-tabs-selected-tab" style="margin: 0;width: fit-content;padding:
document.getElementById("hk-always-lock").selectedIndex = "%ALWAYSLOCK%";
document.getElementById("web-auth-enable").selectedIndex = "%WEBENABLE%";
document.getElementById("prox-bat-enable").selectedIndex = "%PROXBATENABLE%";
document.getElementById("homekit-dumb-switch-mode").selectedIndex = "%DUMBSWITCHMODE%";
let form = document.getElementById("misc-config");
async function handleForm(event) {
event.preventDefault();
Expand Down
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ namespace espConfig
std::array<uint8_t, 4> nfcGpioPins{SS, SCK, MISO, MOSI};
uint8_t btrLowStatusThreshold = 10;
bool proxBatEnabled = false;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(misc_config_t, deviceName, otaPasswd, hk_key_color, setupCode, lockAlwaysUnlock, lockAlwaysLock, controlPin, hsStatusPin, nfcSuccessPin, nfcSuccessTime, nfcNeopixelPin, neopixelSuccessColor, neopixelFailureColor, neopixelSuccessTime, neopixelFailTime, nfcSuccessHL, nfcFailPin, nfcFailTime, nfcFailHL, gpioActionPin, gpioActionLockState, gpioActionUnlockState, gpioActionMomentaryEnabled, gpioActionMomentaryTimeout, webAuthEnabled, webUsername, webPassword, nfcGpioPins, btrLowStatusThreshold, proxBatEnabled)
bool hkDumbSwitchMode = false;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(misc_config_t, deviceName, otaPasswd, hk_key_color, setupCode, lockAlwaysUnlock, lockAlwaysLock, controlPin, hsStatusPin, nfcSuccessPin, nfcSuccessTime, nfcNeopixelPin, neopixelSuccessColor, neopixelFailureColor, neopixelSuccessTime, neopixelFailTime, nfcSuccessHL, nfcFailPin, nfcFailTime, nfcFailHL, gpioActionPin, gpioActionLockState, gpioActionUnlockState, gpioActionMomentaryEnabled, gpioActionMomentaryTimeout, webAuthEnabled, webUsername, webPassword, nfcGpioPins, btrLowStatusThreshold, proxBatEnabled, hkDumbSwitchMode)
} miscConfig;
};

Expand Down Expand Up @@ -366,6 +367,8 @@ struct LockMechanism : Service::LockMechanism
if (espConfig::miscConfig.gpioActionPin != 255) {
const gpioLockAction gpioAction{ .source = gpioLockAction::HOMEKIT, .action = 0 };
xQueueSend(gpio_lock_handle, &gpioAction, 0);
} else if (espConfig::miscConfig.hkDumbSwitchMode) {
lockCurrentState->setVal(targetState);
}
int currentState = lockCurrentState->getNewVal();
if (client != nullptr) {
Expand Down Expand Up @@ -829,6 +832,8 @@ String miscHtmlProcess(const String& var) {
return String(espConfig::miscConfig.btrLowStatusThreshold);
} else if (var == "PROXBATENABLE") {
return String(espConfig::miscConfig.proxBatEnabled);
} else if (var == "DUMBSWITCHMODE") {
return String(espConfig::miscConfig.hkDumbSwitchMode);
}
return String();
}
Expand Down Expand Up @@ -1164,6 +1169,8 @@ void setupWeb() {
statusLowBtr->setVal(0);
}
}
} else if (!strcmp(p->name().c_str(), "homekit-dumb-switch-mode")) {
espConfig::miscConfig.hkDumbSwitchMode = p->value().toInt();
}
}
json json_misc_config = espConfig::miscConfig;
Expand Down

0 comments on commit f7cb016

Please sign in to comment.