diff --git a/pkg/entities/remote.go b/pkg/entities/remote.go index e224794..83c560e 100644 --- a/pkg/entities/remote.go +++ b/pkg/entities/remote.go @@ -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 { @@ -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{}) @@ -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 diff --git a/pkg/integration/entities.go b/pkg/integration/entities.go index 4b01375..61790f3 100644 --- a/pkg/integration/entities.go +++ b/pkg/integration/entities.go @@ -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 diff --git a/pkg/integration/types.go b/pkg/integration/types.go index 33a87ef..0d732c4 100644 --- a/pkg/integration/types.go +++ b/pkg/integration/types.go @@ -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"` +}