plugin

package
v0.0.0-...-8e521ca Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCombinedPlugin

func NewCombinedPlugin(plugged, charging func() (bool, error)) *combinedPlugin

NewCombinedPlugin creates provider for OpenWB status converted from MQTT topics

Types

type Auth

type Auth struct {
	Type, User, Password string
}

Auth is the authorization config

type BoolGetter

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

plugin types

type BoolSetter

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

plugin types

type BytesSetter

type BytesSetter interface {
	BytesSetter(param string) (func([]byte) error, error)
}

plugin types

type Case

type Case struct {
	Case string
	Set  Config
}

type Config

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

Config is the general plugin config

func (*Config) BoolGetter

func (c *Config) BoolGetter(ctx context.Context) (func() (bool, error), error)

func (*Config) BoolSetter

func (c *Config) BoolSetter(ctx context.Context, param string) (func(bool) error, error)

func (*Config) BytesSetter

func (c *Config) BytesSetter(ctx context.Context, param string) (func([]byte) error, error)

func (*Config) FloatGetter

func (c *Config) FloatGetter(ctx context.Context) (func() (float64, error), error)

func (*Config) FloatSetter

func (c *Config) FloatSetter(ctx context.Context, param string) (func(float642 float64) error, error)

func (*Config) IntGetter

func (c *Config) IntGetter(ctx context.Context) (func() (int64, error), error)

func (*Config) IntSetter

func (c *Config) IntSetter(ctx context.Context, param string) (func(int64) error, error)

func (*Config) StringGetter

func (c *Config) StringGetter(ctx context.Context) (func() (string, error), error)

func (*Config) StringSetter

func (c *Config) StringSetter(ctx context.Context, param string) (func(string) error, error)

type FloatGetter

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

plugin types

type FloatSetter

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

plugin types

type Getters

type Getters interface {
	StringGetter
	FloatGetter
	IntGetter
	BoolGetter
}

plugin 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), error)

BoolGetter parses bool from request

func (*Go) BoolSetter

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

BoolSetter sends bool request

func (*Go) FloatGetter

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

FloatGetter parses float from request

func (*Go) FloatSetter

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

FloatSetter sends float request

func (*Go) IntGetter

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

IntGetter parses int64 from request

func (*Go) IntSetter

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

IntSetter sends int request

func (*Go) StringGetter

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

StringGetter parses string from request

func (*Go) StringSetter

func (p *Go) StringSetter(param string) (func(string) error, 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, cache time.Duration) *HTTP

NewHTTP create HTTP provider

func (HTTP) BoolGetter

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

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

func (*HTTP) BoolSetter

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

BoolSetter sends bool request

func (HTTP) FloatGetter

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

FloatGetter parses float from exec result

func (*HTTP) FloatSetter

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

FloatSetter sends int request

func (HTTP) IntGetter

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

IntGetter parses int64 from exec result

func (*HTTP) IntSetter

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

IntSetter sends int request

func (*HTTP) StringGetter

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

StringGetter sends string request

func (*HTTP) StringSetter

func (p *HTTP) StringSetter(param string) (func(string) error, 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 IntGetter

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

plugin types

type IntSetter

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

plugin 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), error)

BoolGetter parses bool from request

func (*Javascript) BoolSetter

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

BoolSetter sends bool request

func (*Javascript) FloatGetter

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

FloatGetter parses float from request

func (*Javascript) FloatSetter

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

FloatSetter sends float request

func (*Javascript) IntGetter

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

IntGetter parses int64 from request

func (*Javascript) IntSetter

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

IntSetter sends int request

func (*Javascript) StringGetter

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

StringGetter parses string from request

func (*Javascript) StringSetter

func (p *Javascript) StringSetter(param string) (func(string) error, 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), error)

BoolGetter implements BoolProvider

func (*Modbus) BoolSetter

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

BoolSetter implements BoolSetter

func (*Modbus) BytesSetter

func (m *Modbus) BytesSetter(_ string) (func([]byte) error, error)

BytesSetter implements BytesSetter

func (*Modbus) FloatGetter

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

FloatGetter implements func() (float64, error)

func (*Modbus) FloatSetter

func (m *Modbus) FloatSetter(_ string) (func(float64) error, error)

FloatSetter implements FloatSetter

func (*Modbus) IntGetter

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

IntGetter implements IntProvider

func (*Modbus) IntSetter

func (m *Modbus) IntSetter(_ string) (func(int64) error, error)

IntSetter implements IntSetter

func (*Modbus) StringGetter

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

StringGetter implements StringProvider

type ModbusSunspec

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

ModbusSunspec implements modbus RTU and TCP access

func (*ModbusSunspec) FloatGetter

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

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

func (*ModbusSunspec) FloatSetter

func (m *ModbusSunspec) FloatSetter(_ string) (func(float64) error, error)

FloatSetter executes configured modbus write operation and implements FloatSetter

func (*ModbusSunspec) IntGetter

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

IntGetter executes configured modbus read operation and implements IntProvider

func (*ModbusSunspec) IntSetter

func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error)

IntSetter executes configured modbus write operation and implements IntSetter

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 (p Mqtt) BoolGetter() (func() (bool, error), error)

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

func (*Mqtt) BoolSetter

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

BoolSetter invokes script with parameter replaced by bool value

func (Mqtt) FloatGetter

func (p Mqtt) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from exec result

func (*Mqtt) FloatSetter

func (m *Mqtt) FloatSetter(param string) (func(float64) error, error)

FloatSetter publishes topic with parameter replaced by float value

func (Mqtt) IntGetter

func (p Mqtt) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from exec result

func (*Mqtt) IntSetter

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

IntSetter publishes topic with parameter replaced by int value

func (*Mqtt) StringGetter

func (m *Mqtt) StringGetter() (func() (string, error), 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, 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 Plugin

type Plugin interface{}

plugin types

func NewCalcFromConfig

func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewCalcFromConfig creates calc provider

func NewChargerEnableFromConfig

func NewChargerEnableFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewChargerEnableFromConfig creates type conversion provider

func NewCombinedFromConfig

func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewCombinedFromConfig creates combined provider

func NewConstFromConfig

func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewConstFromConfig creates const provider

func NewConvertFromConfig

func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewConvertFromConfig creates type conversion provider

func NewErrorFromConfig

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

NewErrorFromConfig creates error provider

func NewGoPluginFromConfig

func NewGoPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewGoPluginFromConfig creates a Go provider

func NewHTTPPluginFromConfig

func NewHTTPPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewHTTPPluginFromConfig creates a HTTP provider

func NewIgnoreFromConfig

func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewIgnoreFromConfig creates const provider

func NewJavascriptPluginFromConfig

func NewJavascriptPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewJavascriptPluginFromConfig creates a Javascript provider

func NewMapFromConfig

func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewMapFromConfig creates type conversion provider

func NewModbusFromConfig

func NewModbusFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewModbusFromConfig creates Modbus plugin

func NewModbusSunspecFromConfig

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

NewModbusSunspecFromConfig creates Modbus plugin

func NewMqttPluginFromConfig

func NewMqttPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewMqttPluginFromConfig creates Mqtt provider

func NewPrometheusFromConfig

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

func NewRandomFromConfig

func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewRandomFromConfig creates random provider

func NewSMAFromConfig

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

NewSMAFromConfig creates SMA provider

func NewScriptPluginFromConfig

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

NewScriptPluginFromConfig creates a script plugin.

func NewSequenceFromConfig

func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewSequenceFromConfig creates sequence provider

func NewSocketPluginFromConfig

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

NewSocketPluginFromConfig creates a HTTP provider

func NewSwitchFromConfig

func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewSwitchFromConfig creates switch provider

func NewWatchDogFromConfig

func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error)

NewWatchDogFromConfig creates watchDog provider

func TimeSeriesFromConfig

func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Plugin, error)

TimeSeriesFromConfig creates timeseries provider

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), error)

FloatGetter expects scalar value from query response as float

func (*Prometheus) IntGetter

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

IntGetter expects scalar value from query response as int

func (*Prometheus) Query

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

type SMA

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

SMA provider

func (*SMA) FloatGetter

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

FloatGetter creates handler for float64

func (*SMA) IntGetter

func (p *SMA) IntGetter() (func() (int64, error), 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 NewScriptPlugin

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

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

func (Script) BoolGetter

func (p Script) BoolGetter() (func() (bool, error), 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, error)

BoolSetter invokes script with parameter replaced by bool value

func (Script) FloatGetter

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

FloatGetter parses float from exec result

func (Script) IntGetter

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

IntGetter parses int64 from exec result

func (*Script) IntSetter

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

IntSetter invokes script with parameter replaced by int value

func (*Script) StringGetter

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

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

func (*Script) StringSetter

func (p *Script) StringSetter(param string) (func(string) error, error)

StringSetter returns a function that invokes a script with parameter by a string value

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), error)

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

func (Socket) FloatGetter

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

FloatGetter parses float from exec result

func (Socket) IntGetter

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

IntGetter parses int64 from exec result

func (*Socket) StringGetter

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

StringGetter sends string request

type StringGetter

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

plugin types

type StringSetter

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

plugin 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(p BoolGetter) (func() (bool, error), error)

func (*TimeoutHandler) FloatGetter

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

func (*TimeoutHandler) JsonGetter

func (h *TimeoutHandler) JsonGetter(p StringGetter) (func(any) error, error)

func (*TimeoutHandler) StringGetter

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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