config

package
v0.2024.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	Name    string           `json:"name,omitempty"`  // The name of the option. Used as default for OptionSource.Value
	Key     string           `json:"key,omitempty"`   // The mode name, defaults to Root.Modes key. e.g. "occupancy". Used as default for OptionSource.Mode
	Value   string           `json:"value,omitempty"` // The value used by this option, defaults to Option.Name. e.g. "occupied
	Sources []SourceOrString `json:"sources,omitempty"`
}

type OptionSource

type OptionSource struct {
	Devices []string `json:"devices,omitempty"`
	Mode    string   `json:"mode,omitempty"`  // The mode name, defaults to Option.Key. e.g. "occupancy"
	Value   string   `json:"value,omitempty"` // The value used by this option, defaults to Option.Value. e.g. "occupied"
}

type Root

type Root struct {
	zone.Config

	Modes map[string][]Option `json:"modes,omitempty"`
}

func ReadConfig

func ReadConfig(in io.Reader) (Root, error)

func ReadConfigBytes

func ReadConfigBytes(in []byte) (Root, error)

func (Root) AllDeviceNames

func (r Root) AllDeviceNames() []string

func (*Root) Hydrate

func (r *Root) Hydrate()

Hydrate fills defaults with their actual values. Called as part of ReadConfig. r is modified in place, each OptionSource will have its Mode and Value set based on the Modes key or Option.Name.

func (*Root) Unhydrate

func (r *Root) Unhydrate()

Unhydrate removes defaults and replaces them with empty strings. Called as part of WriteConfig. r is modified in place, each OptionSource will have its Mode and Value set to "" if it is equal to Modes key or Option.Name.

func (*Root) WriteConfig

func (r *Root) WriteConfig(out io.Writer) error

type SourceOrString

type SourceOrString struct {
	OptionSource
}

SourceOrString is like OptionSource but for simple cases like `{"devices": ["foo"]}` un/marshals from/to `"foo"`.

func (SourceOrString) MarshalJSON

func (m SourceOrString) MarshalJSON() ([]byte, error)

func (*SourceOrString) UnmarshalJSON

func (m *SourceOrString) UnmarshalJSON(bytes []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL