You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
6.6 KiB

  1. package hue
  2. import (
  3. "encoding/xml"
  4. "errors"
  5. )
  6. type DiscoveryEntry struct {
  7. Id string `json:"id"`
  8. InternalIPAddress string `json:"internalipaddress"`
  9. }
  10. type CreateUserInput struct {
  11. DeviceType string `json:"devicetype"`
  12. }
  13. type CreateUserResponse struct {
  14. Success *struct {
  15. Username string `json:"username"`
  16. } `json:"success"`
  17. Error *struct {
  18. Type int `json:"type"`
  19. Address string `json:"address"`
  20. Description string `json:"description"`
  21. } `json:"error"`
  22. }
  23. type Overview struct {
  24. Lights map[int]LightData `json:"lights"`
  25. Config BridgeConfig `json:"config"`
  26. Sensors map[int]SensorData `json:"sensors"`
  27. }
  28. type BridgeConfig struct {
  29. Name string `json:"name"`
  30. ZigbeeChannel int `json:"zigbeechannel"`
  31. BridgeID string `json:"bridgeid"`
  32. Mac string `json:"mac"`
  33. DHCP bool `json:"dhcp"`
  34. IPAddress string `json:"ipaddress"`
  35. NetMask string `json:"netmask"`
  36. Gateway string `json:"gateway"`
  37. ProxyAddress string `json:"proxyaddress"`
  38. ProxyPort int `json:"proxyport"`
  39. UTC string `json:"UTC"`
  40. LocalTime string `json:"localtime"`
  41. TimeZone string `json:"timezone"`
  42. ModelID string `json:"modelid"`
  43. DataStoreVersion string `json:"datastoreversion"`
  44. SWVersion string `json:"swversion"`
  45. APIVersion string `json:"apiversion"`
  46. LinkButton bool `json:"linkbutton"`
  47. PortalServices bool `json:"portalservices"`
  48. PortalConnection string `json:"portalconnection"`
  49. FactoryNew bool `json:"factorynew"`
  50. StarterKitID string `json:"starterkitid"`
  51. Whitelist map[string]WhitelistEntry `json:"whitelist"`
  52. }
  53. type LightState struct {
  54. On bool `json:"on"`
  55. Bri int `json:"bri"`
  56. Hue int `json:"hue"`
  57. Sat int `json:"sat"`
  58. Effect string `json:"effect"`
  59. XY []float64 `json:"xy"`
  60. CT int `json:"ct"`
  61. Alert string `json:"alert"`
  62. ColorMode string `json:"colormode"`
  63. Mode string `json:"mode"`
  64. Reachable bool `json:"reachable"`
  65. }
  66. type LightStateInput struct {
  67. On *bool `json:"on,omitempty"`
  68. Bri *int `json:"bri,omitempty"`
  69. Hue *int `json:"hue,omitempty"`
  70. Sat *int `json:"sat,omitempty"`
  71. Effect *string `json:"effect,omitempty"`
  72. XY *[2]float64 `json:"xy,omitempty"`
  73. CT *int `json:"ct,omitempty"`
  74. Alert *string `json:"alert,omitempty"`
  75. TransitionTime *int `json:"transitiontime,omitempty"`
  76. }
  77. type LightData struct {
  78. State LightState `json:"state"`
  79. Type string `json:"type"`
  80. Name string `json:"name"`
  81. Modelid string `json:"modelid"`
  82. Manufacturername string `json:"manufacturername"`
  83. Productname string `json:"productname"`
  84. Capabilities struct {
  85. Certified bool `json:"certified"`
  86. Control struct {
  87. Mindimlevel int `json:"mindimlevel"`
  88. Maxlumen int `json:"maxlumen"`
  89. Colorgamuttype string `json:"colorgamuttype"`
  90. Colorgamut [][]float64 `json:"colorgamut"`
  91. CT struct {
  92. Min int `json:"min"`
  93. Max int `json:"max"`
  94. } `json:"ct"`
  95. } `json:"control"`
  96. Streaming struct {
  97. Renderer bool `json:"renderer"`
  98. Proxy bool `json:"proxy"`
  99. } `json:"streaming"`
  100. } `json:"capabilities"`
  101. Config struct {
  102. Archetype string `json:"archetype"`
  103. Function string `json:"function"`
  104. Direction string `json:"direction"`
  105. Startup struct {
  106. Mode string `json:"mode"`
  107. Configured bool `json:"configured"`
  108. } `json:"startup"`
  109. } `json:"config"`
  110. Swupdate struct {
  111. State string `json:"state"`
  112. Lastinstall string `json:"lastinstall"`
  113. } `json:"swupdate"`
  114. Uniqueid string `json:"uniqueid"`
  115. Swversion string `json:"swversion"`
  116. Swconfigid string `json:"swconfigid"`
  117. Productid string `json:"productid"`
  118. }
  119. type SensorData struct {
  120. State struct {
  121. Daylight interface{} `json:"daylight"`
  122. ButtonEvent int `json:"buttonevent"`
  123. LastUpdated string `json:"lastupdated"`
  124. Presence bool `json:"presence"`
  125. } `json:"state"`
  126. Config struct {
  127. On bool `json:"on"`
  128. Configured bool `json:"configured"`
  129. Sunriseoffset int `json:"sunriseoffset"`
  130. Sunsetoffset int `json:"sunsetoffset"`
  131. } `json:"config"`
  132. Name string `json:"name"`
  133. Type string `json:"type"`
  134. Modelid string `json:"modelid"`
  135. Manufacturername string `json:"manufacturername"`
  136. Productname string `json:"productname"`
  137. Swversion string `json:"swversion"`
  138. UniqueID string `json:"uniqueid"`
  139. }
  140. type WhitelistEntry struct {
  141. LastUseDate string `json:"last use date"`
  142. CreateDate string `json:"create date"`
  143. Name string `json:"name"`
  144. }
  145. type BridgeDeviceInfo struct {
  146. XMLName xml.Name `xml:"root"`
  147. Text string `xml:",chardata"`
  148. Xmlns string `xml:"xmlns,attr"`
  149. SpecVersion struct {
  150. Text string `xml:",chardata"`
  151. Major string `xml:"major"`
  152. Minor string `xml:"minor"`
  153. } `xml:"specVersion"`
  154. URLBase string `xml:"URLBase"`
  155. Device struct {
  156. Text string `xml:",chardata"`
  157. DeviceType string `xml:"deviceType"`
  158. FriendlyName string `xml:"friendlyName"`
  159. Manufacturer string `xml:"manufacturer"`
  160. ManufacturerURL string `xml:"manufacturerURL"`
  161. ModelDescription string `xml:"modelDescription"`
  162. ModelName string `xml:"modelName"`
  163. ModelNumber string `xml:"modelNumber"`
  164. ModelURL string `xml:"modelURL"`
  165. SerialNumber string `xml:"serialNumber"`
  166. UDN string `xml:"UDN"`
  167. PresentationURL string `xml:"presentationURL"`
  168. IconList struct {
  169. Text string `xml:",chardata"`
  170. Icon struct {
  171. Text string `xml:",chardata"`
  172. Mimetype string `xml:"mimetype"`
  173. Height string `xml:"height"`
  174. Width string `xml:"width"`
  175. Depth string `xml:"depth"`
  176. URL string `xml:"url"`
  177. } `xml:"icon"`
  178. } `xml:"iconList"`
  179. } `xml:"device"`
  180. }
  181. var buttonNames = []string{"On", "DimUp", "DimDown", "Off"}
  182. var errLinkButtonNotPressed = errors.New("link button not pressed")