diff --git a/endpoint/common.go b/endpoint/common.go
index d2f08ff77..d7845698f 100644
--- a/endpoint/common.go
+++ b/endpoint/common.go
@@ -19,9 +19,6 @@
package endpoint
import (
- "fmt"
- "time"
-
"github.com/e154/smart-home/adaptors"
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/system/access_list"
@@ -65,7 +62,7 @@ func NewCommonEndpoint(adaptors *adaptors.Adaptors,
appConfig *m.AppConfig,
automation automation.Automation,
) *CommonEndpoint {
- cache, _ := cache.NewCache("memory", fmt.Sprintf(`{"interval":%d}`, time.Second*60))
+ cache, _ := cache.NewCache("memory", `{"interval":60}`)
return &CommonEndpoint{
adaptors: adaptors,
accessList: accessList,
diff --git a/models/image.go b/models/image.go
index d05702bee..93822b188 100644
--- a/models/image.go
+++ b/models/image.go
@@ -71,7 +71,7 @@ func UploadImage(ctx context.Context, reader *bufio.Reader, fileName string) (ne
}
contentType := http.DetectContentType(buffer.Bytes())
- log.Infof("Content-type from buffer, %s", contentType)
+ //log.Infof("Content-type from buffer, %s", contentType)
//------
// rename & save
diff --git a/plugins/uptime/plugin.go b/plugins/uptime/plugin.go
index c337ecdb0..cbcb50387 100644
--- a/plugins/uptime/plugin.go
+++ b/plugins/uptime/plugin.go
@@ -88,6 +88,14 @@ func (p *plugin) Load(ctx context.Context, service supervisor.Service) (err erro
p.ticker = time.NewTicker(time.Second * pause)
for range p.ticker.C {
+
+ if p.storyModel != nil {
+ p.storyModel.End = common.Time(time.Now())
+ if err = p.Service.Adaptors().RunHistory.Update(context.Background(), p.storyModel); err != nil {
+ log.Error(err.Error())
+ }
+ }
+
p.Actors.Range(func(key, value any) bool {
actor, _ := value.(*Actor)
actor.update()
diff --git a/static_source/admin/src/locales/en.ts b/static_source/admin/src/locales/en.ts
index f76ab89e0..8a7917639 100644
--- a/static_source/admin/src/locales/en.ts
+++ b/static_source/admin/src/locales/en.ts
@@ -540,6 +540,7 @@ export default {
COLOR_PICKER: 'Color Picker',
STREAM_PLAYER: 'Video player',
JOYSTICK: 'Joystick',
+ ICON: 'Icon',
tooltip: 'Tooltip',
slider: {
options: 'Slider Options',
@@ -591,6 +592,7 @@ export default {
entities: 'Entities',
showFilter: 'Show Filter'
},
+ iconOptions: 'Icon Options',
defaultIcon: 'Default Icon',
iconSize: 'Icon Size',
iconColor: 'Icon Color'
diff --git a/static_source/admin/src/locales/ru.ts b/static_source/admin/src/locales/ru.ts
index fc73755d0..ebdb3ee41 100644
--- a/static_source/admin/src/locales/ru.ts
+++ b/static_source/admin/src/locales/ru.ts
@@ -539,6 +539,7 @@ export default {
COLOR_PICKER: 'Цветовая паллитра',
STREAM_PLAYER: 'Video player',
JOYSTICK: 'Joystick',
+ ICON: 'Икона',
tooltip: 'Подсказка',
slider: {
options: 'Параметры слайдера',
@@ -590,10 +591,11 @@ export default {
entities: 'Устройства',
showFilter: 'Показывать фильтры'
},
- defaultIcon: 'Default Icon',
- iconSize: 'Icon Size',
- iconColor: 'Icon Color'
- },
+ iconOptions: 'Параметры Иконки',
+ defaultIcon: 'Иконка по умолчанию',
+ iconSize: 'Размер Иконки',
+ iconColor: 'Цвет Иконки'
+ }
},
settings: {
dashboardOptions: 'Настройки панели',
diff --git a/static_source/admin/src/views/Dashboard/card_items/icon/editor.vue b/static_source/admin/src/views/Dashboard/card_items/icon/editor.vue
new file mode 100644
index 000000000..b1939382b
--- /dev/null
+++ b/static_source/admin/src/views/Dashboard/card_items/icon/editor.vue
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+ {{ $t('dashboard.editor.iconOptions') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('dashboard.editor.getEvent') }}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/static_source/admin/src/views/Dashboard/card_items/icon/index.vue b/static_source/admin/src/views/Dashboard/card_items/icon/index.vue
new file mode 100644
index 000000000..2198de2bf
--- /dev/null
+++ b/static_source/admin/src/views/Dashboard/card_items/icon/index.vue
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/static_source/admin/src/views/Dashboard/card_items/icon/types.ts b/static_source/admin/src/views/Dashboard/card_items/icon/types.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/static_source/admin/src/views/Dashboard/card_items/index.ts b/static_source/admin/src/views/Dashboard/card_items/index.ts
index 152fbfdc0..fadd20c50 100644
--- a/static_source/admin/src/views/Dashboard/card_items/index.ts
+++ b/static_source/admin/src/views/Dashboard/card_items/index.ts
@@ -26,6 +26,8 @@ import streamPlayer from './video/index.vue';
import streamPlayerEditor from './video/editor.vue';
import joystick from './joystick/index.vue';
import joystickEditor from './joystick/editor.vue';
+import icon from './icon/index.vue';
+import iconEditor from './icon/editor.vue';
export const CardItemName = (name: string): any => {
switch (name) {
@@ -55,6 +57,8 @@ export const CardItemName = (name: string): any => {
return streamPlayer;
case 'joystick':
return joystick;
+ case 'icon':
+ return icon;
default:
// console.error(`unknown card name "${name}"`);
return dummy;
@@ -89,6 +93,8 @@ export const CardEditorName = (name: string): any => {
return streamPlayerEditor;
case 'joystick':
return joystickEditor;
+ case 'icon':
+ return iconEditor;
default:
// console.error(`unknown card name "${name}"`);
return dummyEditor;
@@ -113,5 +119,6 @@ export const CardItemList: ItemsType[] = [
{label: 'SLIDER', value: 'slider'},
{label: 'COLOR_PICKER', value: 'colorPicker'},
{label: 'STREAM_PLAYER', value: 'streamPlayer'},
- {label: 'JOYSTICK', value: 'joystick'}
+ {label: 'JOYSTICK', value: 'joystick'},
+ {label: 'ICON', value: 'icon'}
];
diff --git a/static_source/admin/src/views/Dashboard/core.ts b/static_source/admin/src/views/Dashboard/core.ts
index 23caba37f..92fd7183b 100644
--- a/static_source/admin/src/views/Dashboard/core.ts
+++ b/static_source/admin/src/views/Dashboard/core.ts
@@ -86,10 +86,18 @@ export interface ItemPayloadImage {
image?: ApiImage;
}
+export interface ItemPayloadIcon {
+ attrField?: string;
+ value?: string;
+ iconColor?: string;
+ iconSize?: number;
+}
+
//todo: shouldn't be here, so will be optimize!!!
export interface ItemPayload {
text?: ItemPayloadText;
image?: ItemPayloadImage;
+ icon?: ItemPayloadIcon;
button?: ItemPayloadButton;
state?: ItemPayloadState;
logs?: ItemPayloadLogs;
@@ -196,6 +204,13 @@ export class CardItem {
attrField: ''
} as ItemPayloadImage;
}
+ if (!this.payload.icon) {
+ this.payload.icon = {
+ value: '',
+ iconColor: '#000000',
+ iconSize: 12
+ } as ItemPayloadIcon;
+ }
if (this.payload.image.attrField == undefined) {
this.payload.image.attrField = '';
}
diff --git a/system/automation/action.go b/system/automation/action.go
index 71b257659..0b10ebdde 100644
--- a/system/automation/action.go
+++ b/system/automation/action.go
@@ -22,13 +22,11 @@ import (
"fmt"
"sync"
- "github.com/e154/smart-home/common/events"
- "github.com/e154/smart-home/system/bus"
-
"github.com/e154/smart-home/common"
+ "github.com/e154/smart-home/common/events"
m "github.com/e154/smart-home/models"
+ "github.com/e154/smart-home/system/bus"
"github.com/e154/smart-home/system/scripts"
- "go.uber.org/atomic"
)
// ActionFunc ...
@@ -40,7 +38,6 @@ type Action struct {
scriptService scripts.ScriptService
eventBus bus.Bus
scriptEngine *scripts.EngineWatcher
- inProcess atomic.Bool
sync.Mutex
}
diff --git a/system/automation/condition.go b/system/automation/condition.go
index 24ab3588c..c44e8c53b 100644
--- a/system/automation/condition.go
+++ b/system/automation/condition.go
@@ -21,9 +21,10 @@ package automation
import (
"context"
+ "go.uber.org/atomic"
+
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/system/scripts"
- "go.uber.org/atomic"
)
// NewCondition ...
@@ -44,8 +45,7 @@ func NewCondition(scriptService scripts.ScriptService,
condition = &Condition{
model: model,
- inProcess: atomic.Bool{},
- lastStatus: atomic.Bool{},
+ lastStatus: atomic.NewBool(false),
scriptEngine: scriptEngine,
}
@@ -55,8 +55,7 @@ func NewCondition(scriptService scripts.ScriptService,
// Condition ...
type Condition struct {
model *m.Condition
- inProcess atomic.Bool
- lastStatus atomic.Bool
+ lastStatus *atomic.Bool
scriptEngine *scripts.EngineWatcher
}
diff --git a/system/automation/condition_group.go b/system/automation/condition_group.go
index 7ac305bd2..18781bb30 100644
--- a/system/automation/condition_group.go
+++ b/system/automation/condition_group.go
@@ -32,7 +32,7 @@ import (
func NewConditionGroup(t common.ConditionType) *ConditionGroup {
return &ConditionGroup{
t: t,
- lastStatus: atomic.Bool{},
+ lastStatus: atomic.NewBool(false),
Mutex: sync.Mutex{},
}
}
@@ -41,7 +41,7 @@ func NewConditionGroup(t common.ConditionType) *ConditionGroup {
type ConditionGroup struct {
rules []*Condition
t common.ConditionType
- lastStatus atomic.Bool
+ lastStatus *atomic.Bool
sync.Mutex
}
@@ -70,14 +70,12 @@ func (c *ConditionGroup) Check(entityId *common.EntityId) (state bool, err error
return
}
- wg := sync.WaitGroup{}
+ wg := &sync.WaitGroup{}
wg.Add(total)
for _, r := range c.rules {
go func(condition *Condition) {
- defer func() {
- wg.Done()
- }()
+ defer wg.Done()
bg, _ := context.WithTimeout(context.Background(), time.Second)
ctx := context.WithValue(bg, "entityId", entityId)
if _, err = condition.Check(ctx); err != nil {
diff --git a/system/automation/task.go b/system/automation/task.go
index 76edaea1d..abcf13249 100644
--- a/system/automation/task.go
+++ b/system/automation/task.go
@@ -38,7 +38,7 @@ type Task struct {
eventBus bus.Bus
conditionGroup *ConditionGroup
script *scripts.Engine
- enabled atomic.Bool
+ enabled *atomic.Bool
scriptService scripts.ScriptService
actionsMx sync.Mutex
actions map[int64]*Action
@@ -53,7 +53,7 @@ func NewTask(eventBus bus.Bus,
return &Task{
model: model,
eventBus: eventBus,
- enabled: atomic.Bool{},
+ enabled: atomic.NewBool(false),
scriptService: scriptService,
actions: make(map[int64]*Action),
}
diff --git a/system/automation/trigger.go b/system/automation/trigger.go
index 3200b2e40..04737d94e 100644
--- a/system/automation/trigger.go
+++ b/system/automation/trigger.go
@@ -39,11 +39,10 @@ import (
type Trigger struct {
scriptEngine *scripts.EngineWatcher
scriptService scripts.ScriptService
- lastStatus atomic.Bool
+ lastStatus *atomic.Bool
model *m.Trigger
name string
triggerPlugin triggers.ITrigger
- isStarted atomic.Bool
taskName string
subscriber triggers.Subscriber
eventBus bus.Bus
@@ -74,6 +73,7 @@ func NewTrigger(
scriptService: scriptService,
triggerPlugin: triggerPlugin,
eventBus: eventBus,
+ lastStatus: atomic.NewBool(false),
}
tr.subscriber = triggers.Subscriber{
diff --git a/system/automation/trigger_manager.go b/system/automation/trigger_manager.go
index e53ea6818..26f35da14 100644
--- a/system/automation/trigger_manager.go
+++ b/system/automation/trigger_manager.go
@@ -42,7 +42,7 @@ type triggerManager struct {
adaptors *adaptors.Adaptors
isStarted *atomic.Bool
rawPlugin triggers.IGetTrigger
- triggerCounter atomic.Uint64
+ triggerCounter *atomic.Uint64
sync.Mutex
triggers map[int64]*Trigger
}
@@ -52,12 +52,13 @@ func NewTriggerManager(eventBus bus.Bus,
sup supervisor.Supervisor,
adaptors *adaptors.Adaptors) (manager *triggerManager) {
manager = &triggerManager{
- eventBus: eventBus,
- scriptService: scriptService,
- supervisor: sup,
- adaptors: adaptors,
- isStarted: atomic.NewBool(false),
- triggers: make(map[int64]*Trigger),
+ eventBus: eventBus,
+ scriptService: scriptService,
+ supervisor: sup,
+ adaptors: adaptors,
+ isStarted: atomic.NewBool(false),
+ triggers: make(map[int64]*Trigger),
+ triggerCounter: atomic.NewUint64(0),
}
return
}
@@ -157,7 +158,7 @@ func (a *triggerManager) addTrigger(model *m.Trigger) (err error) {
defer func() {
if err == nil {
- a.triggerCounter.Inc()
+ a.triggerCounter.Inc()
}
}()
diff --git a/system/backup/backup.go b/system/backup/backup.go
index c9cdefa75..386577055 100644
--- a/system/backup/backup.go
+++ b/system/backup/backup.go
@@ -57,8 +57,8 @@ type Backup struct {
cfg *Config
eventBus bus.Bus
restoreImage string
- inProcess atomic.Bool
- sendInProcess atomic.Bool
+ inProcess *atomic.Bool
+ sendInProcess *atomic.Bool
}
// NewBackup ...
@@ -69,8 +69,10 @@ func NewBackup(lc fx.Lifecycle, eventBus bus.Bus, cfg *Config) *Backup {
}
backup := &Backup{
- cfg: cfg,
- eventBus: eventBus,
+ cfg: cfg,
+ eventBus: eventBus,
+ inProcess: atomic.NewBool(false),
+ sendInProcess: atomic.NewBool(false),
}
lc.Append(fx.Hook{
diff --git a/system/mqtt_authenticator/mqtt_authenticator.go b/system/mqtt_authenticator/mqtt_authenticator.go
index 904100aac..58bf8cc38 100644
--- a/system/mqtt_authenticator/mqtt_authenticator.go
+++ b/system/mqtt_authenticator/mqtt_authenticator.go
@@ -57,7 +57,7 @@ type Authenticator struct {
// NewAuthenticator ...
func NewAuthenticator(adaptors *adaptors.Adaptors) MqttAuthenticator {
- bm, _ := cache.NewCache("memory", fmt.Sprintf(`{"interval":%d}`, time.Second*60))
+ bm, _ := cache.NewCache("memory", `{"interval":60}`)
return &Authenticator{
adaptors: adaptors,
cache: bm,
diff --git a/system/scripts/javascript.go b/system/scripts/javascript.go
index 79f92434e..aa57d809e 100644
--- a/system/scripts/javascript.go
+++ b/system/scripts/javascript.go
@@ -315,8 +315,8 @@ func (j *Javascript) unsafeRun(program *goja.Program) (result string, err error)
wg.Add(1)
j.loop.Run(func(vm *goja.Runtime) {
+ defer wg.Done()
value, err = vm.RunProgram(program)
- wg.Done()
})
wg.Wait()
diff --git a/system/stream/stream.go b/system/stream/stream.go
index 4ca66b9e4..5501f0318 100644
--- a/system/stream/stream.go
+++ b/system/stream/stream.go
@@ -113,9 +113,7 @@ func (s *Stream) Shutdown(_ context.Context) error {
func (s *Stream) Broadcast(query string, message []byte) {
s.sessions.Range(func(key, value interface{}) bool {
cli := value.(*Client)
- go func() {
- _ = cli.Send(uuid.NewString(), query, message)
- }()
+ _ = cli.Send(uuid.NewString(), query, message)
return true
})
}
@@ -127,9 +125,7 @@ func (s *Stream) DirectMessage(userID int64, query string, message []byte) {
if userID != 0 && cli.user.Id != userID {
return true
}
- go func() {
- _ = cli.Send(uuid.NewString(), query, message)
- }()
+ _ = cli.Send(uuid.NewString(), query, message)
return true
})
}
diff --git a/system/supervisor/supervisor.go b/system/supervisor/supervisor.go
index fbd3a37fc..5a5fc4772 100644
--- a/system/supervisor/supervisor.go
+++ b/system/supervisor/supervisor.go
@@ -20,7 +20,6 @@ package supervisor
import (
"context"
- "fmt"
"runtime/debug"
"sync"
"time"
@@ -50,7 +49,6 @@ var (
type supervisor struct {
*pluginManager
scriptService scripts.ScriptService
- entitiesWg *sync.WaitGroup
eventScriptSubsMx sync.RWMutex
eventScriptSubs map[int64]map[common.EntityId]struct{}
cache cache.Cache
@@ -69,10 +67,9 @@ func NewSupervisor(lc fx.Lifecycle,
crawler web.Crawler) Supervisor {
s := &supervisor{
scriptService: scriptService,
- entitiesWg: &sync.WaitGroup{},
eventScriptSubs: make(map[int64]map[common.EntityId]struct{}),
}
- s.cache, _ = cache.NewCache("memory", fmt.Sprintf(`{"interval":%d}`, time.Second*60))
+ s.cache, _ = cache.NewCache("memory", `{"interval":60}`)
s.pluginManager = &pluginManager{
adaptors: adaptors,
isStarted: atomic.NewBool(false),
@@ -125,7 +122,6 @@ func (e *supervisor) Start(ctx context.Context) (err error) {
func (e *supervisor) Shutdown(ctx context.Context) (err error) {
e.pluginManager.Shutdown(ctx)
- e.entitiesWg.Wait()
e.scriptService.PopFunction("GetEntity")
e.scriptService.PopFunction("SetState")
diff --git a/system/zigbee2mqtt/zigbee2mqtt.go b/system/zigbee2mqtt/zigbee2mqtt.go
index 90d3785af..3a8452831 100644
--- a/system/zigbee2mqtt/zigbee2mqtt.go
+++ b/system/zigbee2mqtt/zigbee2mqtt.go
@@ -45,7 +45,7 @@ var (
type zigbee2mqtt struct {
mqtt mqtt.MqttServ
adaptors *adaptors.Adaptors
- isStarted atomic.Bool
+ isStarted *atomic.Bool
bridgesLock *sync.Mutex
bridges map[int64]*Bridge
eventBus bus.Bus
@@ -62,6 +62,7 @@ func NewZigbee2mqtt(lc fx.Lifecycle,
bridgesLock: &sync.Mutex{},
bridges: make(map[int64]*Bridge),
eventBus: eventBus,
+ isStarted: atomic.NewBool(false),
}
lc.Append(fx.Hook{