provider

package
v0.0.0-...-cba36cc Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cached

func Cached[T any](g func() (T, error), cache time.Duration) func() (T, error)

Cached wraps a getter with a cache

func NewBoolGetterFromConfig

func NewBoolGetterFromConfig(config Config) (func() (bool, error), error)

NewBoolGetterFromConfig creates a BoolGetter from config

func NewBoolSetterFromConfig

func NewBoolSetterFromConfig(param string, config Config) (func(bool) error, error)

NewBoolSetterFromConfig creates a BoolSetter from config

func NewFloatGetterFromConfig

func NewFloatGetterFromConfig(config Config) (func() (float64, error), error)

NewFloatGetterFromConfig creates a FloatGetter from config

func NewFloatSetterFromConfig

func NewFloatSetterFromConfig(param string, config Config) (func(float642 float64) error, error)

NewFloatSetterFromConfig creates a FloatSetter from config

func NewIntGetterFromConfig

func NewIntGetterFromConfig(config Config) (func() (int64, error), error)

NewIntGetterFromConfig creates a IntGetter from config

func NewIntSetterFromConfig

func NewIntSetterFromConfig(param string, config Config) (func(int64) error, error)

NewIntSetterFromConfig creates a IntSetter from config

func NewOpenWBStatusProviderFromConfig

func NewOpenWBStatusProviderFromConfig(other map[string]interface{}) (func() (string, error), error)

NewOpenWBStatusProviderFromConfig creates OpenWBStatus from given configuration

func NewStringGetterFromConfig

func NewStringGetterFromConfig(config Config) (func() (string, error), error)

NewStringGetterFromConfig creates a StringGetter from config

func NewStringSetterFromConfig

func NewStringSetterFromConfig(param string, config Config) (func(string) error, error)

NewStringSetterFromConfig creates a StringSetter from config

func ResetCached

func ResetCached()

func ResettableCached

func ResettableCached[T any](g func() (T, error), cache time.Duration) *cached[T]

ResettableCached wraps a getter with a cache. It returns a `Cacheable`. Instead of the cached getter, the `Get()` and `Reset()` methods are exposed.

func UintFromBytes

func UintFromBytes(bytes []byte) (u uint64, err error)

UintFromBytes converts byte slice to bigendian uint value

Types

type Auth

type Auth struct {
	Type, User, Password string
}

Auth is the authorization config

type BoolProvider

type BoolProvider interface {
	BoolGetter() func() (bool, error)
}

provider types

type Cacheable

type Cacheable[T any] interface {
	Get() (T, error)
	Reset()
}

Cacheable is the interface for a resettable cache

type Config

type Config struct {
	Source string
	Other  map[string]interface{} `mapstructure:",remain"`
}

Config is the general provider config

type FloatProvider

type FloatProvider interface {
	FloatGetter() func() (float64, error)
}

provider types

type Go

type Go struct {
	// contains filtered or unexported fields
}

Go implements Go request provider

func (*Go) BoolGetter

func (p *Go) BoolGetter() func() (bool, error)

BoolGetter parses bool from request

func (*Go) BoolSetter

func (p *Go) BoolSetter(param string) func(bool) error

BoolSetter sends bool request

func (*Go) FloatGetter

func (p *Go) FloatGetter() func() (float64, error)

FloatGetter parses float from request

func (*Go) FloatSetter

func (p *Go) FloatSetter(param string) func(float64) error

FloatSetter sends float request

func (*Go) IntGetter

func (p *Go) IntGetter() func() (int64, error)

IntGetter parses int64 from request

func (*Go) IntSetter

func (p *Go) IntSetter(param string) func(int64) error

IntSetter sends int request

func (*Go) StringGetter

func (p *Go) StringGetter() func() (string, error)

StringGetter parses string from request

func (*Go) StringSetter

func (p *Go) StringSetter(param string) func(string) error

StringSetter sends string request

type HTTP

type HTTP struct {
	*request.Helper
	// contains filtered or unexported fields
}

HTTP implements HTTP request provider

func NewHTTP

func NewHTTP(log *util.Logger, method, uri string, insecure bool, scale float64, cache time.Duration) *HTTP

NewHTTP create HTTP provider

func (*HTTP) BoolGetter

func (p *HTTP) BoolGetter() func() (bool, error)

BoolGetter parses bool from request

func (*HTTP) BoolSetter

func (p *HTTP) BoolSetter(param string) func(bool) error

BoolSetter sends bool request

func (*HTTP) FloatGetter

func (p *HTTP) FloatGetter() func() (float64, error)

FloatGetter parses float from request

func (*HTTP) FloatSetter

func (p *HTTP) FloatSetter(param string) func(float64) error

FloatSetter sends int request

func (*HTTP) IntGetter

func (p *HTTP) IntGetter() func() (int64, error)

IntGetter parses int64 from request

func (*HTTP) IntSetter

func (p *HTTP) IntSetter(param string) func(int64) error

IntSetter sends int request

func (*HTTP) StringGetter

func (p *HTTP) StringGetter() func() (string, error)

StringGetter sends string request

func (*HTTP) StringSetter

func (p *HTTP) StringSetter(param string) func(string) error

StringSetter sends string request

func (*HTTP) WithAuth

func (p *HTTP) WithAuth(typ, user, password string) (*HTTP, error)

WithAuth adds authorized transport

func (*HTTP) WithBody

func (p *HTTP) WithBody(body string) *HTTP

WithBody adds request body

func (*HTTP) WithHeaders

func (p *HTTP) WithHeaders(headers map[string]string) *HTTP

WithHeaders adds request headers

func (*HTTP) WithPipeline

func (p *HTTP) WithPipeline(pipeline *pipeline.Pipeline) *HTTP

WithPipeline adds a processing pipeline

type IntProvider

type IntProvider interface {
	IntGetter() func() (int64, error)
}

provider types

type Javascript

type Javascript struct {
	// contains filtered or unexported fields
}

Javascript implements Javascript request provider

func (*Javascript) BoolGetter

func (p *Javascript) BoolGetter() func() (bool, error)

BoolGetter parses bool from request

func (*Javascript) BoolSetter

func (p *Javascript) BoolSetter(param string) func(bool) error

BoolSetter sends bool request

func (*Javascript) FloatGetter

func (p *Javascript) FloatGetter() func() (float64, error)

FloatGetter parses float from request

func (*Javascript) FloatSetter

func (p *Javascript) FloatSetter(param string) func(float64) error

FloatSetter sends float request

func (*Javascript) IntGetter

func (p *Javascript) IntGetter() func() (int64, error)

IntGetter parses int64 from request

func (*Javascript) IntSetter

func (p *Javascript) IntSetter(param string) func(int64) error

IntSetter sends int request

func (*Javascript) StringGetter

func (p *Javascript) StringGetter() func() (string, error)

StringGetter parses string from request

func (*Javascript) StringSetter

func (p *Javascript) StringSetter(param string) func(string) error

StringSetter sends string request

type Modbus

type Modbus struct {
	// contains filtered or unexported fields
}

Modbus implements modbus RTU and TCP access

func (*Modbus) BoolGetter

func (m *Modbus) BoolGetter() func() (bool, error)

BoolGetter executes configured modbus read operation and implements IntProvider

func (*Modbus) BoolSetter

func (m *Modbus) BoolSetter(param string) func(bool) error

BoolSetter executes configured modbus write operation and implements SetBoolProvider

func (*Modbus) FloatGetter

func (m *Modbus) FloatGetter() func() (f float64, err error)

FloatGetter executes configured modbus read operation and implements func() (float64, error)

func (*Modbus) IntGetter

func (m *Modbus) IntGetter() func() (int64, error)

IntGetter executes configured modbus read operation and implements IntProvider

func (*Modbus) IntSetter

func (m *Modbus) IntSetter(param string) func(int64) error

IntSetter executes configured modbus write operation and implements SetIntProvider

func (*Modbus) StringGetter

func (m *Modbus) StringGetter() func() (string, error)

StringGetter executes configured modbus read operation and implements IntProvider

type Mqtt

type Mqtt struct {
	// contains filtered or unexported fields
}

Mqtt provider

func NewMqtt

func NewMqtt(log *util.Logger, client *mqtt.Client, topic string, timeout time.Duration) *Mqtt

NewMqtt creates mqtt provider for given topic

func (*Mqtt) BoolGetter

func (m *Mqtt) BoolGetter() func() (bool, error)

BoolGetter creates handler for string from MQTT topic that returns cached value

func (*Mqtt) BoolSetter

func (m *Mqtt) BoolSetter(param string) func(bool) error

BoolSetter invokes script with parameter replaced by bool value

func (*Mqtt) FloatGetter

func (m *Mqtt) FloatGetter() func() (float64, error)

FloatGetter creates handler for float64 from MQTT topic that returns cached value

func (*Mqtt) IntGetter

func (m *Mqtt) IntGetter() func() (int64, error)

IntGetter creates handler for int64 from MQTT topic that returns cached value

func (*Mqtt) IntSetter

func (m *Mqtt) IntSetter(param string) func(int64) error

IntSetter publishes topic with parameter replaced by int value

func (*Mqtt) StringGetter

func (m *Mqtt) StringGetter() func() (string, error)

StringGetter creates handler for string from MQTT topic that returns cached value

func (*Mqtt) StringSetter

func (m *Mqtt) StringSetter(param string) func(string) error

StringSetter invokes script with parameter replaced by string value

func (*Mqtt) WithPayload

func (m *Mqtt) WithPayload(payload string) *Mqtt

WithPayload adds payload for setters

func (*Mqtt) WithPipeline

func (p *Mqtt) WithPipeline(pipeline *pipeline.Pipeline) *Mqtt

WithPipeline adds a processing pipeline

func (*Mqtt) WithRetained

func (m *Mqtt) WithRetained() *Mqtt

WithRetained adds retained flag for setters

func (*Mqtt) WithScale

func (m *Mqtt) WithScale(scale float64) *Mqtt

WithScale sets scaler for getters

type OpenWBStatus

type OpenWBStatus struct {
	// contains filtered or unexported fields
}

OpenWBStatus implements status conversion from openWB to api.Status

func NewOpenWBStatusProvider

func NewOpenWBStatusProvider(plugged, charging func() (bool, error)) *OpenWBStatus

NewOpenWBStatusProvider creates provider for OpenWB status converted from MQTT topics

func (*OpenWBStatus) StringGetter

func (o *OpenWBStatus) StringGetter() (string, error)

StringGetter returns string from OpenWB charging/ plugged status

type Prometheus

type Prometheus struct {
	// contains filtered or unexported fields
}

Prometheus provider

func NewPrometheus

func NewPrometheus(log *util.Logger, client api.Client, query string, timeout time.Duration) *Prometheus

func (*Prometheus) FloatGetter

func (p *Prometheus) FloatGetter() func() (float64, error)

FloatGetter expects scalar value from query response as float

func (*Prometheus) IntGetter

func (p *Prometheus) IntGetter() func() (int64, error)

IntGetter expects scalar value from query response as int

func (*Prometheus) Query

func (p *Prometheus) Query() (model.Value, error)

type Provider

type Provider interface{}

provider types

func NewCalcFromConfig

func NewCalcFromConfig(other map[string]interface{}) (Provider, error)

NewCalcFromConfig creates calc provider

func NewCombinedFromConfig

func NewCombinedFromConfig(other map[string]interface{}) (Provider, error)

NewCombinedFromConfig creates combined provider

func NewConstFromConfig

func NewConstFromConfig(other map[string]interface{}) (Provider, error)

NewConstFromConfig creates const provider

func NewGoProviderFromConfig

func NewGoProviderFromConfig(other map[string]interface{}) (Provider, error)

NewGoProviderFromConfig creates a Go provider

func NewHTTPProviderFromConfig

func NewHTTPProviderFromConfig(other map[string]interface{}) (Provider, error)

NewHTTPProviderFromConfig creates a HTTP provider

func NewJavascriptProviderFromConfig

func NewJavascriptProviderFromConfig(other map[string]interface{}) (Provider, error)

NewJavascriptProviderFromConfig creates a Javascript provider

func NewModbusFromConfig

func NewModbusFromConfig(other map[string]interface{}) (Provider, error)

NewModbusFromConfig creates Modbus plugin

func NewMqttFromConfig

func NewMqttFromConfig(other map[string]interface{}) (Provider, error)

NewMqttFromConfig creates Mqtt provider

func NewPrometheusFromConfig

func NewPrometheusFromConfig(other map[string]interface{}) (Provider, error)

func NewSMAFromConfig

func NewSMAFromConfig(other map[string]interface{}) (Provider, error)

NewSMAFromConfig creates SMA provider

func NewScriptProviderFromConfig

func NewScriptProviderFromConfig(other map[string]interface{}) (Provider, error)

NewScriptProviderFromConfig creates a script provider.

func NewSocketProviderFromConfig

func NewSocketProviderFromConfig(other map[string]interface{}) (Provider, error)

NewSocketProviderFromConfig creates a HTTP provider

type SMA

type SMA struct {
	// contains filtered or unexported fields
}

SMA provider

func (*SMA) FloatGetter

func (p *SMA) FloatGetter() func() (float64, error)

FloatGetter creates handler for float64

func (*SMA) IntGetter

func (p *SMA) IntGetter() func() (int64, error)

IntGetter creates handler for int64

type Script

type Script struct {
	// contains filtered or unexported fields
}

Script implements shell script-based providers and setters

func NewScriptProvider

func NewScriptProvider(script string, timeout time.Duration, scale float64, cache time.Duration) (*Script, error)

NewScriptProvider creates a script provider. Script execution is aborted after given timeout.

func (*Script) BoolGetter

func (p *Script) BoolGetter() func() (bool, error)

BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.

func (*Script) BoolSetter

func (p *Script) BoolSetter(param string) func(bool) error

BoolSetter invokes script with parameter replaced by bool value

func (*Script) FloatGetter

func (p *Script) FloatGetter() func() (float64, error)

FloatGetter parses float from exec result

func (*Script) IntGetter

func (p *Script) IntGetter() func() (int64, error)

IntGetter parses int64 from exec result

func (*Script) IntSetter

func (p *Script) IntSetter(param string) func(int64) error

IntSetter invokes script with parameter replaced by int value

func (*Script) StringGetter

func (p *Script) StringGetter() func() (string, error)

StringGetter returns string from exec result. Only STDOUT is considered.

func (*Script) WithJq

func (p *Script) WithJq(jq string) (*Script, error)

func (*Script) WithRegex

func (p *Script) WithRegex(regex string) (*Script, error)

type SetBoolProvider

type SetBoolProvider interface {
	BoolSetter(param string) func(bool) error
}

provider types

type SetFloatProvider

type SetFloatProvider interface {
	FloatSetter(param string) func(float64) error
}

provider types

type SetIntProvider

type SetIntProvider interface {
	IntSetter(param string) func(int64) error
}

provider types

type SetStringProvider

type SetStringProvider interface {
	StringSetter(param string) func(string) error
}

provider types

type Socket

type Socket struct {
	*request.Helper
	// contains filtered or unexported fields
}

Socket implements websocket request provider

func (*Socket) BoolGetter

func (p *Socket) BoolGetter() func() (bool, error)

BoolGetter parses bool from string getter

func (*Socket) FloatGetter

func (p *Socket) FloatGetter() func() (float64, error)

FloatGetter parses float from string getter

func (*Socket) IntGetter

func (p *Socket) IntGetter() func() (int64, error)

IntGetter parses int64 from float getter

func (*Socket) StringGetter

func (p *Socket) StringGetter() func() (string, error)

StringGetter sends string request

type StringProvider

type StringProvider interface {
	StringGetter() func() (string, error)
}

provider types

type TimeoutHandler

type TimeoutHandler struct {
	// contains filtered or unexported fields
}

TimeoutHandler is a wrapper for a Getter that times out after a given duration

func NewTimeoutHandler

func NewTimeoutHandler(ticker func() (string, error)) *TimeoutHandler

func (*TimeoutHandler) BoolGetter

func (h *TimeoutHandler) BoolGetter(g func() (bool, error)) func() (bool, error)

func (*TimeoutHandler) FloatGetter

func (h *TimeoutHandler) FloatGetter(g func() (float64, error)) func() (float64, error)

func (*TimeoutHandler) StringGetter

func (h *TimeoutHandler) StringGetter(g func() (string, error)) func() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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