preferences

package
v5.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveAppPreferences

func SaveAppPreferences(app string, setters ...AppPref) error

SaveAppPreferences will save the given preferences for the given app to a file on disk. Any existing preferences will be preserved. If there are no existing preferences, a new preferences file will be created.

func SavePreferences

func SavePreferences(setters ...Pref) error

SavePreferences writes the given preferences to disk under the specified path. If the path is "", the preferences are saved to the file specified by PreferencesFile under the location specified by ConfigBasePath.

func SetFile

func SetFile(file string)

SetFile will set the filename of the preferences file to the given name. This function is optional and a default filename is used when calling Load/Save if it is not called.

func SetPath

func SetPath(path string)

SetPath will set the path to the preferences file to the given path. This function is optional and a default path is used when calling Load/Save if it is not called.

Types

type AppPref

type AppPref func(*AppPreferences)

AppPref is a functional type for applying AppPreferences

func SetAppPreferences

func SetAppPreferences(prefs map[string]any) AppPref

SetAppPreferences will assign the given preferences map to the AppPreferences struct.

type AppPreferences

type AppPreferences struct {
	Prefs map[string]any `toml:"preferences"`
}

AppPreferences holds a given app's preferences as a generic map[string]any.

func DefaultAppPreferences

func DefaultAppPreferences() *AppPreferences

DefaultAppPreferences returns an empty AppPreferences struct ready for use by apps.

func LoadAppPreferences

func LoadAppPreferences(app string) (*AppPreferences, error)

LoadAppPreferences will load the given app preferences from file. If there are no existing preferences, it will return an os.IsNotExist error and a default (empty) AppPreferences.

type Pref

type Pref func(*Preferences)

Pref is a functional type for applying a value to a particular preference.

func RegisterApps

func RegisterApps(apps ...string) Pref

RegisterApps is the functional preference that appends the list of given apps to the existing registered apps in the preferences.

func SetMQTTPassword added in v5.0.1

func SetMQTTPassword(password string) Pref

SetMQTTPassword is the functional preference that sets the SetMQTTPassword preference to the specified value.

func SetMQTTServer added in v5.0.1

func SetMQTTServer(server string) Pref

SetMQTTServer is the functional preference that sets the SetMQTTServer preference to the specified value.

func SetMQTTUser added in v5.0.1

func SetMQTTUser(user string) Pref

SetMQTTUser is the functional preference that sets the SetMQTTUser preference to the specified value.

func UnRegisterApps

func UnRegisterApps(apps ...string) Pref

UnRegisterApps is the functional preference that will remove the list of given apps from the registered apps in the preferences.

type Preferences

type Preferences struct {
	Server         string   `toml:"mqttserver"`
	User           string   `toml:"mqttuser,omitempty"`
	Password       string   `toml:"mqttpassword,omitempty"`
	RegisteredApps []string `toml:"registeredapps,omitempty"`
}

Preferences is a struct containing the general preferences for either the agent or for any code that imports go-hass-anything as a package. Currently, these preferences are for MQTT connectivity selection.

func LoadPreferences

func LoadPreferences() (*Preferences, error)

LoadPreferences retrives all Preferences from disk at the given path. If the path is "", the preferences are loaded from the file specified by PreferencesFile under the location specified by ConfigBasePath.

func (*Preferences) GetMQTTPassword added in v5.0.1

func (p *Preferences) GetMQTTPassword() string

MQTTPassword returns any password set in the preferences.

func (*Preferences) GetMQTTServer added in v5.0.1

func (p *Preferences) GetMQTTServer() string

MQTTServer returns the current server set in the preferences.

func (*Preferences) GetMQTTUser added in v5.0.1

func (p *Preferences) GetMQTTUser() string

MQTTUser returns any username set in the preferences.

func (*Preferences) IsRegistered

func (p *Preferences) IsRegistered(app string) bool

IsRegistered will check whether the given app has been recorded as registered in the preferences.

Jump to

Keyboard shortcuts

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