Code Farm: per-plot auto-replant pause and crop-lock check; community sync and node work
DevPlace CI / test (push) Failing after 44m45s
DevPlace CI / test (push) Failing after 44m45s
Continuous Delivery could never be turned off once a crop was planted. Add a one-shot per-plot "stop after harvest" flag (POST /game/plot/stop, Devii tool game_plot_stop, game_plots.stop_after_harvest), cleared by the next plant, autoreplant claim or Refactor. Autoreplant now also respects crop locks through the shared _crop_lock predicate. Plan and measurements in happyplanting.md. Also includes the pending community sync, node network and related work in the tree; the full suite passed (4999) with all of it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const powerSupplyRoot = "/sys/class/power_supply"
|
||||
|
||||
func systemBattery() (bool, error) {
|
||||
return sysfsOnBattery(powerSupplyRoot)
|
||||
}
|
||||
|
||||
func readSupplyField(dir, name string) string {
|
||||
data, err := os.ReadFile(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
func isMainsType(kind string) bool {
|
||||
return kind == "Mains" || kind == "ADP" || strings.HasPrefix(kind, "USB")
|
||||
}
|
||||
|
||||
func sysfsOnBattery(root string) (bool, error) {
|
||||
entries, err := os.ReadDir(root)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
discharging := false
|
||||
for _, entry := range entries {
|
||||
dir := filepath.Join(root, entry.Name())
|
||||
if readSupplyField(dir, "scope") == "Device" {
|
||||
continue
|
||||
}
|
||||
kind := readSupplyField(dir, "type")
|
||||
switch {
|
||||
case kind == "Battery":
|
||||
if readSupplyField(dir, "status") == "Discharging" {
|
||||
discharging = true
|
||||
}
|
||||
case isMainsType(kind):
|
||||
if readSupplyField(dir, "online") == "1" {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return discharging, nil
|
||||
}
|
||||
Reference in New Issue
Block a user