supervisor

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: GPL-3.0 Imports: 26 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

This section is empty.

Functions

func CallActionBind

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

func CallActionV2Bind added in v0.17.0

func CallActionV2Bind(manager Supervisor) func(params CallActionV2, value map[string]interface{})

func CallSceneBind

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

func CallScriptBind added in v0.19.0

func CallScriptBind(manager Supervisor) func(entityId, fn string, arg ...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 PointInsideAreaBind added in v0.14.0

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

func PushSystemEvent added in v0.14.0

func PushSystemEvent(manager Supervisor) func(command string, params map[string]interface{})

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"`
	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 BaseActor

type BaseActor struct {
	PluginActor
	Id          common.EntityId
	ParentId    *common.EntityId
	Name        string
	Description string
	EntityType  string

	Metric            []*m.Metric
	Hidden            bool
	AttrMu            *sync.RWMutex
	Attrs             m.Attributes
	Actions           map[string]ActorAction
	States            map[string]ActorState
	ScriptsEngine     *scripts.EnginesWatcher
	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) Area

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

func (*BaseActor) Attributes

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

Attributes ...

func (*BaseActor) CallScript added in v0.19.0

func (e *BaseActor) CallScript(fn string, arg ...interface{})

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() *events.EventEntityState

func (*BaseActor) GetEventState

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

func (*BaseActor) GetOldState added in v0.15.0

func (e *BaseActor) GetOldState() *events.EventEntityState

func (*BaseActor) Info

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

Info ...

func (*BaseActor) MatchTags added in v0.17.0

func (e *BaseActor) MatchTags(tags []string) bool

func (*BaseActor) Metrics

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

Metrics ...

func (*BaseActor) Now

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

Now ...

func (*BaseActor) RestoreState added in v0.15.0

func (e *BaseActor) RestoreState(entity *m.Entity)

func (*BaseActor) SaveState

func (e *BaseActor) SaveState(doNotSaveMetric, storageSave bool)

func (*BaseActor) SetActorState added in v0.15.0

func (e *BaseActor) SetActorState(name *string)

SetActorState ...

func (*BaseActor) SetActorStateImage added in v0.15.0

func (e *BaseActor) SetActorStateImage(imageUrl, icon *string)

SetActorStateImage ...

func (*BaseActor) SetCurrentState

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

func (*BaseActor) SetState

func (e *BaseActor) SetState(EntityStateParams) error

SetState ...

func (*BaseActor) Settings

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

Settings ...

func (*BaseActor) Spawn added in v0.16.1

func (e *BaseActor) Spawn()

func (*BaseActor) StopWatchers

func (e *BaseActor) StopWatchers()

type CallActionV2 added in v0.17.0

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

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    events.EventEntityState
	NewState    events.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
	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 *m.Entity) (err error)

func (*Plugin) AddOrUpdateActor

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

func (*Plugin) Check added in v0.17.0

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 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) Readme added in v0.14.0

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

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() *events.EventEntityState
	GetOldState() *events.EventEntityState
	SetCurrentState(events.EventEntityState)
	GetEventState() events.EventEntityState
	AddMetric(name string, value map[string]interface{})
	MatchTags(tags []string) bool
	Area() *m.Area
	CallScript(fn string, arg ...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) (interface{}, 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{})
	CallScript(id common.EntityId, fn string, arg ...interface{})
	CallActionV2(CallActionV2, 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) bool
	PluginIsLoaded(string) bool
	GetService() Service
	GetPluginReadme(context.Context, string, *string, *string) ([]byte, error)
	PushSystemEvent(strCommand string, params map[string]interface{})
}

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