-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct.go
77 lines (69 loc) · 2.53 KB
/
struct.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"lib.hemtjan.st/device"
"lib.hemtjan.st/feature"
)
// Config is the basic struct for the HCL parser, it has a map of devices and a mqtt config
type Config struct {
Device map[string]*DeviceConfig `json:"device"`
}
// DeviceConfig contains meta-data for a device and it's features
type DeviceConfig struct {
// Name as exposed to Hemtjänst/homekit, required
Name string `json:"name"`
// Manufacturer as exposed to Hemtjänst, optional
Manufacturer string `json:"manufacturer"`
// Model as exposed to Hemtjänst, optional
Model string `json:"model"`
// SerialNumber as exposed to Hemtjänst, optional
SerialNumber string `json:"serialNumber"`
// Type must be a valid homekit type, see Hemtjänst documentation for valid types
Type string `json:"type"`
Feature map[string]*DeviceFeature `json:"feature"`
}
func (d *DeviceConfig) DeviceInfo(topic string) *device.Info {
i := &device.Info{
Topic: topic,
Name: d.Name,
Type: d.Type,
Manufacturer: d.Manufacturer,
Model: d.Model,
SerialNumber: d.SerialNumber,
Features: map[string]*feature.Info{},
}
for name, ft := range d.Feature {
if ft.Info == nil {
ft.Info = &feature.Info{}
}
i.Features[name] = ft.Info
}
return i
}
// DeviceFeature reflects a homekit characteristic
type DeviceFeature struct {
// Info contains hemtjänst-specific settings like what topics to use and what the min/max/step values are
Info *feature.Info
// GpioIn is the configuration for reading from GPIO to MQTT
GpioIn *GpioReaderCfg `json:"gpioIn"`
// GpioOut is the configuration for writing to GPIO from MQTT
GpioOut *GpioWriterCfg `json:"gpioOut"`
}
// GpioReaderCfg sets configuration values for the GpioReader instance
type GpioReaderCfg struct {
// Pin number (according to BCM2835 pinout
Pin int `json:"pin"`
// Invert the reading, if true then "1" is sent as "0" to MQTT
Invert bool `json:"invert"`
// ReadInterval defines the time (in milliseconds) between reads
ReadInterval int64 `json:"readInterval"`
// ConsecutiveReadsForOpenState specifies the number of reads with same value before a open state is reported
MinReadOpened int64 `json:"minReadOpened"`
// ConsecutiveReadsForCloseState specifies the number of reads with same value before a close state is reported
MinReadClosed int64 `json:"minReadClosed"`
}
type GpioWriterCfg struct {
// Pin number (according to BCM2835 pinout
Pin int `json:"pin"`
// Invert the reading, if true then "1" from MQTT sets the GPIO to High
Invert bool `json:"invert"`
}