Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SaveAppPreferences ¶
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 ¶
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.
Types ¶
type AppPref ¶
type AppPref func(*AppPreferences)
AppPref is a functional type for applying AppPreferences
func SetAppPreferences ¶
SetAppPreferences will assign the given preferences map to the AppPreferences struct.
type AppPreferences ¶
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 MQTTPassword ¶
MQTTPassword is the functional preference that sets the MQTTPassword preference to the specified value.
func MQTTServer ¶
MQTTServer is the functional preference that sets the MQTTServer preference to the specified value.
func MQTTUser ¶
MQTTUser is the functional preference that sets the MQTTUser preference to the specified value.
func RegisterApps ¶
RegisterApps is the functional preference that appends the list of given apps to the existing registered apps in the preferences.
func UnRegisterApps ¶
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) IsRegistered ¶
func (p *Preferences) IsRegistered(app string) bool
IsRegistered will check whether the given app has been recorded as registered in the preferences.
func (*Preferences) MQTTPassword ¶
func (p *Preferences) MQTTPassword() string
MQTTPassword returns any password set in the preferences.
func (*Preferences) MQTTServer ¶
func (p *Preferences) MQTTServer() string
MQTTServer returns the current server set in the preferences.
func (*Preferences) MQTTUser ¶
func (p *Preferences) MQTTUser() string
MQTTUser returns any username set in the preferences.