Skip to content

Commit

Permalink
Merge pull request #42 from OdysseusLarp/big-battery-emergency-positions
Browse files Browse the repository at this point in the history
feat: allow emergency overrides for big battery locations
  • Loading branch information
plaa authored Jun 12, 2024
2 parents 8970fd2 + ce93d46 commit 03dade0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
17 changes: 16 additions & 1 deletion db/redux/box/bigbattery.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@ blobs.push({
// Whether box is currently actively used (set by backend), affects tube glowing
active: false,
// Brightness of Neopixel LEDs 1-255 (configuration)
brightness: 20,
brightness: 10,
// In what time is the battery depleted from 100% to 0%, minutes (configuration)
depletion_time_mins: 3 * 60 + 15,
// Set to integer values of locations where device is always assumed to be connected + charged.
// For disaster situations where the real device no longer works.
emergency_assumed_at_positions: [],

presets: {
set_full_capacity: {
capacity_percent: 100,
},
assume_battery_everywhere: {
emergency_assumed_at_positions: [1, 2, 3, 4, 5, 6, 7, 8, 9],
},
assume_battery_nowhere: {
emergency_assumed_at_positions: [],
},
},
});

export default blobs;
1 change: 1 addition & 0 deletions src/rules/boxes/bigbattery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function updateActiveStatus() {
return;
}

// NOTE: This intentionally does not use isBatteryConnected since emergency overrides are undesired here
let active = false;
switch (box.connected_position) {
case BigBatteryLocation.ENGINEERING:
Expand Down
22 changes: 20 additions & 2 deletions src/utils/bigbattery-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,36 @@ export interface BigBattery {
brightness: number;
// In what time is the battery depleted from 100% to 0%, minutes (configuration)
depletion_time_mins: number;
// Emergency assumed at positions (configuration)
emergency_assumed_at_positions: BigBatteryLocation[];
}

/**
* Check whether big battery is connected to the specified location and has charge remaining.
*/
export function isBatteryConnectedAndCharged(battery: BigBattery | undefined, location: BigBatteryLocation) {
export function isBatteryConnectedAndCharged(
battery: BigBattery | undefined,
location: BigBatteryLocation,
allow_emergency_override = true
) {
if (allow_emergency_override && (battery?.emergency_assumed_at_positions ?? []).includes(location)) {
// Emergency override allows to assume battery is always connected here
return true;
}
return battery?.connected_position === location && battery?.capacity_percent > 0;
}

/**
* Check whether big battery is connected to the specified location (regardless whether charged).
*/
export function isBatteryConnected(battery: BigBattery | undefined, location: BigBatteryLocation) {
export function isBatteryConnected(
battery: BigBattery | undefined,
location: BigBatteryLocation,
allow_emergency_override = true
) {
if (allow_emergency_override && (battery?.emergency_assumed_at_positions ?? []).includes(location)) {
// Emergency override allows to assume battery is always connected here
return true;
}
return battery?.connected_position === location;
}

0 comments on commit 03dade0

Please sign in to comment.