Documentation
¶
Index ¶
- Variables
- type ExampleApp
- func (a *ExampleApp) Configuration() []*mqttapi.Msg
- func (a *ExampleApp) MsgCh() chan *mqttapi.Msg
- func (a *ExampleApp) Name() string
- func (a *ExampleApp) PollConfig() (interval, jitter time.Duration)
- func (a *ExampleApp) Preferences() (preferences.AppPreferences, error)
- func (a *ExampleApp) States() []*mqttapi.Msg
- func (a *ExampleApp) Subscriptions() []*mqttapi.Subscription
- func (a *ExampleApp) URL() string
- func (a *ExampleApp) UnmarshalJSON(data []byte) error
- func (a *ExampleApp) Update(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ExampleApp ¶
type ExampleApp struct {
// contains filtered or unexported fields
}
func New ¶
func New(_ context.Context) (*ExampleApp, error)
New sets up our example app. We make use of the preference loading/saving in the agent to handle our preferences.
func (*ExampleApp) Configuration ¶
func (a *ExampleApp) Configuration() []*mqttapi.Msg
Configuration is called when our app is first registered in Home Assistant and will return configuration messages for the data our app will send/receive.
func (*ExampleApp) MsgCh ¶
func (a *ExampleApp) MsgCh() chan *mqttapi.Msg
MsgCh returns a channel through which we could pass any message to MQTT on any kind of custom event trigger or other non time-based polling.
func (*ExampleApp) Name ¶
func (a *ExampleApp) Name() string
Name simply returns the name of this app.
func (*ExampleApp) PollConfig ¶
func (a *ExampleApp) PollConfig() (interval, jitter time.Duration)
PollConfig defines our polling interval and jitter and instructs the agent to fetch our state values on these.
func (*ExampleApp) Preferences ¶
func (a *ExampleApp) Preferences() (preferences.AppPreferences, error)
Preferences sets up and returns our app preferences. This will load our preferences from disk. If no preferences file exists, default preferences will be set (as would be the case on first run).
func (*ExampleApp) States ¶
func (a *ExampleApp) States() []*mqttapi.Msg
States is called when we want to send our sensor data to Home Assistant.
func (*ExampleApp) Subscriptions ¶
func (a *ExampleApp) Subscriptions() []*mqttapi.Subscription
Subscriptions is called once to register the callbacks we will use when Home Assistant sends back messages on any command topics.
func (*ExampleApp) URL ¶
func (a *ExampleApp) URL() string
In order to use the web.ExecuteRequest helper to fetch the weather, we need to pass it a type that satisfies the web.Request interface. We can do this by adding a URL() method that returns the URL to our weather provider, to our app struct.
func (*ExampleApp) UnmarshalJSON ¶
func (a *ExampleApp) UnmarshalJSON(data []byte) error
We also need a way to save the response of the web request, and we can do this by satisfying the web.Response interface through adding a UnmarshalJSON that will take the raw response JSON and save it into our app struct.