Documentation
¶
Overview ¶
Package sensorapp demonstrates an app that displays sensors in Home Assistant. When the sensor states change, their values will change in Home Assistant. Go Hass Anything will poll the app to update its state on the interval provided. The app also provides a preference for configuration of a URL for a data source of one of the sensors, which the agent will present when run with the "configure" option. The remote data is fetched through the use of the web helper, reducing the need for writing code to talk to a remote server.
Index ¶
- Variables
- type SensorApp
- func (a *SensorApp) Configuration() []*mqttapi.Msg
- func (a *SensorApp) DefaultPreferences() preferences.AppPreferences
- func (a *SensorApp) Name() string
- func (a *SensorApp) PollConfig() (interval, jitter time.Duration)
- func (a *SensorApp) States() []*mqttapi.Msg
- func (a *SensorApp) Subscriptions() []*mqttapi.Subscription
- func (a *SensorApp) URL() string
- func (a *SensorApp) UnmarshalJSON(data []byte) error
- func (a *SensorApp) Update(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var ErrFetchWeatherFailed = errors.New("could not get weather data")
Functions ¶
This section is empty.
Types ¶
type SensorApp ¶
type SensorApp struct {
// contains filtered or unexported fields
}
func (*SensorApp) Configuration ¶
func (*SensorApp) DefaultPreferences ¶
func (a *SensorApp) DefaultPreferences() preferences.AppPreferences
func (*SensorApp) PollConfig ¶
PollConfig defines our polling interval and jitter and instructs the agent to fetch our state values on these.
func (*SensorApp) Subscriptions ¶
func (a *SensorApp) Subscriptions() []*mqttapi.Subscription
Subscriptions is unused. Sensors do not have any interactivity requirements.
func (*SensorApp) URL ¶
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 (*SensorApp) UnmarshalJSON ¶
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.