Skip to content

Commit

Permalink
Develop (#281)
Browse files Browse the repository at this point in the history
* dahboard filter list updated
* added bluetooth le plugin
* added example for govee rbic bluetooth strip
* added example for LYWSD03MMC bluetooth thermometer
* technical debt
* the trigger system has been reworked
* added EntityCallScript function
* added jspack to javascript
  • Loading branch information
e154 authored Jul 28, 2024
1 parent 20a7215 commit 210d161
Show file tree
Hide file tree
Showing 204 changed files with 3,970 additions and 1,245 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,33 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: upload server darwin amd64 artifact
uses: softprops/action-gh-release@v1
with:
files: /home/runner/work/smart-home/smart-home/server-darwin-10.6-amd64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: upload server darwin arm64 artifact
uses: softprops/action-gh-release@v1
with:
files: /home/runner/work/smart-home/smart-home/server-darwin-10.6-arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: upload cli darwin arm64 artifact
uses: softprops/action-gh-release@v1
with:
files: /home/runner/work/smart-home/smart-home/cli-darwin-10.6-arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: upload cli darwin amd64 artifact
uses: softprops/action-gh-release@v1
with:
files: /home/runner/work/smart-home/smart-home/cli-darwin-10.6-amd64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: upload server darwin amd64 artifact
# uses: softprops/action-gh-release@v1
# with:
# files: /home/runner/work/smart-home/smart-home/server-darwin-10.6-amd64
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#
# - name: upload server darwin arm64 artifact
# uses: softprops/action-gh-release@v1
# with:
# files: /home/runner/work/smart-home/smart-home/server-darwin-10.6-arm64
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#
# - name: upload cli darwin arm64 artifact
# uses: softprops/action-gh-release@v1
# with:
# files: /home/runner/work/smart-home/smart-home/cli-darwin-10.6-arm64
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#
# - name: upload cli darwin amd64 artifact
# uses: softprops/action-gh-release@v1
# with:
# files: /home/runner/work/smart-home/smart-home/cli-darwin-10.6-amd64
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: upload cli linux amd64 artifact
uses: softprops/action-gh-release@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: trying to build
id: build-all
run: make build_server build_cli build_structure build_common_structure build_archive docker_image
id: build-linux
run: make build_linux build_structure build_common_structure build_archive docker_image
48 changes: 23 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.PHONY: get_deps fmt
.DEFAULT_GOAL := build
build: build_public build_server build_cli
tests: lint test
all: build build_structure build_common_structure build_archive docker_image
all: build_public build_linux build_structure build_common_structure build_archive docker_image
deploy: docker_image_upload

EXEC=server
Expand Down Expand Up @@ -100,21 +99,34 @@ svgo:
DIR=${ROOT}/data/icons/*
cd ${ROOT} && svgo ${DIR} --enable=inlineStyles --config '{ "plugins": [ { "inlineStyles": { "onlyMatchedOnce": false } }] }' --pretty

build_server:
@echo MARK: build server
build_linux:
@echo MARK: build linux server
${GO_BUILD_ENV} GOOS=linux GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-amd64
${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=7 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-7
${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=6 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-6
${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=5 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-5
${GO_BUILD_ENV} GOOS=darwin GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-amd64
${GO_BUILD_ENV} GOOS=darwin GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-arm64

build_cli:
@echo MARK: build cli
cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=linux GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-linux-amd64

build_darwin:
@echo MARK: build darwin server
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-amd64
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-arm64

@echo MARK: build cli
cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=darwin GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-darwin-10.6-amd64
cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=darwin GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-darwin-10.6-arm64

build_windows:
@echo MARK: build windows server
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-windows-amd64
CGO_ENABLED=1 GOOS=windows GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-windows-arm64

@echo MARK: build cli
cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=windows GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-windows-amd64
cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=windows GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-windows-arm64

build_public:
@echo MARK: build public
echo -e "node version.\n" && \
Expand Down Expand Up @@ -149,15 +161,8 @@ build_structure:
cp ${ROOT}/CONTRIBUTING.md ${SERVER_DIR}
cp ${ROOT}/bin/server-installer.sh ${SERVER_DIR}
chmod +x ${SERVER_DIR}/data/scripts/ping.sh
cp ${ROOT}/${EXEC}-linux-amd64 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-linux-arm-7 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-linux-arm-6 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-linux-arm-5 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-darwin-10.6-amd64 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-darwin-10.6-arm64 ${SERVER_DIR}
cp ${ROOT}/${CLI}-darwin-10.6-amd64 ${SERVER_DIR}
cp ${ROOT}/${CLI}-darwin-10.6-arm64 ${SERVER_DIR}
cp ${ROOT}/${CLI}-linux-amd64 ${SERVER_DIR}
cp ${ROOT}/${EXEC}-* ${SERVER_DIR}
cp ${ROOT}/${CLI}-* ${SERVER_DIR}
cp ${ROOT}/bin/server ${SERVER_DIR}

build_common_structure:
Expand Down Expand Up @@ -228,15 +233,8 @@ docker_image_upload:
clean:
@echo MARK: clean
rm -rf ${SERVER_DIR}
rm -f ${ROOT}/${EXEC}-linux-amd64
rm -f ${ROOT}/${EXEC}-linux-arm-7
rm -f ${ROOT}/${EXEC}-linux-arm-6
rm -f ${ROOT}/${EXEC}-linux-arm-5
rm -f ${ROOT}/${EXEC}-darwin-10.6-amd64
rm -f ${ROOT}/${EXEC}-darwin-10.6-arm64
rm -f ${ROOT}/${CLI}-linux-amd64
rm -f ${ROOT}/${CLI}-darwin-10.6-amd64
rm -f ${ROOT}/${CLI}-darwin-10.6-arm64
rm -f ${ROOT}/${EXEC}-*
rm -f ${ROOT}/${CLI}-*
rm -f ${HOME}/${ARCHIVE}

front_client:
Expand Down
2 changes: 1 addition & 1 deletion Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BUILD_NUMBER_VALUE=$(shell echo ${TRAVIS_BUILD_NUMBER})
RELEASE_VERSION ?= v0.1.0

IMAGE=smart-home-${EXEC}
SERVER ?= 192.168.43.127
SERVER ?= 192.168.0.170
DOCKER_ACCOUNT ?= ${SERVER}:5000
DOCKER_IMAGE_VER=${DOCKER_ACCOUNT}/${IMAGE}:${RELEASE_VERSION}
DOCKER_IMAGE_LATEST=${DOCKER_ACCOUNT}/${IMAGE}:latest
Expand Down
28 changes: 15 additions & 13 deletions adaptors/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IPlugin interface {
CreateOrUpdate(ctx context.Context, ver *m.Plugin) error
Update(ctx context.Context, plugin *m.Plugin) error
Delete(ctx context.Context, pluginId string) error
List(ctx context.Context, limit, offset int64, orderBy, sort string, onlyEnabled bool) (list []*m.Plugin, total int64, err error)
List(ctx context.Context, limit, offset int64, orderBy, sort string, enabled, triggers *bool) (list []*m.Plugin, total int64, err error)
Search(ctx context.Context, query string, limit, offset int64) (list []*m.Plugin, total int64, err error)
GetByName(ctx context.Context, name string) (ver *m.Plugin, err error)
fromDb(dbVer *db.Plugin) (plugin *m.Plugin)
Expand Down Expand Up @@ -80,9 +80,9 @@ func (p *Plugin) Delete(ctx context.Context, name string) (err error) {
}

// List ...
func (p *Plugin) List(ctx context.Context, limit, offset int64, orderBy, sort string, onlyEnabled bool) (list []*m.Plugin, total int64, err error) {
func (p *Plugin) List(ctx context.Context, limit, offset int64, orderBy, sort string, enabled, triggers *bool) (list []*m.Plugin, total int64, err error) {
var dbList []*db.Plugin
if dbList, total, err = p.table.List(ctx, int(limit), int(offset), orderBy, sort, onlyEnabled); err != nil {
if dbList, total, err = p.table.List(ctx, int(limit), int(offset), orderBy, sort, enabled, triggers); err != nil {
return
}

Expand Down Expand Up @@ -123,11 +123,12 @@ func (p *Plugin) GetByName(ctx context.Context, name string) (ver *m.Plugin, err

func (p *Plugin) fromDb(dbVer *db.Plugin) (ver *m.Plugin) {
ver = &m.Plugin{
Name: dbVer.Name,
Version: dbVer.Version,
Enabled: dbVer.Enabled,
System: dbVer.System,
Actor: dbVer.Actor,
Name: dbVer.Name,
Version: dbVer.Version,
Enabled: dbVer.Enabled,
System: dbVer.System,
Actor: dbVer.Actor,
Triggers: dbVer.Triggers,
}

// deserialize settings
Expand All @@ -141,11 +142,12 @@ func (p *Plugin) fromDb(dbVer *db.Plugin) (ver *m.Plugin) {

func (p *Plugin) toDb(ver *m.Plugin) (dbVer *db.Plugin) {
dbVer = &db.Plugin{
Name: ver.Name,
Version: ver.Version,
Enabled: ver.Enabled,
System: ver.System,
Actor: ver.Actor,
Name: ver.Name,
Version: ver.Version,
Enabled: ver.Enabled,
System: ver.System,
Actor: ver.Actor,
Triggers: ver.Triggers,
}

// serialize settings
Expand Down
37 changes: 34 additions & 3 deletions api/api.swagger3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,11 @@ paths:
required: true
schema:
type: string
- name: note
in: query
required: false
schema:
type: string
- name: lang
in: query
required: false
Expand Down Expand Up @@ -2536,6 +2541,16 @@ paths:
- $ref: '#/components/parameters/listSort'
- $ref: '#/components/parameters/listPage'
- $ref: '#/components/parameters/listLimit'
- name: triggers
in: query
required: false
schema:
type: boolean
- name: enabled
in: query
required: false
schema:
type: boolean
responses:
200:
description: A successful response.
Expand Down Expand Up @@ -6203,8 +6218,6 @@ components:
type: array
items:
type: string
script:
$ref: '#/components/schemas/apiScript'
scriptId:
type: integer
format: int64
Expand Down Expand Up @@ -6309,7 +6322,7 @@ components:
apiPluginOptionsResult:
type: object
required: [ triggers, actors, actorCustomAttrs, actorAttrs, actorCustomActions, actorActions, actorCustomStates,
actorStates, actorCustomSetts, actorSetts, setts ]
actorStates, actorCustomSetts, actorSetts, setts, triggerParams ]
properties:
triggers:
type: boolean
Expand Down Expand Up @@ -6343,6 +6356,24 @@ components:
type: object
additionalProperties:
$ref: '#/components/schemas/apiAttribute'
triggerParams:
$ref: '#/components/schemas/apiTriggerParams'
apiTriggerParams:
type: object
required: [script, entities, attributes, required]
properties:
required:
type: array
items:
type: string
script:
type: boolean
entities:
type: boolean
attributes:
type: object
additionalProperties:
$ref: '#/components/schemas/apiAttribute'
apiPluginOptionsResultEntityAction:
type: object
required: [ name, description, imageUrl, icon ]
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewControllerPlugin(common *ControllerCommon) *ControllerPlugin {
func (c ControllerPlugin) PluginServiceGetPluginList(ctx echo.Context, params stub.PluginServiceGetPluginListParams) error {

pagination := c.Pagination(params.Page, params.Limit, params.Sort)
items, total, err := c.endpoint.Plugin.GetList(ctx.Request().Context(), pagination)
items, total, err := c.endpoint.Plugin.GetList(ctx.Request().Context(), pagination, params.Enabled, params.Triggers)
if err != nil {
return c.ERROR(ctx, err)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c ControllerPlugin) PluginServiceUpdatePluginSettings(ctx echo.Context, na
// PluginServiceGetPluginReadme ...
func (c ControllerPlugin) PluginServiceGetPluginReadme(ctx echo.Context, name string, params stub.PluginServiceGetPluginReadmeParams) error {

html, err := c.endpoint.Plugin.Readme(ctx.Request().Context(), name, params.Lang)
html, err := c.endpoint.Plugin.Readme(ctx.Request().Context(), name, params.Note, params.Lang)
if err != nil {
return c.ERROR(ctx, err)
}
Expand Down
2 changes: 2 additions & 0 deletions api/dto/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func AttributeToApi(attributes m.Attributes) (apiAttr map[string]stub.ApiAttribu
case "encrypted":
attr.Type = stub.ENCRYPTED
attr.Encrypted = common.String(v.Decrypt())
default:
attr.Type = stub.ApiTypes(v.Type)
}
apiAttr[k] = attr
}
Expand Down
9 changes: 8 additions & 1 deletion api/dto/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package dto

import (
stub "github.com/e154/smart-home/api/stub"
"github.com/e154/smart-home/api/stub"
"github.com/e154/smart-home/common"
m "github.com/e154/smart-home/models"
)
Expand Down Expand Up @@ -85,7 +85,14 @@ func (p Plugin) Options(options m.PluginOptions) (result *stub.ApiPluginOptionsR
ActorCustomSetts: options.ActorCustomSetts,
ActorSetts: AttributeToApi(options.ActorSetts),
Setts: AttributeToApi(options.Setts),
TriggerParams: stub.ApiTriggerParams{
Attributes: AttributeToApi(options.TriggerParams.Attributes),
Entities: options.TriggerParams.Entities,
Script: options.TriggerParams.Script,
Required: options.TriggerParams.Required,
},
}

return
}

Expand Down
21 changes: 21 additions & 0 deletions api/stub/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 210d161

Please sign in to comment.