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.

55 lines
1.6 KiB

  1. package device
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/internal/color"
  5. "strings"
  6. )
  7. type State struct {
  8. Power *bool `json:"power"`
  9. Temperature *float64 `json:"temperature"`
  10. Intensity *float64 `json:"intensity"`
  11. Color *color.Color `json:"color"`
  12. SensedTemperature *float64 `json:"sensedTemperature"`
  13. SensedLightLevel *float64 `json:"sensedLightLevel"`
  14. SensedPresence *PresenceState `json:"sensedPresence"`
  15. SensedButton *int `json:"sensedButton"`
  16. }
  17. func (d State) String() string {
  18. parts := make([]string, 0, 4)
  19. if d.Power != nil {
  20. parts = append(parts, fmt.Sprintf("power:%t", *d.Power))
  21. }
  22. if d.Temperature != nil {
  23. parts = append(parts, fmt.Sprintf("temperature:%f", *d.Temperature))
  24. }
  25. if d.Intensity != nil {
  26. parts = append(parts, fmt.Sprintf("intensity:%.2f", *d.Intensity))
  27. }
  28. if d.Color != nil {
  29. parts = append(parts, fmt.Sprintf("color:%s", d.Color.String()))
  30. }
  31. if d.SensedTemperature != nil {
  32. parts = append(parts, fmt.Sprintf("sensedTemperature:%.2f", *d.SensedTemperature))
  33. }
  34. if d.SensedLightLevel != nil {
  35. parts = append(parts, fmt.Sprintf("sensedLightLevel:%.1f", *d.SensedLightLevel))
  36. }
  37. if d.SensedPresence != nil {
  38. parts = append(parts, fmt.Sprintf("sensedPresense:(%t,%.1f)", d.SensedPresence.Present, d.SensedPresence.AbsenceSeconds))
  39. }
  40. if d.SensedButton != nil {
  41. parts = append(parts, fmt.Sprintf("sensedButton:%d", *d.SensedButton))
  42. }
  43. return fmt.Sprint("(", strings.Join(parts, ", "), ")")
  44. }
  45. type PresenceState struct {
  46. Present bool `json:"present"`
  47. AbsenceSeconds float64 `json:"absenceSeconds,omitempty"`
  48. }