Skip to content

Commit

Permalink
add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed May 3, 2024
1 parent dca0703 commit 68222aa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
30 changes: 13 additions & 17 deletions pkg/entities/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,23 @@ const (
StateRemoteEntityAttribute RemoteEntityAttributes = "state"
)

const (
OnRemoteEntityCommand RemoteEntityCommand = "on"
OffRemoteEntityCommand RemoteEntityCommand = "off"
SendCmdRemoteEntityCommand RemoteEntityCommand = "send_cmd"
SendCmdSequenceRemoteEntityCommand RemoteEntityCommand = "send_cmd_sequence"
)

const (
SimpleCommandsRemoteEntityOption RemoteEntityOption = "simple_commands"
ButtonMappingRemoteEntityOption RemoteEntityOption = "button_mapping"
UserInterfaceRemoteEntityOption RemoteEntityOption = "user_interface"
)

type RemoteButtonMapping struct {
Button string `json:"string"`
ShortPress RemoteCommand `json:"short_press,omitempty"`
LongPress RemoteCommand `json:"long_press,omitempty"`
}

type RemoteCommand struct {
CmdId string `json:"cmd_id"`
Params map[string]string `json:"params,omitempty"`
}

type RemoteEntity struct {
Entity
Commands map[RemoteEntityCommand]func(RemoteEntity) int `json:"-"`
Options map[RemoteEntityOption]interface{} `json:"options"`
Commands map[RemoteEntityCommand]func(RemoteEntity, map[string]interface{}) int `json:"-"`
Options map[RemoteEntityOption]interface{} `json:"options"`
}

func NewRemoteEntity(id string, name LanguageText, area string) *RemoteEntity {
Expand All @@ -51,7 +47,7 @@ func NewRemoteEntity(id string, name LanguageText, area string) *RemoteEntity {
remoteEntity.Name = name
remoteEntity.Area = area

remoteEntity.Commands = make(map[RemoteEntityCommand]func(RemoteEntity) int)
remoteEntity.Commands = make(map[RemoteEntityCommand]func(RemoteEntity, map[string]interface{}) int)
remoteEntity.Attributes = make(map[string]interface{})

remoteEntity.Options = make(map[RemoteEntityOption]interface{})
Expand Down Expand Up @@ -85,15 +81,15 @@ func (e RemoteEntity) AddFeature(feature RemoteEntityFeatures) {
}

// Register a function for the Entity command
func (e *RemoteEntity) AddCommand(command RemoteEntityCommand, function func(RemoteEntity) int) {
func (e *RemoteEntity) AddCommand(command RemoteEntityCommand, function func(RemoteEntity, map[string]interface{}) int) {
e.Commands[command] = function

}

// Call the registred function for this entity_command
func (e *RemoteEntity) HandleCommand(cmd_id string) int {
func (e *RemoteEntity) HandleCommand(cmd_id string, params map[string]interface{}) int {
if e.Commands[RemoteEntityCommand(cmd_id)] != nil {
return e.Commands[RemoteEntityCommand(cmd_id)](*e)
return e.Commands[RemoteEntityCommand(cmd_id)](*e, params)
}

return 404
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (i *Integration) handleCommand(entity interface{}, req *EntityCommandReq) i
// Sensor do not have commands

case *entities.RemoteEntity:
return e.HandleCommand(cmd_id)
return e.HandleCommand(cmd_id, params)
}

return 404
Expand Down
40 changes: 40 additions & 0 deletions pkg/integration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,43 @@ type RequireUserAction struct {
Input interface{} `json:"input,omitempty"`
Confirmation interface{} `json:"confirmation,omitempty"`
}

type RemoteButtonMapping struct {
Button string `json:"string"`
ShortPress RemoteCommand `json:"short_press,omitempty"`
LongPress RemoteCommand `json:"long_press,omitempty"`
}

type RemoteCommand struct {
CmdId string `json:"cmd_id"`
Params map[string]string `json:"params,omitempty"`
}

type UserInterface struct {
Pages []UserInterfacePage `json:"pages"`
}

type UserInterfacePage struct {
PageID string `json:"page_id"`
Name string `json:"name,omitempty"`
Grid struct {
Width int `json:"width"`
Height int `json:"height"`
} `json:"grid"`
Items []UserInterfaceItem `json:"items"`
}

type UserInterfaceItem struct {
Type string `json:"type"`
Icon string `json:"icon"`
Text string `json:"text"`
Command RemoteCommand `json:"command"`
Location struct {
X int `json:"x"`
Y int `json:"y"`
} `json:"location"`
Size struct {
Width int `json:"width"`
Height int `json:"height"`
} `json:"size"`
}

0 comments on commit 68222aa

Please sign in to comment.