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.

73 lines
15 KiB

  1. package lifx
  2. import "encoding/json"
  3. type ProductMap struct {
  4. Vid uint32 `json:"vid"`
  5. Name string `json:"name"`
  6. Defaults struct {
  7. Hev bool `json:"hev"`
  8. Color bool `json:"color"`
  9. Chain bool `json:"chain"`
  10. Matrix bool `json:"matrix"`
  11. Relays bool `json:"relays"`
  12. Buttons bool `json:"buttons"`
  13. Infrared bool `json:"infrared"`
  14. Multizone bool `json:"multizone"`
  15. TemperatureRange []int `json:"temperature_range"`
  16. ExtendedMultiZone bool `json:"extended_multizone"`
  17. } `json:"defaults"`
  18. Products []ProductMapEntry `json:"products"`
  19. }
  20. type ProductMapEntry struct {
  21. Pid uint32 `json:"pid"`
  22. Name string `json:"name"`
  23. Features struct {
  24. Color bool `json:"color"`
  25. Chain bool `json:"chain"`
  26. Matrix bool `json:"matrix"`
  27. Infrared bool `json:"infrared"`
  28. MultiZone bool `json:"multizone"`
  29. TemperatureRange []int `json:"temperature_range,omitempty"`
  30. MinExtMzFirmware int `json:"min_ext_mz_firmware,omitempty"`
  31. MinExtMzFirmwareComponents []int `json:"min_ext_mz_firmware_components,omitempty"`
  32. Relays bool `json:"relays,omitempty"`
  33. Buttons bool `json:"buttons,omitempty"`
  34. Hev bool `json:"hev,omitempty"`
  35. } `json:"features"`
  36. Upgrades []struct {
  37. Major uint16 `json:"major"`
  38. Minor uint16 `json:"minor"`
  39. Features struct {
  40. TemperatureRange []int `json:"temperature_range,omitempty"`
  41. ExtendedMultizone *bool `json:"extended_multizone,omitempty"`
  42. } `json:"features"`
  43. } `json:"upgrades"`
  44. }
  45. var productMap ProductMap
  46. func findProduct(vendorId uint32, productId uint32) *ProductMapEntry {
  47. if vendorId != productMap.Vid {
  48. return nil
  49. }
  50. for _, entry := range productMap.Products {
  51. if entry.Pid == productId {
  52. return &entry
  53. }
  54. }
  55. return nil
  56. }
  57. func init() {
  58. // Source: https://github.com/LIFX/products
  59. // Commit: 2734460e132dd7ed32c3c0132345a758d47ff80b
  60. err := json.Unmarshal([]byte(`{"vid":1,"name":"LIFX","defaults":{"hev":false,"color":false,"chain":false,"matrix":false,"relays":false,"buttons":false,"infrared":false,"multizone":false,"temperature_range":null,"extended_multizone":false},"products":[{"pid":1,"name":"LIFX Original 1000","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":3,"name":"LIFX Color 650","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":10,"name":"LIFX White 800 (Low Voltage)","features":{"color":false,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2700,6500]},"upgrades":[]},{"pid":11,"name":"LIFX White 800 (High Voltage)","features":{"color":false,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2700,6500]},"upgrades":[]},{"pid":15,"name":"LIFX Color 1000","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":18,"name":"LIFX White 900 BR30 (Low Voltage)","features":{"color":false,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":19,"name":"LIFX White 900 BR30 (High Voltage)","features":{"color":false,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":20,"name":"LIFX Color 1000 BR30","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":22,"name":"LIFX Color 1000","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":27,"name":"LIFX A19","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":28,"name":"LIFX BR30","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":29,"name":"LIFX A19 Night Vision","features":{"color":true,"chain":false,"matrix":false,"infrared":true,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":30,"name":"LIFX BR30 Night Vision","features":{"color":true,"chain":false,"matrix":false,"infrared":true,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":31,"name":"LIFX Z","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":true,"temperature_range":[2500,9000]},"upgrades":[]},{"pid":32,"name":"LIFX Z","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":true,"temperature_range":[2500,9000],"min_ext_mz_firmware":1532997580,"min_ext_mz_firmware_components":[2,77]},"upgrades":[{"major":2,"minor":77,"features":{"extended_multizone":true}},{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":36,"name":"LIFX Downlight","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":37,"name":"LIFX Downlight","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":false,"temperature_range":[2500,9000]},"upgrades":[{"major":2,"minor":80,"features":{"temperature_range":[1500,9000]}}]},{"pid":38,"name":"LIFX Beam","features":{"color":true,"chain":false,"matrix":false,"infrared":false,"multizone":true,"temperature_range":[2500,9000],"min_ext_mz_firmware":1532997580,"min_ext_mz_firmware_components":[2,77]},"upgrades":[{"major":2,"minor":77,"features
  61. if err != nil {
  62. panic(err)
  63. }
  64. }