preferences

package
v7.2.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 4 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 SetMQTTPassword

func SetMQTTPassword(password string) Pref

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

func SetMQTTServer

func SetMQTTServer(server string) Pref

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

func SetMQTTUser

func SetMQTTUser(user string) Pref

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

func SetTopicPrefix

func SetTopicPrefix(prefix string) Pref

SetTopicPrefix is the functional preference that sets the topic prefix preference to the specified value.

type Preferences

type Preferences struct {
	Server      string `toml:"mqttserver"`
	User        string `toml:"mqttuser,omitempty"`
	Password    string `toml:"mqttpassword,omitempty"`
	TopicPrefix string `toml:"topicprefix"`
}

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

func (p *Preferences) GetMQTTPassword() string

MQTTPassword returns any password set in the preferences.

func (*Preferences) GetMQTTServer

func (p *Preferences) GetMQTTServer() string

MQTTServer returns the current server set in the preferences.

func (*Preferences) GetMQTTUser

func (p *Preferences) GetMQTTUser() string

MQTTUser returns any username set in the preferences.

func (*Preferences) GetTopicPrefix

func (p *Preferences) GetTopicPrefix() string

TopicPrefix returns the topic prefix set in the preferences.

Jump to

Keyboard shortcuts

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