zaphyra's git: airpodsctl

Control and monitor your AirPods

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
package types

import (
	"encoding/json"
	"fmt"

	"git.zaphyra.eu/airpodsctl/helpers"
)

type BatteryTTLEstimate Option[int]

func (s *BatteryTTLEstimate) UnmarshalJSON(data []byte) error {
	var v Option[int]
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	*s = BatteryTTLEstimate{
		Set:   v.Set,
		Valid: v.Valid,
		Value: v.Value,
	}

	return nil
}

func (batteryTTLEstimate BatteryTTLEstimate) String() string {
	if batteryTTLEstimate.Valid {
		hours, minutes := helpers.Divmod(batteryTTLEstimate.Value, 60)
		return fmt.Sprintf("%dh %dm", hours, minutes)
	}

	return ""
}