Add server-side rendered setup UI accessible via `heatwave web`. The dashboard is now re-rendered per request and includes a nav bar linking to the new /setup page. Setup provides full CRUD for profiles, rooms, devices, occupants, AC units (with room assignment), scenario toggles, and forecast fetching — all via POST/redirect/GET forms. - Add ShowNav field to DashboardData for conditional nav bar - Extract fetchForecastForProfile() for reuse by web handler - Create setup.html.tmpl with Tailwind-styled entity sections - Create web_handlers.go with 15 route handlers and flash cookies - Switch web.go from pre-rendered to per-request dashboard rendering - Graceful dashboard fallback when no forecast data exists
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// Config holds the application configuration.
|
|
type Config struct {
|
|
LLM LLMConfig `yaml:"llm"`
|
|
}
|
|
|
|
// LLMConfig holds LLM provider settings.
|
|
type LLMConfig struct {
|
|
Provider string `yaml:"provider"` // anthropic, openai, ollama, none
|
|
Model string `yaml:"model"`
|
|
Endpoint string `yaml:"endpoint"` // for ollama
|
|
}
|
|
|
|
// DefaultConfig returns a Config with sensible defaults.
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
LLM: LLMConfig{Provider: "none"},
|
|
}
|
|
}
|
|
|
|
// ConfigDir returns the XDG config directory for heatwave.
|
|
func ConfigDir() string {
|
|
if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" {
|
|
return filepath.Join(xdg, "heatwave")
|
|
}
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, ".config", "heatwave")
|
|
}
|
|
|
|
// DataDir returns the XDG data directory for heatwave.
|
|
func DataDir() string {
|
|
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
|
|
return filepath.Join(xdg, "heatwave")
|
|
}
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, ".local", "share", "heatwave")
|
|
}
|
|
|
|
// DefaultDBPath returns the default SQLite database path.
|
|
func DefaultDBPath() string {
|
|
return filepath.Join(DataDir(), "heatwave.db")
|
|
}
|
|
|
|
// Load reads the config file from the config directory.
|
|
func Load() Config {
|
|
cfg := DefaultConfig()
|
|
path := filepath.Join(ConfigDir(), "config.yaml")
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return cfg
|
|
}
|
|
_ = yaml.Unmarshal(data, &cfg)
|
|
return cfg
|
|
}
|