device.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package zigbee2mqtt
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. type hex int
  7. /* {
  8. "ieee_address":"0x00158d00018255df",
  9. "type":"Router",
  10. "network_address":29159,
  11. "supported":true,
  12. "disabled": false,
  13. "friendly_name":"my_plug",
  14. "description":"this plug is in the kitchen",
  15. "endpoints":{"1":{"bindings":[],"configured_reportings":[],"clusters":{"input":["genOnOff","genBasic"],"output":[]}}},
  16. "definition":{
  17. "model":"ZNCZ02LM",
  18. "vendor":"Xiaomi",
  19. "description":"Mi power plug ZigBee",
  20. "options": [...], // see exposes/options below
  21. "exposes": [...] // see exposes/options below
  22. },
  23. "power_source":"Mains (single phase)",
  24. "date_code":"02-28-2017",
  25. "model_id":"lumi.plug",
  26. "scenes": [{"id": 3, "name": "Chill scene"}],
  27. "interviewing":false,
  28. "interview_completed":true
  29. }, */
  30. /*
  31. "exposes": [{
  32. "access": 1,
  33. "description": "Remaining battery in %",
  34. "name": "battery",
  35. "property": "battery",
  36. "type": "numeric",
  37. "unit": "%",
  38. "value_max": 100,
  39. "value_min": 0
  40. }
  41. */
  42. type expose struct {
  43. Access int
  44. Description string
  45. Name string
  46. Property string
  47. Type string
  48. Unit string
  49. Value_max int
  50. Value_min int
  51. }
  52. /*
  53. "target": {
  54. "endpoint": 1,
  55. "ieee_address": "0x00124b00229884d8",
  56. "type": "endpoint"
  57. }
  58. */
  59. type target struct {
  60. Endpoint int
  61. Ieee_address string
  62. Type string
  63. }
  64. /*
  65. "bindings": [{
  66. "cluster": "genPowerCfg",
  67. "target": {
  68. "endpoint": 1,
  69. "ieee_address": "0x00124b00229884d8",
  70. "type": "endpoint"
  71. }
  72. },
  73. */
  74. type binding struct {
  75. Cluster string
  76. Target target
  77. }
  78. /*
  79. "clusters": {
  80. "input": ["genBasic", "genPowerCfg", "genPollCtrl", "touchlink", "64768"],
  81. "output": ["genIdentify", "genGroups", "genScenes", "genOnOff", "genLevelCtrl", "genOta", "lightingColorCtrl", "touchlink"]
  82. },
  83. */
  84. type clusters struct {
  85. Input []string
  86. Output []string
  87. }
  88. /*
  89. "configured_reportings": [{
  90. "attribute": "batteryVoltage",
  91. "cluster": "genPowerCfg",
  92. "maximum_report_interval": 62000,
  93. "minimum_report_interval": 3600,
  94. "reportable_change": 0
  95. }],
  96. */
  97. type reportings struct {
  98. Attribute string
  99. Cluster string
  100. Maximum_report_interval int
  101. Minimum_report_interval json.Number
  102. Reportable_change int
  103. }
  104. /*
  105. "scenes": []
  106. */
  107. type endpoint struct {
  108. Bindings []binding
  109. Configured_reportings []reportings
  110. // Scenes: []
  111. Scenes []string
  112. }
  113. type definition struct {
  114. Description string
  115. Exposes []expose
  116. }
  117. type device struct {
  118. Date_code string
  119. Disabled bool
  120. Friendly_name string
  121. Ieee_address string
  122. Interview_completed bool
  123. Interviewing bool
  124. Manufacturer string
  125. Model_id string
  126. Network_address int
  127. Power_source string
  128. Software_build_id string
  129. Supported bool
  130. Type string
  131. Endpoints map[string]endpoint
  132. Clusters clusters
  133. Definition definition
  134. }
  135. type Builder func([]byte)
  136. func Build(data []byte) []device {
  137. var arr []device
  138. err := json.Unmarshal(data, &arr)
  139. fmt.Println("connectors/zigbee2mqtt/device/builder")
  140. if err != nil {
  141. panic(err)
  142. }
  143. fmt.Println(arr)
  144. for _, s := range arr {
  145. fmt.Println(s)
  146. }
  147. return arr
  148. }