Documentation
¶
Overview ¶
Package api provides functionality to interact with smart home devices connected to F&Home system.
Index ¶
- Constants
- Variables
- func DecodeTemperatureValue(value string) (float64, error)
- func DecodeTemperatureValueStr(value string) (float64, error)
- func EncodeTemperature(value float64) string
- func MapLighting(value int) string
- func Pprint(i interface{}) string
- func RemapLighting(value string) (int, error)
- type Action
- type Cell
- type CellValue
- type Client
- func (c *Client) Close() error
- func (c *Client) GetMyResources() (*GetMyResourcesResponse, error)
- func (c *Client) GetSystemConfig(ctx context.Context) (*TouchesResponse, error)
- func (c *Client) GetUserConfig(ctx context.Context) (*UserConfig, error)
- func (c *Client) OpenCloudSession(email, password string) error
- func (c *Client) OpenResourceSession(ctx context.Context, resourcePassword string) error
- func (c *Client) ReadAnyMessage() (*Message, error)
- func (c *Client) ReadMessage(ctx context.Context, actionName string, requestToken string) (*Message, error)
- func (c *Client) SendEvent(ctx context.Context, cellID int, value string) error
- type Config
- type DisplayType
- type Event
- type GetMyResources
- type GetMyResourcesResponse
- type GetUserConfigResponse
- type Icon
- type Message
- type MobileDisplayCell
- type OpenClientSession
- type OpenClientToResourceSession
- type Panel
- type PositionInPanel
- type Response
- type StatusTouchesChangedResponse
- type TouchesResponse
- type UserCell
- type UserConfig
- type UserPanel
Constants ¶
const ( ActionOpenClientSession = "open_client_session" ActionGetMyData = "get_my_data" ActionGetMyResources = "get_my_resources" ActionOpenClienToResourceSession = "open_client_to_resource_session" ActionGetSystemConfig = "touches" ActionGetUserConfig = "get_user_config" ActionEvent = "xevent" // ActionStatusTouches can be sent to get real values of resources. ActionStatusTouches = "statustouches" ActionStatusTouchesChanged = "statustoucheschanged" )
const URL = "wss://fhome.cloud/webapp-interface/"
URL is a URL at which F&Home API lives.
It has to end with a trailing slash, otherwise handshake fails.
Variables ¶
var ValueToggle = "0x4001"
Functions ¶
func DecodeTemperatureValue ¶
DecodeTemperatureValue converts hex string to float64 representing temperature in °C.
Examples:
* "0xa005" -> 0.5
* "0xa078" -> 12.0
* "0xa118" -> 28.0
func DecodeTemperatureValueStr ¶
DecodeTemperatureValueStr converts °C in string to float64.
Example:
"24,0°C" -> 24
func EncodeTemperature ¶
EncodeTemperature encodes value to represent temperature that is ready to be passed to Client.SendEvent.
Examples of the process:
* 12 -> 41080 + 12 * 10 -> 41080 -> "0xa078"
* 25 -> 41080 + 25 * 10 -> 41210 -> "0xa0fa"
* 28 -> 41080 + 28 * 10 -> 41240 -> "0xa118"
func MapLighting ¶
MapLighting maps value to a string that is ready to be passed to Client.SendEvent.
Clamps if the value is too small or too big.
func RemapLighting ¶
Types ¶
type CellValue ¶
type CellValue struct { ID string `json:"VOI"` Ii string `json:"II"` DisplayType DisplayType `json:"DT"` Value string `json:"DV"` // Probably "data value" ValueStr string `json:"DVS"` // Probably "data value string" }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient returns a new F&Home API client.
If a nil dialer is provided, a default dialer from gorilla/websocket will be used.
func (*Client) GetMyResources ¶
func (c *Client) GetMyResources() (*GetMyResourcesResponse, error)
GetMyResources gets resources assigned to the user.
Most of the time, there will be just one resource. Currently we handle only this case and assign its unique ID to the client.
func (*Client) GetSystemConfig ¶
func (c *Client) GetSystemConfig(ctx context.Context) (*TouchesResponse, error)
GetSystemConfig returns additional information about particular cells, e.g., their style (icon) and configurator-set name.
Configuration returned by this method is set in the desktop configurator app.
This action is named "Touches" in F&Home's terminology.
func (*Client) GetUserConfig ¶
func (c *Client) GetUserConfig(ctx context.Context) (*UserConfig, error)
GetUserConfig returns configuration of cells and panels.
The configuration returned by this method is set in the web or mobile app.
func (*Client) OpenCloudSession ¶
OpenCloudSession opens a websocket connection to F&Home Cloud.
func (*Client) OpenResourceSession ¶
OpenResourceSession open a websocket connection to the only resource that the user has.
Currently, it assumes that a user has only one resource.
func (*Client) ReadAnyMessage ¶
ReadAnyMessage returns any message received from the server.
If the message has status and it is not ok, it returns an error.
func (*Client) ReadMessage ¶
func (c *Client) ReadMessage(ctx context.Context, actionName string, requestToken string) (*Message, error)
ReadMessage waits until the client receives a message with matching actionName and requestToken.
If requestToken is empty, then it is ignored. In such a case, the first message with matching actionName is returned.
If its status is not "ok", it returns an error.
type Config ¶
type Config struct {
Panels []Panel
}
Config merges UserConfig and TouchesResponse.
func MergeConfigs ¶
func MergeConfigs(userConfig *UserConfig, touchesResp *TouchesResponse) (*Config, error)
MergeConfigs creates Config config from "get_user_config" action and "get_system_config" action.
type DisplayType ¶
type DisplayType string
const ( Bit DisplayType = "BIT" Byte DisplayType = "BYTE" Temperature DisplayType = "TEMP" Percentage DisplayType = "PROC" RGB DisplayType = "RGB" )
type GetMyResources ¶
type GetMyResourcesResponse ¶
type GetMyResourcesResponse struct { ActionName string `json:"action_name"` RequestToken string `json:"request_token"` Status string `json:"status"` Source string `json:"source"` AvatarID0 string `json:"avatar_id_0"` FriendlyName0 string `json:"friendly_name_0"` ResourceType0 string `json:"resource_type_0"` UniqueID0 string `json:"unique_id_0"` }
type GetUserConfigResponse ¶
type Message ¶
type Message struct { ActionName string `json:"action_name"` RequestToken *string `json:"request_token"` Status *string `json:"status"` Raw []byte }
Message is a websocket message sent from the client to the server.
Messages are most commonly used to make server do perform something, e.g., change the status of some resource/device.
type MobileDisplayCell ¶
type MobileDisplayCell struct { // Cell description. Note that this is by the configurator app, not by the // user in the mobile or web app. Desc string `json:"CD"` // Object ID ID string `json:"OI"` // Type number. Known values: 706, 707, 708, 709, 710, 711, 717, 718, 719, // 722, 724, 760 TypeNumber string `json:"TN"` // Preset. Known values: 0, 1, 4 Preset string `json:"P"` // Style. Display Type TEMP always has this set to 2. Style string `json:"Se"` // Minimum value MinValue string `json:"Min"` // Maximum value MaxValue string `json:"Max"` // Step (aka current value). Display Type TEMP always has this set to // 0xa005. Step string `json:"Sp"` // Display Type. DisplayType DisplayType `json:"DT"` // Cell permission. Known values: FC (Full Control), RO (Read-Only) Permission string `json:"CP"` }
MobileDisplayCell is a Cell but returned from "touches" action.
func (MobileDisplayCell) String ¶
func (cell MobileDisplayCell) String() string
type OpenClientSession ¶
type PositionInPanel ¶
type PositionInPanel struct { Orientation string `json:"orientation"` PanelID string `json:"panelId"` X int `json:"x"` Y int `json:"y"` }
func (PositionInPanel) String ¶
func (p PositionInPanel) String() string
type Response ¶
type Response struct { ActionName string `json:"action_name"` RequestToken string `json:"request_token"` Status string `json:"status"` Source string `json:"source"` Details string `json:"details"` // Non-empty for "disconnecting" action Reason string `json:"reason"` // Non-empty for "disconnecting" action }
Response is a websocket message sent from the server to the client in response to the client's previous websocket message to the server.
type StatusTouchesChangedResponse ¶
type StatusTouchesChangedResponse struct { ActionName string `json:"action_name"` Response struct { ProjectVersion string `json:"ProjectVersion"` Status bool `json:"Status"` StatusText string `json:"StatusText"` CellValues []CellValue `json:"CV"` ServerTime int `json:"ServerTime"` } `json:"response"` Status string `json:"status"` Source string `json:"source"` }
type TouchesResponse ¶
type TouchesResponse struct { ActionName string `json:"action_name"` Response struct { ProjectVersion string `json:"ProjectVersion"` Status bool `json:"Status"` StatusText string `json:"StatusText"` MobileDisplayProperties struct { Cells []MobileDisplayCell `json:"Cells"` } `json:"MobileDisplayProperties"` } `json:"response"` Status string `json:"status"` Source string `json:"source"` RequestToken string `json:"request_token"` }
type UserCell ¶
type UserCell struct { ObjectID int `json:"objectId"` Icon string `json:"icon"` Name string `json:"name"` PositionInPanel []PositionInPanel `json:"positionInPanel"` }
type UserConfig ¶
type UserConfig struct { Cells []UserCell `json:"cells"` Panels []UserPanel `json:"panels"` Server struct { ProjectVersion string `json:"projectVersion"` } `json:"server"` }
func (*UserConfig) GetCellsByPanelID ¶
func (f *UserConfig) GetCellsByPanelID(id string) []UserCell