integration

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2024 License: MPL-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const API_VERSION = "0.10.0"

Variables

This section is empty.

Functions

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host TODO: make this more robust, what if more ifaces are available

Types

type AbortDriverSetupData

type AbortDriverSetupData struct {
	Error DriverSetupError `json:"error"`
}

type AbortDriverSetupEvent

type AbortDriverSetupEvent struct {
	CommonEvent
	MsgData AbortDriverSetupData `json:"msg_data"`
}

type AuthRequestData

type AuthRequestData struct {
	Token string `json:"token"`
}

type AuthRequestMessage

type AuthRequestMessage struct {
	CommonReq
	MsgData AuthRequestData `json:"msg_data"`
}

type AuthenticationResponse

type AuthenticationResponse struct {
	CommonResp
	MsgData DriverVersionData `json:"msg_data"`
}

type AvailableEntityData

type AvailableEntityData struct {
	Filter            AvailableEntityFilter `json:"filter,omitempty"`
	AvailableEntities []interface{}         `json:"available_entities"`
}

type AvailableEntityFilter

type AvailableEntityFilter struct {
	DeviceId
	entities.EntityType
}

type AvailableEntityMessage

type AvailableEntityMessage struct {
	CommonResp
	MsgData AvailableEntityData `json:"msg_data"`
}

type AvailableEntityMessageData

type AvailableEntityMessageData struct {
	Filter AvailableEntityFilter `json:"filter,omitempty"`
}

type AvailableEntityMessageReq

type AvailableEntityMessageReq struct {
	CommonReq
	MsgData AvailableEntityMessageData `json:"msg_data,omitempty"`
}

type AvailableEntityNoFilterData

type AvailableEntityNoFilterData struct {
	AvailableEntities []interface{} `json:"available_entities"`
}

type AvailableEntityNoFilterMessage

type AvailableEntityNoFilterMessage struct {
	CommonResp
	MsgData AvailableEntityNoFilterData `json:"msg_data"`
}

type ButtonMapping added in v0.3.4

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

type Client added in v0.2.0

type Client struct {
	IntegrationDriver *Integration

	DeviceState DState

	Messages chan string

	// Client specific functions
	// Initialize the client
	// Here you can add entities if they are already known
	InitFunc func()
	// Called by RemoteTwo when the integration is added and setup started
	SetupFunc func(SetupData)
	// Handles connect/disconnect calls from RemoteTwo
	ClientLoopFunc        func()
	SetDriverUserDataFunc func(map[string]string, bool)
}

Generic client

func NewClient added in v0.2.0

func NewClient(i *Integration) *Client

func (*Client) ClientLoop added in v0.2.0

func (c *Client) ClientLoop()

func (*Client) Connect added in v0.2.0

func (c *Client) Connect()

func (*Client) Disconnect added in v0.2.0

func (c *Client) Disconnect()

func (*Client) FinishIntegrationSetup added in v0.3.1

func (c *Client) FinishIntegrationSetup()

func (*Client) HandleConnection added in v0.2.0

func (c *Client) HandleConnection(e *ConnectEvent)

func (*Client) HandleSetDriverUserDataFunction added in v0.2.0

func (c *Client) HandleSetDriverUserDataFunction(userdata map[string]string, confirm bool)

User input result of a SettingsPage as key values. key: id of the field value: entered user value as string. This is either the entered text or number, selected checkbox state or the selected dropdown item id. ⚠️ Non native string values as numbers or booleans are represented as string values!

func (*Client) HandleSetup added in v0.2.0

func (c *Client) HandleSetup(setup_data SetupData)

Handle Setup called by Remote Two to setup this integration the SetupData are passed to this function

func (*Client) InitClient added in v0.2.0

func (c *Client) InitClient()

func (*Client) IntegrationSetupFinished added in v0.3.1

func (c *Client) IntegrationSetupFinished() bool

func (*Client) SetDeviceState added in v0.2.0

func (c *Client) SetDeviceState(state DState)

type Command added in v0.3.4

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

type CommonEvent

type CommonEvent struct {
	Kind string `json:"kind"`
	Msg  string `json:"msg"`
	Cat  string `json:"cat"`
	Ts   string `json:"ts,omitempty"`
}

type CommonReq

type CommonReq struct {
	Kind string `json:"kind"`
	Id   int    `json:"id"`
	Msg  string `json:"msg"`
}

Common

type CommonResp

type CommonResp struct {
	Kind string `json:"kind"`
	Id   int    `json:"req_id"`
	Msg  string `json:"msg"`
	Code int    `json:"code"`
}

type Config

type Config struct {
	ListenPort               int    `mapstructure:"listenPort"`
	DisableMDNS              bool   `mapstructure:"disableMDNS"`
	EnableRegistration       bool   `mapstructure:"enableRegistration"`
	RegistrationUsername     string `mapstructure:"registrationUsername"`
	RegistrationPin          string `mapstructure:"registrationPin"`
	WebsocketPath            string `mapstructure:"websocketPath"`
	ConfigHome               string `mapstructure:"ucconfighome"`
	RemoteTwoHost            string `mapstructure:"remoteTwoIP"`
	RemoteTwoPort            int    `mapstructure:"remoteTwoPort"`
	IgnoreEntitySubscription bool
}

Generic string key/value config map to store configuration option

type ConfirmationPage

type ConfirmationPage struct {
	Title    LanguageText `json:"title"`
	Message1 interface{}  `json:"message1,omitempty"`
	Image    string       `json:"image,omitempty"`
	Message2 interface{}  `json:"message2,omitempty"`
}

type ConnectEvent

type ConnectEvent struct {
	CommonEvent
	MsgData ConnectEventData `json:"msg_data,omitempty"`
}

type ConnectEventData

type ConnectEventData struct {
	DeviceId string `json:"device_id,omitempty"`
}

type DState

type DState string
const (
	ConnectedDeviceState    DState = "CONNECTED"
	ConnectingDeviceState   DState = "CONNECTING"
	DisconnectedDeviceState DState = "DISCONNECTED"
	ErrorDeviceState        DState = "ERROR"
)

type Developer

type Developer struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	EMail string `json:"email,omitempty"`
}

type DeviceId

type DeviceId struct {
	DeviceId string `json:"device_id,omitempty"`
}

type DeviceState

type DeviceState struct {
	DeviceId
	State string `json:"state"`
}

type DeviceStateEventMessage

type DeviceStateEventMessage struct {
	CommonEvent
	MsgData DeviceState `json:"msg_data"`
}

type DeviceStateMessageReq

type DeviceStateMessageReq struct {
	CommonReq
	MsgData DeviceId
}

type DriverMetadata

type DriverMetadata struct {
	DriverId        string          `json:"driver_id"`
	Name            LanguageText    `json:"name"`
	DriverUrl       string          `json:"driver_url,omitempty"`
	AuthMethod      string          `json:"auth_method,omitempty"`
	Version         string          `json:"version"`
	MinCoreAPI      string          `json:"min_core_api,omitempty"`
	Icon            string          `json:"icon,omitempty"`
	Description     LanguageText    `json:"description"`
	Developer       Developer       `json:"developer,omitempty"`
	HomePage        string          `json:"home_page,omitempty"`
	DeviceDiscovery bool            `json:"device_discovery,omitempty"`
	SetupDataSchema SetupDataSchema `json:"setup_data_schema,omitempty"`
	ReleaseData     string          `json:"release_date,omitempty"`
}

type DriverMetadataReponse

type DriverMetadataReponse struct {
	CommonResp
	MsgData DriverMetadata `json:"msg_data"`
}

type DriverMetadataReq

type DriverMetadataReq struct {
	CommonReq
}

type DriverRegistration

type DriverRegistration struct {
	DriverId        string          `json:"driver_id,omitempty"`
	Name            LanguageText    `json:"name"`
	DriverURL       string          `json:"driver_url"`
	Version         string          `json:"version"`
	Icon            string          `json:"icon"`
	Enabled         bool            `json:"enabled"`
	Description     LanguageText    `json:"description"`
	DeviceDiscovery bool            `json:"device_discovery"`
	SetupDataSchema SetupDataSchema `json:"setup_data_schema"`
	ReleaseDate     string          `json:"release_date,omitempty"`
}

type DriverSetupChangeData

type DriverSetupChangeData struct {
	EventType         DriverSetupEventType `json:"event_type"`
	State             DriverSetupState     `json:"state"`
	Error             DriverSetupError     `json:"error,omitempty"`
	RequireUserAction interface{}          `json:"require_user_action,omitempty"`
}

type DriverSetupChangeEvent

type DriverSetupChangeEvent struct {
	CommonEvent
	MsgData DriverSetupChangeData `json:"msg_data,omitempty"`
}

type DriverSetupError

type DriverSetupError string
const (
	NoneError              DriverSetupError = "NONE"
	NotFoundError          DriverSetupError = "NOT_FOUND"
	ConnectionRefusedError DriverSetupError = "CONNECTION_REFUSED"
	AuthErrorError         DriverSetupError = "AUTHORIZATION_ERROR"
	TimeoutError           DriverSetupError = "TIMEOUT"
	OtherError             DriverSetupError = "OTHER"
)

type DriverSetupEventType

type DriverSetupEventType string
const (
	StartEvent DriverSetupEventType = "START"
	SetupEvent DriverSetupEventType = "SETUP"
	StopEvent  DriverSetupEventType = "STOP"
)

type DriverSetupState

type DriverSetupState string
const (
	SetupState          DriverSetupState = "SETUP"
	WaitUserActionState DriverSetupState = "WAIT_USER_ACTION"
	OkState             DriverSetupState = "OK"
	ErrorState          DriverSetupState = "ERROR"
)

type DriverVersionData

type DriverVersionData struct {
	Name    string  `json:"name"`
	Version Version `json:"version"`
}

type DriverVersionReq

type DriverVersionReq struct {
	CommonReq
}

type EntityAvailableEvent

type EntityAvailableEvent struct {
	CommonEvent
	MsgData interface{} `json:"msg_data"`
}

type EntityChangeData

type EntityChangeData struct {
	DeviceId   string                 `json:"device_id,omitempty"`
	EntityType string                 `json:"entity_type"`
	EntityId   string                 `json:"entity_id"`
	Attributes map[string]interface{} `json:"attributes"`
}

type EntityChangeEvent

type EntityChangeEvent struct {
	CommonEvent
	MsgData EntityChangeData `json:"msg_data"`
}

type EntityCommandData

type EntityCommandData struct {
	DeviceId string                 `json:"device_id"`
	EntityId string                 `json:"entity_id"`
	CmdId    string                 `json:"cmd_id"`
	Params   map[string]interface{} `json:"params"`
}

type EntityCommandReq

type EntityCommandReq struct {
	CommonReq
	MsgData EntityCommandData `json:"msg_data,omitempty"`
}

type EntityCommandResponse

type EntityCommandResponse struct {
	CommonResp
}

type EntityRemovedEvent

type EntityRemovedEvent struct {
	CommonEvent
	MsgData EntityRemovedEventData `json:"msg_data"`
}

type EntityRemovedEventData

type EntityRemovedEventData struct {
	DeviceId   string `json:"device_id,omitempty"`
	EntityType string `json:"entity_type"`
	EntityId   string `json:"entity_id"`
}

type EventMessage

type EventMessage struct {
	CommonEvent
	MsgData interface{} `json:"msg_data"`
}

type GetEntityStatesMessage

type GetEntityStatesMessage struct {
	CommonResp
	MsgData []entities.EntityStateData `json:"msg_data,omitempty"`
}

type GetEntityStatesMessageData

type GetEntityStatesMessageData struct {
	DeviceId string `json:"device_id"`
}

type GetEntityStatesMessageReq

type GetEntityStatesMessageReq struct {
	CommonReq
	MsgData GetEntityStatesMessageData `json:"msg_data,omitempty"`
}

type Integration

type Integration struct {
	DeviceId string
	DriverId string

	Metadata *DriverMetadata

	Config Config

	Remote remote

	Entities []interface{}

	SubscribedEntities []string

	SetupState DriverSetupState

	SetupData SetupData
	// contains filtered or unexported fields
}

func NewIntegration

func NewIntegration(config Config) (*Integration, error)

func (*Integration) AddEntity

func (i *Integration) AddEntity(e interface{}) error

Add a new Entity to the list of Entities (if not already added) Also make sure the EntityChange Function is set so Entity Change Events are emitted when a Entity Attribute changes Send Entity Available Event to RT

func (*Integration) GetEntitiesByType

func (i *Integration) GetEntitiesByType(entityType entities.EntityType) []interface{}

Return all available entities of a given type

func (*Integration) GetEntityById

func (i *Integration) GetEntityById(id string) (interface{}, int, error)

Return an Entity by its Name Also return the current index in the Entities Array (TODO: do we need this?) Error when Entity not found

func (*Integration) LoadSetupData

func (i *Integration) LoadSetupData()

Load persist setupData File TODO: handle location via ENV's

func (*Integration) PersistSetupData

func (i *Integration) PersistSetupData()

Persist File TODO: handle location via ENV's

func (*Integration) RemoveEntity

func (i *Integration) RemoveEntity(entity interface{}) error

Remove an Entity from the Integration Send Entity Removed Event to RT

func (*Integration) RemoveEntityByID

func (i *Integration) RemoveEntityByID(entity_id string) error

Remove an Entity from the Integration Send Entity Removed Event to RT

func (*Integration) Run

func (i *Integration) Run() error

func (*Integration) SendAuthenticationResponse

func (i *Integration) SendAuthenticationResponse()

Send a AuthenticationResponse Message

func (*Integration) SendEntityChangeEvent

func (i *Integration) SendEntityChangeEvent(e interface{}, a *map[string]interface{})

Emitted when an attribute of an entity changes, e.g. is switched off. Either after an entity_command or if the entity is updated manually through a user or an external system. This keeps the Remote Two in sync with the real state of the entity without the need of constant polling.

func (*Integration) SetDeviceState

func (i *Integration) SetDeviceState(state DState)

func (*Integration) SetDriverSetupState

func (i *Integration) SetDriverSetupState(event_Type DriverSetupEventType, state DriverSetupState, err DriverSetupError, requireUserAction *RequireUserAction)

Set and then Send the Driver Setup State to Remote two

func (*Integration) SetHandleConnectionFunction

func (i *Integration) SetHandleConnectionFunction(f func(*ConnectEvent))

Set the function which is called when the connect/disconnect request was sent by the remote

func (*Integration) SetHandleSetDriverUserDataFunction

func (i *Integration) SetHandleSetDriverUserDataFunction(f func(map[string]string, bool))

Set the function which is called when the setDriverUsaerData request was sent by the remote

func (*Integration) SetHandleSetupFunction

func (i *Integration) SetHandleSetupFunction(f func(SetupData))

Set the function which is called when the setup_driver request was sent by the remote

func (*Integration) SetMetadata

func (i *Integration) SetMetadata(metadata *DriverMetadata)

func (*Integration) UpdateEntity

func (i *Integration) UpdateEntity(entity interface{}, newEntity interface{}) error

Update an existing entity with a new entity

type LanguageText

type LanguageText struct {
	En string `json:"en,omitempty"`
	De string `json:"de,omitempty"`
}

type RequestMessage

type RequestMessage struct {
	CommonReq
	MsgData interface{} `json:"msg_data,omitempty"`
}

Requests

type RequireUserAction

type RequireUserAction struct {
	Input        interface{} `json:"input,omitempty"`
	Confirmation interface{} `json:"confirmation,omitempty"`
}

type ResponseMessage

type ResponseMessage struct {
	CommonResp
	MsgData interface{} `json:"msg_data,omitempty"`
}

type SetDriverUserData

type SetDriverUserData struct {
	InputValues map[string]string `json:"input_values,omitempty"`
	Confirm     bool              `json:"confirm,omitempty"`
}

type SetDriverUserDataRequest

type SetDriverUserDataRequest struct {
	CommonReq
	MsgData SetDriverUserData `json:"msg_data"`
}

Set required data to configure the integration driver or continue the setup process.

type SettigsPage

type SettigsPage struct {
	Title    LanguageText `json:"title"`
	Settings []Setting    `json:"settings"`
}

type Setting

type Setting struct {
	Id    string       `json:"id"`
	Label LanguageText `json:"label"`
	Field interface{}  `json:"field"`
}

type SettingTypeCheckbox

type SettingTypeCheckbox struct {
	Checkbox SettingTypeCheckboxDefinition `json:"checkbox"`
}

type SettingTypeCheckboxDefinition

type SettingTypeCheckboxDefinition struct {
	Value bool `json:"value"`
}

type SettingTypeDropdowDefinition

type SettingTypeDropdowDefinition struct {
	Value string                              `json:"value"`
	Items []SettingTypeDropdowItemsDefinition `json:"items"`
}

type SettingTypeDropdowItemsDefinition

type SettingTypeDropdowItemsDefinition struct {
	Id    string       `json:"id"`
	Label LanguageText `json:"label"`
}

type SettingTypeDropdown

type SettingTypeDropdown struct {
	Dropdown SettingTypeDropdowDefinition `json:"dropdown"`
}

type SettingTypeLabel

type SettingTypeLabel struct {
	Label SettingTypeLabelDefinition `json:"label"`
}

type SettingTypeLabelDefinition

type SettingTypeLabelDefinition struct {
	Value LanguageText `json:"value"`
}

type SettingTypeNumber

type SettingTypeNumber struct {
	Number SettingTypeNumberDefinition `json:"number"`
}

type SettingTypeNumberDefinition

type SettingTypeNumberDefinition struct {
	Value    float64      `json:"value"`
	Min      float64      `json:"min,omitempty"`
	Max      float64      `json:"max,omitempty"`
	Step     float64      `json:"step,omitempty"`
	Decimals int          `json:"decimal,omitempty"`
	Unit     LanguageText `json:"unit"`
}

type SettingTypePassword

type SettingTypePassword struct {
	Password SettingTypePasswordDefinition `json:"password"`
}

type SettingTypePasswordDefinition

type SettingTypePasswordDefinition struct {
	Value string `json:"value"`
	Regex string `json:"regex,omitempty"`
}

type SettingTypeText

type SettingTypeText struct {
	Text SettingTypeTextDefinition `json:"text"`
}

type SettingTypeTextArea

type SettingTypeTextArea struct {
	TextArea SettingTypeTextAreaDefinition `json:"textarea"`
}

type SettingTypeTextAreaDefinition

type SettingTypeTextAreaDefinition struct {
	Value string `json:"value"`
}

type SettingTypeTextDefinition

type SettingTypeTextDefinition struct {
	Value string `json:"value"`
	Regex string `json:"regex,omitempty"`
}

type SetupData

type SetupData map[string]string

type SetupDataSchema

type SetupDataSchema struct {
	Title    LanguageText              `json:"title"`
	Settings []SetupDataSchemaSettings `json:"settings"`
}

type SetupDataSchemaSettings

type SetupDataSchemaSettings struct {
	Id    string       `json:"id"`
	Label LanguageText `json:"label"`
	Field interface{}  `json:"field"`
}

type SetupDataValue

type SetupDataValue struct {
	Reconfigure bool      `json:"reconfigure,omitempty"`
	Value       SetupData `json:"setup_data"`
}

type SetupDriverMessageReq

type SetupDriverMessageReq struct {
	CommonReq
	MsgData SetupDataValue `json:"msg_data"`
}

type SubscribeEventMessage

type SubscribeEventMessage struct {
	CommonResp
}

type SubscribeEventMessageData

type SubscribeEventMessageData struct {
	DeviceId  string   `json:"device_id"`
	EntityIds []string `json:"entity_ids"`
}

type SubscribeEventMessageReq

type SubscribeEventMessageReq struct {
	CommonReq
	MsgData SubscribeEventMessageData `json:"msg_data,omitempty"`
}

type Token

type Token struct {
	Token string `json:"token"`
}

type UnubscribeEventMessage

type UnubscribeEventMessage struct {
	CommonResp
}

type UnubscribeEventMessageData

type UnubscribeEventMessageData struct {
	DeviceId  string   `json:"device_id"`
	EntityIds []string `json:"entity_ids"`
}

type UnubscribeEventMessageReq

type UnubscribeEventMessageReq struct {
	CommonReq
	MsgData SubscribeEventMessageData `json:"msg_data,omitempty"`
}

type UserInterface added in v0.3.4

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

type UserInterfaceItem added in v0.3.4

type UserInterfaceItem struct {
	Type     string  `json:"type"`
	Icon     string  `json:"icon"`
	Text     string  `json:"text"`
	Command  Command `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"`
}

type UserInterfacePage added in v0.3.4

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 Version

type Version struct {
	Api    string `json:"api"`
	Driver string `json:"driver"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL