provider

package
v0.0.0-...-e6e1b3f Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthHeaders

func AuthHeaders(log *util.Logger, auth Auth, headers map[string]string) error

AuthHeaders creates authorization headers from config

func NewBoolGetterFromConfig

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

NewBoolGetterFromConfig creates a BoolGetter from config

func NewBoolSetterFromConfig

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

NewBoolSetterFromConfig creates a BoolSetter from config

func NewFloatGetterFromConfig

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

NewFloatGetterFromConfig creates a FloatGetter from config

func NewIntGetterFromConfig

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

NewIntGetterFromConfig creates a IntGetter from config

func NewIntSetterFromConfig

func NewIntSetterFromConfig(param string, config Config) (res func(int64) error, err 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) (res func() (string, error), err error)

NewStringGetterFromConfig creates a StringGetter from config

func ResetCached

func ResetCached()

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 Cached

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

Cached wraps a getter with a cache

func NewCached

func NewCached(getter interface{}, cache time.Duration) *Cached

NewCached wraps a getter with a cache

func (*Cached) BoolGetter

func (c *Cached) BoolGetter() func() (bool, error)

BoolGetter gets bool value

func (*Cached) CacheReset

func (c *Cached) CacheReset() func() error

func (*Cached) DurationGetter

func (c *Cached) DurationGetter() func() (time.Duration, error)

DurationGetter gets time.Duration value

func (*Cached) FloatGetter

func (c *Cached) FloatGetter() func() (float64, error)

FloatGetter gets float value

func (*Cached) IntGetter

func (c *Cached) IntGetter() func() (int64, error)

IntGetter gets int value

func (*Cached) InterfaceGetter

func (c *Cached) InterfaceGetter() func() (interface{}, error)

InterfaceGetter gets interface value

func (*Cached) StringGetter

func (c *Cached) StringGetter() func() (string, error)

StringGetter gets string value

func (*Cached) TimeGetter

func (c *Cached) TimeGetter() func() (time.Time, error)

TimeGetter gets time.Time value

type Config

type Config struct {
	Type  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 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, headers map[string]string, body string, insecure bool, jq string, scale float64) (*HTTP, error)

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

type IntProvider

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

provider types

func NewCalcFromConfig

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

NewCalcFromConfig creates calc provider

func NewHTTPProviderFromConfig

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

NewHTTPProviderFromConfig creates a HTTP provider

func NewJavascriptProviderFromConfig

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

NewJavascriptProviderFromConfig creates a HTTP provider

func NewModbusFromConfig

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

NewModbusFromConfig creates Modbus plugin

func NewMqttFromConfig

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

NewMqttFromConfig creates Mqtt provider

func NewScriptProviderFromConfig

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

NewScriptProviderFromConfig creates a script provider.

func NewSocketProviderFromConfig

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

NewSocketProviderFromConfig creates a HTTP provider

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) 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 sends string 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() (float64, 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, payload string, scale float64, 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

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 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, jq string, cache time.Duration) (*Script, error)

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

func (*Script) BoolGetter

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

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

func (*Script) BoolSetter

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

BoolSetter invokes script with parameter replaced by bool value

func (*Script) FloatGetter

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

FloatGetter parses float from exec result

func (*Script) IntGetter

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

IntGetter parses int64 from exec result

func (*Script) IntSetter

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

IntSetter invokes script with parameter replaced by int value

func (*Script) StringGetter

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

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

type SetBoolProvider

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

provider types

type SetIntProvider

type SetIntProvider interface {
	IntSetter(param string) func(int64) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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