Skip to content

Commit

Permalink
technical debt
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 committed Nov 28, 2023
1 parent 3130c60 commit 3505174
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 56 deletions.
5 changes: 1 addition & 4 deletions endpoint/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion models/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions plugins/uptime/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions static_source/admin/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ export default {
COLOR_PICKER: 'Color Picker',
STREAM_PLAYER: 'Video player',
JOYSTICK: 'Joystick',
ICON: 'Icon',
tooltip: 'Tooltip',
slider: {
options: 'Slider Options',
Expand Down Expand Up @@ -591,6 +592,7 @@ export default {
entities: 'Entities',
showFilter: 'Show Filter'
},
iconOptions: 'Icon Options',
defaultIcon: 'Default Icon',
iconSize: 'Icon Size',
iconColor: 'Icon Color'
Expand Down
10 changes: 6 additions & 4 deletions static_source/admin/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ export default {
COLOR_PICKER: 'Цветовая паллитра',
STREAM_PLAYER: 'Video player',
JOYSTICK: 'Joystick',
ICON: 'Икона',
tooltip: 'Подсказка',
slider: {
options: 'Параметры слайдера',
Expand Down Expand Up @@ -590,10 +591,11 @@ export default {
entities: 'Устройства',
showFilter: 'Показывать фильтры'
},
defaultIcon: 'Default Icon',
iconSize: 'Icon Size',
iconColor: 'Icon Color'
},
iconOptions: 'Параметры Иконки',
defaultIcon: 'Иконка по умолчанию',
iconSize: 'Размер Иконки',
iconColor: 'Цвет Иконки'
}
},
settings: {
dashboardOptions: 'Настройки панели',
Expand Down
96 changes: 96 additions & 0 deletions static_source/admin/src/views/Dashboard/card_items/icon/editor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<script setup lang="ts">
import {computed, onMounted, PropType, ref, unref, watch} from "vue";
import {Card, CardItem, comparisonType, Core, requestCurrentState, Tab} from "@/views/Dashboard/core";
import ViewCard from "@/views/Dashboard/editor/ViewCard.vue";
import {ElDivider, ElCollapse, ElCollapseItem, ElCard, ElForm, ElFormItem, ElPopconfirm, ElSwitch,
ElRow, ElCol, ElSelect, ElOption, ElInput, ElTag, ElButton, ElColorPicker, ElInputNumber } from 'element-plus'
import CommonEditor from "@/views/Dashboard/card_items/common/editor.vue";
import {useI18n} from "@/hooks/web/useI18n";
import {Cache, GetTokens} from "@/views/Dashboard/render";
import Viewer from "@/components/JsonViewer/JsonViewer.vue";
const {t} = useI18n()
// ---------------------------------
// common
// ---------------------------------
const _cache: Cache = new Cache();
const props = defineProps({
core: {
type: Object as PropType<Core>,
},
item: {
type: Object as PropType<Nullable<CardItem>>,
default: () => null
},
})
const currentItem = computed({
get(): CardItem {
return props.item as CardItem
},
set(val: CardItem) {}
})
// ---------------------------------
// component methods
// ---------------------------------
const updateCurrentState = () => {
if (currentItem.value.entityId) {
requestCurrentState(currentItem.value?.entityId)
}
}
</script>

<template>

<CommonEditor :item="currentItem" :core="core"/>

<ElDivider content-position="left">{{ $t('dashboard.editor.iconOptions') }}</ElDivider>

<ElRow :gutter="24">
<ElCol :span="8" :xs="8">
<ElFormItem :label="$t('dashboard.editor.icon')" prop="icon">
<ElInput v-model="currentItem.payload.icon.value" />
</ElFormItem>
</ElCol>
<ElCol :span="8" :xs="8">
<ElFormItem :label="$t('dashboard.editor.iconColor')" prop="iconColor">
<ElColorPicker show-alpha v-model="currentItem.payload.icon.iconColor"/>
</ElFormItem>
</ElCol>
<ElCol :span="8" :xs="8">
<ElFormItem :label="$t('dashboard.editor.iconSize')" prop="iconSize">
<ElInputNumber size="small" v-model="currentItem.payload.icon.iconSize" :min="1" :value-on-clear="12"/>
</ElFormItem>
</ElCol>
</ElRow>

<ElFormItem :label="$t('dashboard.editor.attrField')" prop="text">
<ElInput size="small" v-model="currentItem.payload.icon.attrField"/>
</ElFormItem>

<ElRow style="padding-bottom: 20px" v-if="currentItem.entity">
<ElCol>
<ElCollapse>
<ElCollapseItem :title="$t('dashboard.editor.eventstateJSONobject')">
<ElButton type="default" @click.prevent.stop="updateCurrentState()" style="margin-bottom: 20px">
<Icon icon="ep:refresh" class="mr-5px"/>
{{ $t('dashboard.editor.getEvent') }}
</ElButton>

<Viewer v-model="currentItem.lastEvent"/>

</ElCollapseItem>
</ElCollapse>
</ElCol>
</ElRow>

</template>

<style lang="less" >
</style>
95 changes: 95 additions & 0 deletions static_source/admin/src/views/Dashboard/card_items/icon/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<script setup lang="ts">
import {computed, onMounted, onUnmounted, PropType, ref, unref, watch} from "vue";
import {ButtonAction, Card, CardItem, Core, requestCurrentState, Tab} from "@/views/Dashboard/core";
import {Cache, Compare, GetTokens, RenderText, Resolve} from "@/views/Dashboard/render";
import {ElImage, ElIcon} from "element-plus";
import { Picture as IconPicture } from '@element-plus/icons-vue'
import {Attribute, GetAttrValue} from "@/api/stream_types";
import {debounce} from "lodash-es";
// ---------------------------------
// common
// ---------------------------------
const props = defineProps({
item: {
type: Object as PropType<Nullable<CardItem>>,
default: () => null
},
})
const el = ref(null)
onMounted(() => {
// store dom element moveable
props.item.setTarget(el.value)
})
onUnmounted(() => {
})
// ---------------------------------
// component methods
// ---------------------------------
const reloadKey = ref(0)
const icon = ref<Nullable<string>>(null)
const iconSize = ref<Nullable<number>>(null)
const iconColor = ref<Nullable<string>>(null)
const reload = () => {
reloadKey.value += 1
}
const update = debounce(() => {
if (!props.item?.payload?.icon) {
return;
}
iconColor.value = props.item?.payload?.icon?.iconColor || '#000000';
iconSize.value = props.item?.payload?.icon?.iconSize || 14;
if (props.item?.payload.icon.attrField) {
icon.value = RenderText([props.item?.payload.icon.attrField], '[' + props.item?.payload.icon.attrField + ']', props.item?.lastEvent);
return
}
icon.value = props.item?.payload.icon?.value || '';
return;
}, 100)
watch(
() => props.item,
(val?: CardItem) => {
if (!val) return;
update()
},
{
deep: true,
immediate: true
}
)
update();
</script>

<template>
<div ref="el" :class="[{'hidden': item.hidden}]" style="width: 100%; height: 100%">
<Icon
style="width: 100%; height: 100%"
:key="reloadKey"
:icon="icon"
:color="iconColor"
:size="iconSize" />
</div>

</template>

<style lang="less" >
.el-image__error, .el-image__placeholder, .el-image__inner {
height: auto;
}
.el-image.item-element {
overflow: visible;
}
</style>
Empty file.
9 changes: 8 additions & 1 deletion static_source/admin/src/views/Dashboard/card_items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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'}
];
15 changes: 15 additions & 0 deletions static_source/admin/src/views/Dashboard/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '';
}
Expand Down
7 changes: 2 additions & 5 deletions system/automation/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -40,7 +38,6 @@ type Action struct {
scriptService scripts.ScriptService
eventBus bus.Bus
scriptEngine *scripts.EngineWatcher
inProcess atomic.Bool
sync.Mutex
}

Expand Down
9 changes: 4 additions & 5 deletions system/automation/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -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,
}

Expand All @@ -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
}

Expand Down
Loading

0 comments on commit 3505174

Please sign in to comment.