supervisor

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateAwait ...
	StateAwait = "await"
	// StateOk ...
	StateOk = "ok"
	// StateError ...
	StateError = "error"
	// StateInProcess ...
	StateInProcess = "in process"
)
View Source
const (
	// PluginBuiltIn ...
	PluginBuiltIn = PluginType("System")
	// PluginInstallable ...
	PluginInstallable = PluginType("Installable")
)

Variables

View Source
var (
	// ErrPluginIsLoaded ...
	ErrPluginIsLoaded = errors.New("plugin is loaded")
	// ErrPluginIsUnloaded ...
	ErrPluginIsUnloaded = errors.New("plugin is unloaded")
	// ErrPluginNotLoaded ...
	ErrPluginNotLoaded = errors.New("plugin not loaded")
)

Functions

func CallActionBind

func CallActionBind(manager Supervisor) func(entityId, action string, value map[string]interface{})

func CallSceneBind

func CallSceneBind(manager Supervisor) func(entityId string, value map[string]interface{})

func GetAttributesBind

func GetAttributesBind(manager Supervisor) func(entityId string) m.AttributeValue

func GetDistanceBetweenPointsBind

func GetDistanceBetweenPointsBind(adaptors *adaptors.Adaptors) func(point1, point2 m.Point) float64

func GetDistanceToAreaBind

func GetDistanceToAreaBind(adaptors *adaptors.Adaptors) func(areaId int64, point m.Point) float64

func GetEntityBind

func GetEntityBind(manager Supervisor) func(entityId string) *EntityBind

func GetSettingsBind

func GetSettingsBind(manager Supervisor) func(entityId string) m.AttributeValue

func GetStateBind

func GetStateBind(manager Supervisor) func(entityId string) *m.EntityStateShort

func NewEntity

func NewEntity(a PluginActor) m.EntityShort

NewEntity ...

func PointInsideAriaBind

func PointInsideAriaBind(adaptors *adaptors.Adaptors) func(areaId int64, point m.Point) bool

func RegisterPlugin

func RegisterPlugin(name string, new func() Pluggable)

RegisterPlugin ...

func SetAttributesBind

func SetAttributesBind(manager Supervisor) func(entityId string, params m.AttributeValue)

func SetMetricBind

func SetMetricBind(manager Supervisor) func(entityId, name string, value map[string]interface{})

func SetStateBind

func SetStateBind(manager Supervisor) func(entityId string, params EntityStateParams)

func SetStateNameBind

func SetStateNameBind(manager Supervisor) func(entityId, stateName string)

func ToEntityActionShort

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

ToEntityActionShort ...

func ToEntityStateShort

func ToEntityStateShort(from map[string]ActorState) (to map[string]m.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(*m.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              *m.Area                `json:"area"`
	AutoLoad          bool                   `json:"auto_load"`
	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 BaseActor

type BaseActor struct {
	PluginActor
	Id                common.EntityId
	ParentId          *common.EntityId
	Name              string
	Description       string
	EntityType        string
	State             *ActorState
	Area              *m.Area
	Metric            []*m.Metric
	Hidden            bool
	AttrMu            *sync.RWMutex
	Attrs             m.Attributes
	Actions           map[string]ActorAction
	States            map[string]ActorState
	ScriptEngines     []*scripts.EngineWatcher
	Icon              *string
	ImageUrl          *string
	UnitOfMeasurement string
	Scripts           []*m.Script
	Value             *atomic.String
	AutoLoad          bool
	LastChanged       *time.Time
	LastUpdated       *time.Time
	SettingsMu        *sync.RWMutex
	Setts             m.Attributes
	Service           Service
	// contains filtered or unexported fields
}

BaseActor ...

func NewBaseActor

func NewBaseActor(entity *m.Entity,
	service Service) BaseActor

NewBaseActor ...

func (*BaseActor) AddMetric

func (e *BaseActor) AddMetric(name string, value map[string]interface{})

func (*BaseActor) Attributes

func (e *BaseActor) Attributes() m.Attributes

Attributes ...

func (*BaseActor) DeserializeAttr

func (e *BaseActor) DeserializeAttr(data m.AttributeValue)

DeserializeAttr ...

func (*BaseActor) DeserializeSettings

func (e *BaseActor) DeserializeSettings(settings m.AttributeValue)

DeserializeSettings ...

func (*BaseActor) GetCurrentState

func (e *BaseActor) GetCurrentState() *bus.EventEntityState

func (*BaseActor) GetEventState

func (e *BaseActor) GetEventState() (eventState bus.EventEntityState)

func (*BaseActor) Info

func (e *BaseActor) Info() (info ActorInfo)

Info ...

func (*BaseActor) Metrics

func (e *BaseActor) Metrics() []*m.Metric

Metrics ...

func (*BaseActor) Now

func (e *BaseActor) Now(oldState bus.EventEntityState) time.Time

Now ...

func (*BaseActor) SaveState

func (e *BaseActor) SaveState(msg events.EventStateChanged)

func (*BaseActor) SetCurrentState

func (e *BaseActor) SetCurrentState(state bus.EventEntityState)

func (*BaseActor) SetState

func (e *BaseActor) SetState(EntityStateParams) error

SetState ...

func (*BaseActor) Settings

func (e *BaseActor) Settings() m.Attributes

Settings ...

func (*BaseActor) StopWatchers

func (e *BaseActor) StopWatchers()

type EntityBind

type EntityBind struct {
	m.EntityShort
	// contains filtered or unexported fields
}

EntityBind ...

func NewEntityBind

func NewEntityBind(id common.EntityId, manager Supervisor) *EntityBind

NewEntityBind ...

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 Installable

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

Installable ...

type MessageStateChanged

type MessageStateChanged struct {
	StorageSave bool
	OldState    bus.EventEntityState
	NewState    bus.EventEntityState
}

MessageStateChanged -> supervisor

type Pluggable

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

Pluggable ...

type Plugin

type Plugin struct {
	Service   Service
	IsStarted *atomic.Bool
	Actors    *sync.Map
	// contains filtered or unexported fields
}

Plugin ...

func NewPlugin

func NewPlugin() *Plugin

NewPlugin ...

func (*Plugin) AddActor

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

func (*Plugin) AddOrUpdateActor

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

func (*Plugin) Depends

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

Depends ...

func (*Plugin) EntityIsLoaded

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

func (*Plugin) GetActor

func (p *Plugin) GetActor(id common.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 m.Attributes, err error)

LoadSettings ...

func (*Plugin) Name

func (p *Plugin) Name() string

Name ...

func (*Plugin) Options

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

Options ...

func (*Plugin) RemoveActor

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

func (*Plugin) Type

func (p *Plugin) Type() PluginType

Type ...

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() m.Attributes
	Settings() m.Attributes
	Metrics() []*m.Metric
	SetState(EntityStateParams) error
	Info() ActorInfo
	GetCurrentState() *bus.EventEntityState
	SetCurrentState(bus.EventEntityState)
	GetEventState() (eventState bus.EventEntityState)
	AddMetric(name string, value map[string]interface{})
}

PluginActor ...

type PluginInfo

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

PluginInfo ...

type PluginType

type PluginType string

PluginType ...

type Service

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

Service ...

type Supervisor

type Supervisor interface {
	Start(context.Context) error
	Shutdown(context.Context) error
	Restart(context.Context) error
	GetPlugin(name string) (plugin interface{}, err error)
	EnablePlugin(context.Context, string) error
	DisablePlugin(context.Context, string) error
	PluginList() (list []PluginInfo, total int64, err 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{})
	CallScene(common.EntityId, map[string]interface{})
	AddEntity(*m.Entity) error
	GetEntityById(common.EntityId) (m.EntityShort, error)
	UpdateEntity(*m.Entity) error
	UnloadEntity(common.EntityId)
	EntityIsLoaded(id common.EntityId) (loaded bool)
	PluginIsLoaded(name string) (loaded bool)
	GetService() Service
}

Supervisor ...

func NewSupervisor

func NewSupervisor(lc fx.Lifecycle,
	adaptors *adaptors.Adaptors,
	bus bus.Bus,
	mqttServ mqtt.MqttServ,
	scriptService scripts.ScriptService,
	appConfig *m.AppConfig,
	eventBus bus.Bus,
	scheduler *scheduler.Scheduler,
	crawler web.Crawler) Supervisor

NewSupervisor ...

Jump to

Keyboard shortcuts

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