Nik Afiq b327150d45
All checks were successful
CI / test (push) Successful in 5s
CI / build-ai-gateway (push) Successful in 39s
CI / build-ha-gateway (push) Successful in 39s
CI / build-discord-bot (push) Successful in 40s
feat: implement ClimateApp for managing HVAC entities
- Added ClimateApp to handle climate entity operations including turning on/off, adjusting temperature, and setting HVAC modes.
- Implemented caching mechanism for climate entities to optimize state retrieval.
- Created domain model for Climate with attributes such as current temperature, target temperature, and HVAC modes.
- Developed unit tests for ClimateApp to ensure functionality and correctness.

feat: add RemoteApp for SwitchBot commands

- Introduced RemoteApp to facilitate sending commands to SwitchBot devices.
- Implemented SendCommand method for executing device commands without state management.

chore: update configuration for SwitchBot integration

- Added SwitchBotToken and SwitchBotSecret to configuration for enabling SwitchBot Cloud commands.

feat: define gRPC services for Climate and Remote operations

- Created climate.proto and remote.proto files to define gRPC services for climate management and remote command execution.
- Implemented corresponding request and response message structures for gRPC interactions.
2026-07-23 13:49:54 +09:00

56 lines
1.7 KiB
Go

package config
import (
"errors"
"os"
)
// Config holds runtime configuration for the Home Assistant gRPC gateway.
type Config struct {
GRPCPort string // GRPC_PORT, default "50051"
HABaseURL string // HA_BASE_URL, e.g. "http://ha.home.arpa:8123"
HAToken string // HA_TOKEN — long-lived access token (required)
TLSDir string // TLS_DIR, empty disables mTLS for local dev
OTELEndpoint string // OTEL_ENDPOINT, e.g. "otel-collector.monitoring.svc:4317"
LogLevel string // LOG_LEVEL, default "info"
LogFormat string // LOG_FORMAT, default "json"
// empty = telemetry disabled (local dev default)
SwitchBotToken string // SWITCHBOT_TOKEN, optional; enables SwitchBot Cloud commands
SwitchBotSecret string // SWITCHBOT_SECRET, optional; enables SwitchBot Cloud commands
}
// Load reads configuration from environment variables and applies defaults.
func Load() (*Config, error) {
token := os.Getenv("HA_TOKEN")
if token == "" {
return nil, errors.New("HA_TOKEN is required but not set")
}
port := os.Getenv("GRPC_PORT")
if port == "" {
port = "50051"
}
return &Config{
GRPCPort: port,
HABaseURL: os.Getenv("HA_BASE_URL"),
HAToken: token,
TLSDir: os.Getenv("TLS_DIR"),
OTELEndpoint: os.Getenv("OTEL_ENDPOINT"),
LogLevel: getenvDefault("LOG_LEVEL", "info"),
LogFormat: getenvDefault("LOG_FORMAT", "json"),
SwitchBotToken: os.Getenv("SWITCHBOT_TOKEN"),
SwitchBotSecret: os.Getenv("SWITCHBOT_SECRET"),
}, nil
}
// getenvDefault keeps config loading concise for optional variables with defaults.
func getenvDefault(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}