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

package device
import (
"fmt"
"git.aiterp.net/lucifer3/server/internal/color"
"strings"
)
type State struct {
Power *bool `json:"power"`
Temperature *float64 `json:"temperature"`
Intensity *float64 `json:"intensity"`
Color *color.Color `json:"color"`
SensedTemperature *float64 `json:"sensedTemperature"`
SensedLightLevel *float64 `json:"sensedLightLevel"`
SensedPresence *PresenceState `json:"sensedPresence"`
SensedButton *int `json:"sensedButton"`
}
func (d State) String() string {
parts := make([]string, 0, 4)
if d.Power != nil {
parts = append(parts, fmt.Sprintf("power:%t", *d.Power))
}
if d.Temperature != nil {
parts = append(parts, fmt.Sprintf("temperature:%f", *d.Temperature))
}
if d.Intensity != nil {
parts = append(parts, fmt.Sprintf("intensity:%.2f", *d.Intensity))
}
if d.Color != nil {
parts = append(parts, fmt.Sprintf("color:%s", d.Color.String()))
}
if d.SensedTemperature != nil {
parts = append(parts, fmt.Sprintf("sensedTemperature:%.2f", *d.SensedTemperature))
}
if d.SensedLightLevel != nil {
parts = append(parts, fmt.Sprintf("sensedLightLevel:%.1f", *d.SensedLightLevel))
}
if d.SensedPresence != nil {
parts = append(parts, fmt.Sprintf("sensedPresense:(%t,%.1f)", d.SensedPresence.Present, d.SensedPresence.AbsenceSeconds))
}
if d.SensedButton != nil {
parts = append(parts, fmt.Sprintf("sensedButton:%d", *d.SensedButton))
}
return fmt.Sprint("(", strings.Join(parts, ", "), ")")
}
type PresenceState struct {
Present bool `json:"present"`
AbsenceSeconds float64 `json:"absenceSeconds,omitempty"`
}