sensorapp

package
v11.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 New

func New(_ context.Context) (*SensorApp, error)

func (*SensorApp) Configuration

func (a *SensorApp) Configuration() []*mqttapi.Msg

func (*SensorApp) DefaultPreferences

func (a *SensorApp) DefaultPreferences() preferences.AppPreferences

func (*SensorApp) Name

func (a *SensorApp) Name() string

func (*SensorApp) PollConfig

func (a *SensorApp) PollConfig() (interval, jitter time.Duration)

PollConfig defines our polling interval and jitter and instructs the agent to fetch our state values on these.

func (*SensorApp) States

func (a *SensorApp) States() []*mqttapi.Msg

func (*SensorApp) Subscriptions

func (a *SensorApp) Subscriptions() []*mqttapi.Subscription

Subscriptions is unused. Sensors do not have any interactivity requirements.

func (*SensorApp) URL

func (a *SensorApp) 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 (*SensorApp) UnmarshalJSON

func (a *SensorApp) 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.

func (*SensorApp) Update

func (a *SensorApp) Update(ctx context.Context) error

Update will fetch the remote data.

Jump to

Keyboard shortcuts

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