plugins

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: GPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// StateAwait ...
	StateAwait = "await"
	// StateOk ...
	StateOk = "ok"
	// StateError ...
	StateError = "error"
	// StateInProcess ...
	StateInProcess = "in process"
)

Variables

This section is empty.

Functions

func ToEntityActionShort

func ToEntityActionShort(from map[string]ActorAction) (to map[string]models.EntityActionShort)

ToEntityActionShort ...

func ToEntityStateShort

func ToEntityStateShort(from map[string]ActorState) (to map[string]models.EntityStateShort)

ToEntityStateShort ...

Types

type ActorAction

type ActorAction struct {
	Name         string                `json:"name"`
	Description  string                `json:"description"`
	ImageUrl     *string               `json:"image_url"`
	Icon         *string               `json:"icon"`
	ScriptEngine scripts.EngineWatcher `json:"-"`
}

ActorAction ...

type ActorConstructor

type ActorConstructor func(*models.Entity) (PluginActor, error)

ActorConstructor ...

type ActorInfo

type ActorInfo struct {
	Id                common.EntityId        `json:"id"`
	ParentId          *common.EntityId       `json:"parent_id"`
	PluginName        string                 `json:"plugin_name"`
	Name              string                 `json:"name"`
	Description       string                 `json:"description"`
	Hidde             bool                   `json:"hidde"`
	UnitOfMeasurement string                 `json:"unit_of_measurement"`
	LastChanged       *time.Time             `json:"last_changed"`
	LastUpdated       *time.Time             `json:"last_updated"`
	DependsOn         []string               `json:"depends_on"`
	State             *ActorState            `json:"state"`
	ImageUrl          *string                `json:"image_url"`
	Icon              *string                `json:"icon"`
	Area              *models.Area           `json:"area"`
	AutoLoad          bool                   `json:"auto_load"`
	RestoreState      bool                   `json:"restoreState"`
	Value             interface{}            `json:"value"`
	States            map[string]ActorState  `json:"states"`
	Actions           map[string]ActorAction `json:"actions"`
}

ActorInfo ...

type ActorState

type ActorState struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	ImageUrl    *string `json:"image_url"`
	Icon        *string `json:"icon"`
}

ActorState ...

func (*ActorState) Copy

func (a *ActorState) Copy() (state *ActorState)

Copy ...

type Authorization added in v0.21.1

type Authorization interface {
	AuthPlain(login, pass string) (*m.User, error)
	AuthREST(ctx context.Context, accessToken string, requestURI *url.URL, method string) (*m.User, bool, error)
}

type CallActionV2

type CallActionV2 struct {
	EntityId   *common.EntityId `json:"entity_id"`
	ActionName string           `json:"action_name"`
	Tags       []string         `json:"tags"`
	AreaId     *int64           `json:"area_id"`
}

type EntityStateParams

type EntityStateParams struct {
	NewState        *string          `json:"new_state"`
	AttributeValues m.AttributeValue `json:"attribute_values"`
	SettingsValue   m.AttributeValue `json:"settings_value"`
	StorageSave     bool             `json:"storage_save"`
}

EntityStateParams -> supervisor

type HttpAccessFilter added in v0.21.1

type HttpAccessFilter interface {
	Auth(next http.Handler) http.Handler
}

type Installable

type Installable interface {
	Install() error
	Uninstall() error
}

Installable ...

type Pluggable

type Pluggable interface {
	Load(context.Context, Service) error
	Unload(context.Context) error
	Name() string
	Depends() []string
	Version() string
	Options() models.PluginOptions
	EntityIsLoaded(id common.EntityId) bool
	GetActor(id common.EntityId) (pla PluginActor, err error)
	AddOrUpdateActor(*models.Entity) error
	RemoveActor(common.EntityId) error
	Readme(*string, *string) ([]byte, error)
}

Pluggable ...

type Plugin

type Plugin struct {
	Service   Service
	IsStarted *atomic.Bool
	Actors    *sync.Map

	F embed.FS
	// contains filtered or unexported fields
}

Plugin ...

func NewPlugin

func NewPlugin() *Plugin

NewPlugin ...

func (*Plugin) AddActor

func (p *Plugin) AddActor(pla PluginActor, entity *models.Entity) (err error)

func (*Plugin) AddOrUpdateActor

func (p *Plugin) AddOrUpdateActor(entity *models.Entity) (err error)

func (*Plugin) Check

func (p *Plugin) Check(msg events.EventCallEntityAction) (result []interface{}, ok bool)

func (*Plugin) Depends

func (p *Plugin) Depends() []string

Depends ...

func (*Plugin) EntityIsLoaded

func (p *Plugin) EntityIsLoaded(id pkgCommon.EntityId) bool

func (*Plugin) GetActor

func (p *Plugin) GetActor(id pkgCommon.EntityId) (pla PluginActor, err error)

func (*Plugin) Load

func (p *Plugin) Load(ctx context.Context, service Service, actorConstructor ActorConstructor) error

Load ...

func (*Plugin) LoadSettings

func (p *Plugin) LoadSettings(pl Pluggable) (settings models.Attributes, err error)

LoadSettings ...

func (*Plugin) Name

func (p *Plugin) Name() string

Name ...

func (*Plugin) Options

func (p *Plugin) Options() models.PluginOptions

Options ...

func (*Plugin) Readme

func (p *Plugin) Readme(note, lang *string) (result []byte, err error)

func (*Plugin) RemoveActor

func (p *Plugin) RemoveActor(entityId pkgCommon.EntityId) (err error)

func (*Plugin) Unload

func (p *Plugin) Unload(ctx context.Context) error

Unload ...

func (*Plugin) Version

func (p *Plugin) Version() string

Version ...

type PluginActor

type PluginActor interface {
	Spawn()
	Destroy()
	StopWatchers()
	Attributes() models.Attributes
	Settings() models.Attributes
	Metrics() []*models.Metric
	SetState(EntityStateParams) error
	Info() ActorInfo
	GetCurrentState() *events.EventEntityState
	GetOldState() *events.EventEntityState
	SetCurrentState(events.EventEntityState)
	GetEventState() events.EventEntityState
	AddMetric(name string, value map[string]interface{})
	MatchTags(tags []string) bool
	Area() *models.Area
	CallScript(fn string, arg ...interface{})
}

PluginActor ...

type PluginFileInfo

type PluginFileInfo struct {
	ModTime  time.Time
	Name     string
	MimeType string
	Size     int64
	IsDir    bool
	FileMode fs.FileMode
}

type PluginFileInfos

type PluginFileInfos []*PluginFileInfo

func (PluginFileInfos) Len

func (l PluginFileInfos) Len() int

func (PluginFileInfos) Less

func (l PluginFileInfos) Less(i, j int) bool

func (PluginFileInfos) Swap

func (l PluginFileInfos) Swap(i, j int)

type PluginInfo

type PluginInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Enabled bool   `json:"enabled"`
	System  bool   `json:"system"`
}

PluginInfo ...

type PluginManifest

type PluginManifest struct {
	Name        string                 `json:"name"`
	Version     string                 `json:"version"`
	Description string                 `json:"description"`
	Repository  string                 `json:"repository"`
	Plugin      string                 `json:"plugin"`
	Libs        []string               `json:"libs"`
	Assets      []string               `json:"assets"`
	Settings    map[string]interface{} `json:"settings"`
	Actor       bool                   `json:"actor"`
	Triggers    bool                   `json:"triggers"`
	OS          string                 `json:"os"`
	Arch        string                 `json:"arch"`
}

type Service

type Service interface {
	Plugins() map[string]Pluggable
	EventBus() bus.Bus
	Adaptors() *adaptors.Adaptors
	Supervisor() Supervisor
	ScriptService() scripts.ScriptService
	MqttServ() mqtt.MqttServ
	AppConfig() *models.AppConfig
	Scheduler() scheduler.Scheduler
	Crawler() web.Crawler
	Authorization() Authorization
	HttpAccessFilter() HttpAccessFilter
}

Service ...

type Supervisor

type Supervisor interface {
	Start(context.Context) error
	Shutdown(context.Context) error
	Restart(context.Context) error
	GetPlugin(name string) (interface{}, error)
	EnablePlugin(context.Context, string) error
	DisablePlugin(context.Context, string) error
	SetMetric(common.EntityId, string, map[string]interface{})
	SetState(common.EntityId, EntityStateParams) error
	GetActorById(common.EntityId) (PluginActor, error)
	CallAction(common.EntityId, string, map[string]interface{})
	CallScript(id common.EntityId, fn string, arg ...interface{})
	CallActionV2(CallActionV2, map[string]interface{})
	CallScene(common.EntityId, map[string]interface{})
	AddEntity(*models.Entity) error
	GetEntityById(common.EntityId) (models.EntityShort, error)
	UpdateEntity(*models.Entity) error
	UnloadEntity(common.EntityId)
	EntityIsLoaded(id common.EntityId) bool
	PluginIsLoaded(string) bool
	GetService() Service
	GetPluginReadme(context.Context, string, *string, *string) ([]byte, error)
	PushSystemEvent(strCommand string, params map[string]interface{})
	UploadPlugin(ctx context.Context, reader *bufio.Reader) (newFile *models.Plugin, err error)
	RemovePlugin(ctx context.Context, pluginName string) error
}

Supervisor ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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