|
| 1 | +package homeassistant |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + |
| 7 | + // Packages |
| 8 | + "github.com/mutablelogic/go-client" |
| 9 | +) |
| 10 | + |
| 11 | +/////////////////////////////////////////////////////////////////////////////// |
| 12 | +// TYPES |
| 13 | + |
| 14 | +// Config represents the Home Assistant server configuration. |
| 15 | +type Config struct { |
| 16 | + Components []string `json:"components"` |
| 17 | + ConfigDir string `json:"config_dir"` |
| 18 | + Elevation float64 `json:"elevation"` |
| 19 | + Latitude float64 `json:"latitude"` |
| 20 | + Longitude float64 `json:"longitude"` |
| 21 | + LocationName string `json:"location_name"` |
| 22 | + TimeZone string `json:"time_zone"` |
| 23 | + UnitSystem map[string]any `json:"unit_system"` |
| 24 | + Version string `json:"version"` |
| 25 | + ExternalDirs []string `json:"whitelist_external_dirs,omitempty"` |
| 26 | + AllowlistDirs []string `json:"allowlist_external_dirs,omitempty"` |
| 27 | + AllowlistURLs []string `json:"allowlist_external_urls,omitempty"` |
| 28 | + Currency string `json:"currency,omitempty"` |
| 29 | + Country string `json:"country,omitempty"` |
| 30 | + Language string `json:"language,omitempty"` |
| 31 | + SafeMode bool `json:"safe_mode,omitempty"` |
| 32 | + State string `json:"state,omitempty"` |
| 33 | + InternalURL string `json:"internal_url,omitempty"` |
| 34 | + ExternalURL string `json:"external_url,omitempty"` |
| 35 | + RecoveryMode bool `json:"recovery_mode,omitempty"` |
| 36 | +} |
| 37 | + |
| 38 | +/////////////////////////////////////////////////////////////////////////////// |
| 39 | +// API CALLS |
| 40 | + |
| 41 | +// Config returns the current server configuration. |
| 42 | +func (c *Client) Config(ctx context.Context) (*Config, error) { |
| 43 | + var response Config |
| 44 | + if err := c.DoWithContext(ctx, nil, &response, client.OptPath("config")); err != nil { |
| 45 | + return nil, err |
| 46 | + } |
| 47 | + return &response, nil |
| 48 | +} |
| 49 | + |
| 50 | +/////////////////////////////////////////////////////////////////////////////// |
| 51 | +// STRINGIFY |
| 52 | + |
| 53 | +func (v Config) String() string { |
| 54 | + data, _ := json.MarshalIndent(v, "", " ") |
| 55 | + return string(data) |
| 56 | +} |
0 commit comments