feat(monitoring): add edge-triggered threshold handling with group action orchestration and HA-aware Proxmox shutdowns
This commit is contained in:
+43
-9
@@ -120,19 +120,53 @@ export function hasThresholdViolation(
|
||||
batteryRuntime: number,
|
||||
actions: IActionConfig[] | undefined,
|
||||
): boolean {
|
||||
if (powerStatus !== 'onBattery' || !actions || actions.length === 0) {
|
||||
return getActionThresholdStates(powerStatus, batteryCapacity, batteryRuntime, actions).some(
|
||||
Boolean,
|
||||
);
|
||||
}
|
||||
|
||||
export function isActionThresholdExceeded(
|
||||
actionConfig: IActionConfig,
|
||||
powerStatus: IProtocolUpsStatus['powerStatus'],
|
||||
batteryCapacity: number,
|
||||
batteryRuntime: number,
|
||||
): boolean {
|
||||
if (powerStatus !== 'onBattery' || !actionConfig.thresholds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const actionConfig of actions) {
|
||||
if (
|
||||
actionConfig.thresholds &&
|
||||
(batteryCapacity < actionConfig.thresholds.battery ||
|
||||
batteryRuntime < actionConfig.thresholds.runtime)
|
||||
) {
|
||||
return true;
|
||||
return (
|
||||
batteryCapacity < actionConfig.thresholds.battery ||
|
||||
batteryRuntime < actionConfig.thresholds.runtime
|
||||
);
|
||||
}
|
||||
|
||||
export function getActionThresholdStates(
|
||||
powerStatus: IProtocolUpsStatus['powerStatus'],
|
||||
batteryCapacity: number,
|
||||
batteryRuntime: number,
|
||||
actions: IActionConfig[] | undefined,
|
||||
): boolean[] {
|
||||
if (!actions || actions.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return actions.map((actionConfig) =>
|
||||
isActionThresholdExceeded(actionConfig, powerStatus, batteryCapacity, batteryRuntime)
|
||||
);
|
||||
}
|
||||
|
||||
export function getEnteredThresholdIndexes(
|
||||
previousStates: boolean[] | undefined,
|
||||
currentStates: boolean[],
|
||||
): number[] {
|
||||
const enteredIndexes: number[] = [];
|
||||
|
||||
for (let index = 0; index < currentStates.length; index++) {
|
||||
if (currentStates[index] && !previousStates?.[index]) {
|
||||
enteredIndexes.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return enteredIndexes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user