Skip to content

Commit

Permalink
Develop (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 authored Jan 12, 2024
1 parent 8aa44f8 commit 741f49a
Show file tree
Hide file tree
Showing 47 changed files with 115 additions and 81 deletions.
6 changes: 3 additions & 3 deletions api/api.swagger3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5041,14 +5041,14 @@ components:
type: string
area:
$ref: '#/components/schemas/apiArea'
image:
$ref: '#/components/schemas/apiImage'
icon:
type: string
autoLoad:
type: boolean
parentId:
type: string
isLoaded:
type: boolean
createdAt:
type: string
format: date-time
Expand Down Expand Up @@ -5234,7 +5234,7 @@ components:
items:
type: array
items:
$ref: '#/components/schemas/apiEntity'
$ref: '#/components/schemas/apiEntityShort'
meta:
$ref: '#/components/schemas/apiMeta'
apiGetEntityStorageResult:
Expand Down
21 changes: 8 additions & 13 deletions api/dto/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ package dto
import (
"fmt"

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 @@ -168,20 +167,19 @@ func (r Entity) ToSearchResult(list []*m.Entity) *stub.ApiSearchEntityResult {
}

// ToListResult ...
func (r Entity) ToListResult(list []*m.Entity) []*stub.ApiEntity {
func (r Entity) ToListResult(list []*m.Entity) []*stub.ApiEntityShort {

items := make([]*stub.ApiEntity, 0, len(list))
items := make([]*stub.ApiEntityShort, 0, len(list))

for _, i := range list {
items = append(items, ToEntity(i))
items = append(items, r.ToEntityShort(i))
}

return items
}

// ToEntityShort ...
func (r Entity) ToEntityShort(entity *m.Entity) (obj *stub.ApiEntityShort) {
imageDto := NewImageDto()
obj = &stub.ApiEntityShort{
Id: entity.Id.String(),
PluginName: entity.PluginName,
Expand All @@ -191,6 +189,7 @@ func (r Entity) ToEntityShort(entity *m.Entity) (obj *stub.ApiEntityShort) {
CreatedAt: entity.CreatedAt,
UpdatedAt: entity.UpdatedAt,
ParentId: entity.ParentId.StringPtr(),
IsLoaded: common.Bool(entity.IsLoaded),
}
// area
if entity.Area != nil {
Expand All @@ -200,10 +199,6 @@ func (r Entity) ToEntityShort(entity *m.Entity) (obj *stub.ApiEntityShort) {
Description: entity.Area.Description,
}
}
// image
if entity.Image != nil {
obj.Image = imageDto.ToImage(entity.Image)
}

return
}
Expand Down Expand Up @@ -241,7 +236,7 @@ func ToEntity(entity *m.Entity) (obj *stub.ApiEntity) {
}
// image
if entity.Image != nil {
obj.Image = imageDto.ToImage(entity.Image)
obj.Image = imageDto.ToImageShort(entity.Image)
}
// parent
if entity.ParentId != nil {
Expand All @@ -263,7 +258,7 @@ func ToEntity(entity *m.Entity) (obj *stub.ApiEntity) {
}
// script
if a.Script != nil {
action.Script = scriptDto.GetStubScript(a.Script)
action.Script = scriptDto.GetStubScriptShort(a.Script)
}
obj.Actions = append(obj.Actions, action)
}
Expand All @@ -284,7 +279,7 @@ func ToEntity(entity *m.Entity) (obj *stub.ApiEntity) {
}
// scripts
for _, s := range entity.Scripts {
script := scriptDto.GetStubScript(s)
script := scriptDto.GetStubScriptShort(s)
obj.Scripts = append(obj.Scripts, *script)
obj.ScriptIds = append(obj.ScriptIds, s.Id)
}
Expand Down
10 changes: 10 additions & 0 deletions api/dto/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func (i Image) ToImage(image *m.Image) (result *stub.ApiImage) {
return
}

// ToImageShort ...
func (i Image) ToImageShort(image *m.Image) (result *stub.ApiImage) {
result = &stub.ApiImage{
Id: image.Id,
Name: image.Name,
Url: image.Url,
}
return
}

// FromNewImageRequest ...
func (i Image) FromNewImageRequest(req *stub.ApiNewImageRequest) (image *m.Image) {
image = &m.Image{
Expand Down
18 changes: 18 additions & 0 deletions api/dto/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (s Script) GetStubScript(script *m.Script) (result *stub.ApiScript) {
return
}

// GetStubScriptShort ...
func (s Script) GetStubScriptShort(script *m.Script) (result *stub.ApiScript) {
result = GetStubScriptShort(script)
return
}

// ToSearchResult ...
func (s Script) ToSearchResult(list []*m.Script) *stub.ApiSearchScriptListResult {

Expand Down Expand Up @@ -139,6 +145,18 @@ func GetStubScript(script *m.Script) (result *stub.ApiScript) {
return
}

// GetStubScriptShort ...
func GetStubScriptShort(script *m.Script) (result *stub.ApiScript) {
if script == nil {
return
}
result = &stub.ApiScript{
Id: script.Id,
Name: script.Name,
}
return
}

func ImportScript(from *stub.ApiScript) (*int64, *m.Script) {
if from == nil {
return nil, nil
Expand Down
6 changes: 3 additions & 3 deletions api/stub/types.go

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

2 changes: 1 addition & 1 deletion plugins/alexa/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Server ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/cgminer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/cpuspeed/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/email/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/hdd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/html5_notify/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/logs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/memory/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/memory_app/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/messagebird/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/modbus_rtu/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/modbus_tcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/moon/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/mqtt/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/mqtt_bridge/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/neural_network/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (p *plugin) Depends() []string {
}

func (p *plugin) Version() string {
return "0.0.1"
return Version
}

func (p *plugin) Options() m.PluginOptions {
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

func (p *plugin) pushToNode() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/notify/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}
2 changes: 1 addition & 1 deletion plugins/onvif/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/scene/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/sensor/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/slack/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/sun/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/triggers/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// GetTrigger ...
Expand Down
2 changes: 1 addition & 1 deletion plugins/twilio/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *plugin) Depends() []string {

// Version ...
func (p *plugin) Version() string {
return "0.0.1"
return Version
}

// Options ...
Expand Down
Loading

0 comments on commit 741f49a

Please sign in to comment.