entity_manager

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

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 GetEventState

func GetEventState(actor PluginActor) (eventState bus.EventEntityState)

GetEventState ...

func NewEntity

func NewEntity(a PluginActor) m.EntityShort

NewEntity ...

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.Engine `json:"-"`
}

ActorAction ...

type ActorConstructor

type ActorConstructor func() PluginActor

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
	Manager           EntityManager
	State             *ActorState
	Area              *m.Area
	Metric            []*m.Metric
	Hidden            bool
	AttrMu            *sync.RWMutex
	Attrs             m.Attributes
	Actions           map[string]ActorAction
	States            map[string]ActorState
	ScriptEngine      *scripts.Engine
	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
	// contains filtered or unexported fields
}

BaseActor ...

func NewBaseActor

func NewBaseActor(entity *m.Entity,
	scriptService scripts.ScriptService,
	adaptors *adaptors.Adaptors) BaseActor

NewBaseActor ...

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

func (b *BaseActor) GetEventState(actor PluginActor) bus.EventEntityState

GetEventState ...

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

func (e *BaseActor) SetMetric(id common.EntityId, name string, value map[string]float32)

SetMetric ...

func (*BaseActor) SetState

func (e *BaseActor) SetState(EntityStateParams) error

SetState ...

func (*BaseActor) Settings

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

Settings ...

type CrudActor

type CrudActor interface {
	AddOrUpdateActor(*m.Entity) error
	RemoveActor(common.EntityId) error
}

CrudActor ...

type EntityBind

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

EntityBind ...

func NewEntityBind

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

NewEntityBind ...

func (*EntityBind) CallAction

func (e *EntityBind) CallAction(action string, arg map[string]interface{})

CallAction ...

func (*EntityBind) GetAttributes

func (e *EntityBind) GetAttributes() m.AttributeValue

GetAttributes ...

func (*EntityBind) GetSettings added in v0.6.0

func (e *EntityBind) GetSettings() m.AttributeValue

GetSettings ...

func (*EntityBind) SetAttributes

func (e *EntityBind) SetAttributes(params m.AttributeValue)

SetAttributes ...

func (*EntityBind) SetMetric

func (e *EntityBind) SetMetric(name string, value map[string]float32)

SetMetric ...

func (*EntityBind) SetState

func (e *EntityBind) SetState(stateName string)

SetState ...

type EntityManager

type EntityManager interface {

	// SetPluginManager ...
	SetPluginManager(pluginManager common.PluginManager)

	// LoadEntities ...
	LoadEntities()

	// Shutdown ...
	Shutdown()

	// SetMetric ...
	SetMetric(common.EntityId, string, map[string]float32)

	// SetState ...
	SetState(common.EntityId, EntityStateParams) error

	// GetEntityById ...
	GetEntityById(common.EntityId) (m.EntityShort, error)

	// GetActorById ...
	GetActorById(common.EntityId) (PluginActor, error)

	// List ...
	List() ([]m.EntityShort, error)

	// Spawn ...
	Spawn(ActorConstructor) PluginActor

	// Remove ...
	Remove(common.EntityId)

	// CallAction ...
	CallAction(common.EntityId, string, map[string]interface{})

	// CallScene ...
	CallScene(common.EntityId, map[string]interface{})

	// Add ...
	Add(*m.Entity) error

	// Update ...
	Update(*m.Entity) error
}

EntityManager ...

func NewEntityManager

func NewEntityManager(lc fx.Lifecycle,
	eventBus bus.Bus,
	adaptors *adaptors.Adaptors,
	scripts scripts.ScriptService) EntityManager

NewEntityManager ...

type EntityManagerBind

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

EntityManagerBind ...

func NewEntityManagerBind

func NewEntityManagerBind(manager EntityManager) *EntityManagerBind

NewEntityManagerBind ...

func (*EntityManagerBind) CallAction

func (e *EntityManagerBind) CallAction(id common.EntityId, action string, arg map[string]interface{})

CallAction ...

func (*EntityManagerBind) CallScene added in v0.8.3

func (e *EntityManagerBind) CallScene(id common.EntityId, arg map[string]interface{})

CallScene ...

func (*EntityManagerBind) GetEntity

func (e *EntityManagerBind) GetEntity(id common.EntityId) *EntityBind

GetEntity ...

func (*EntityManagerBind) SetAttribute

func (e *EntityManagerBind) SetAttribute(id common.EntityId, params m.AttributeValue)

SetAttribute ...

func (*EntityManagerBind) SetMetric

func (e *EntityManagerBind) SetMetric(id common.EntityId, name string, value map[string]float32)

SetMetric ...

func (*EntityManagerBind) SetState

func (e *EntityManagerBind) SetState(id common.EntityId, stateName string)

SetState ...

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

type Message

type Message struct {
	From    common.EntityId
	To      common.EntityId
	Payload interface{}
}

Message ...

type MessageStateChanged

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

MessageStateChanged -> entityManager

type PluginActor

type PluginActor interface {

	// Spawn ...
	Spawn() PluginActor

	// Attributes ...
	Attributes() m.Attributes

	// Settings ...
	Settings() m.Attributes

	// Metrics ...
	Metrics() []*m.Metric

	// SetState ...
	SetState(EntityStateParams) error

	// Info ...
	Info() ActorInfo
}

PluginActor ...

type ScriptBind

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

ScriptBind ...

func NewScriptBind

func NewScriptBind(actor PluginActor) *ScriptBind

NewScriptBind ...

func (*ScriptBind) GetSettings added in v0.9.4

func (s *ScriptBind) GetSettings() map[string]interface{}

GetSettings ...

func (*ScriptBind) SetAttribute added in v0.9.4

func (s *ScriptBind) SetAttribute(params m.AttributeValue)

SetAttribute ...

func (*ScriptBind) SetState

func (s *ScriptBind) SetState(params EntityStateParams)

SetState ...

Jump to

Keyboard shortcuts

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