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.

197 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. Temperature int
  126. } `json:"state"`
  127. Config struct {
  128. On bool `json:"on"`
  129. Configured bool `json:"configured"`
  130. Sunriseoffset int `json:"sunriseoffset"`
  131. Sunsetoffset int `json:"sunsetoffset"`
  132. } `json:"config"`
  133. Name string `json:"name"`
  134. Type string `json:"type"`
  135. Modelid string `json:"modelid"`
  136. Manufacturername string `json:"manufacturername"`
  137. Productname string `json:"productname"`
  138. Swversion string `json:"swversion"`
  139. UniqueID string `json:"uniqueid"`
  140. }
  141. type WhitelistEntry struct {
  142. LastUseDate string `json:"last use date"`
  143. CreateDate string `json:"create date"`
  144. Name string `json:"name"`
  145. }
  146. type BridgeDeviceInfo struct {
  147. XMLName xml.Name `xml:"root"`
  148. Text string `xml:",chardata"`
  149. Xmlns string `xml:"xmlns,attr"`
  150. SpecVersion struct {
  151. Text string `xml:",chardata"`
  152. Major string `xml:"major"`
  153. Minor string `xml:"minor"`
  154. } `xml:"specVersion"`
  155. URLBase string `xml:"URLBase"`
  156. Device struct {
  157. Text string `xml:",chardata"`
  158. DeviceType string `xml:"deviceType"`
  159. FriendlyName string `xml:"friendlyName"`
  160. Manufacturer string `xml:"manufacturer"`
  161. ManufacturerURL string `xml:"manufacturerURL"`
  162. ModelDescription string `xml:"modelDescription"`
  163. ModelName string `xml:"modelName"`
  164. ModelNumber string `xml:"modelNumber"`
  165. ModelURL string `xml:"modelURL"`
  166. SerialNumber string `xml:"serialNumber"`
  167. UDN string `xml:"UDN"`
  168. PresentationURL string `xml:"presentationURL"`
  169. IconList struct {
  170. Text string `xml:",chardata"`
  171. Icon struct {
  172. Text string `xml:",chardata"`
  173. Mimetype string `xml:"mimetype"`
  174. Height string `xml:"height"`
  175. Width string `xml:"width"`
  176. Depth string `xml:"depth"`
  177. URL string `xml:"url"`
  178. } `xml:"icon"`
  179. } `xml:"iconList"`
  180. } `xml:"device"`
  181. }
  182. var buttonNames = []string{"On", "DimUp", "DimDown", "Off"}
  183. var errLinkButtonNotPressed = errors.New("link button not pressed")