-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_source_hue_sensor.go
55 lines (44 loc) · 1.07 KB
/
data_source_hue_sensor.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
package hue
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/lawsontyler/ghue/sdk/common"
"github.com/lawsontyler/ghue/sdk/sensors"
)
func dataSourceHueSensor() *schema.Resource {
return &schema.Resource{
Read: dataSourceHueSensorRead,
Schema: map[string]*schema.Schema {
"name": {
Type: schema.TypeString,
ConflictsWith: []string{"sensor_id"},
Optional: true,
},
"sensor_id": {
Type: schema.TypeString,
ConflictsWith: []string{"name"},
Optional: true,
},
},
}
}
func dataSourceHueSensorRead(d *schema.ResourceData, meta interface{}) error {
connection := meta.(*common.Connection)
sensorName := d.Get("name")
sensorId := d.Get("sensor_id")
if sensorId != nil {
sensorId := sensorId.(string)
_, _, err := sensors.GetSensor(connection, sensorId)
if err != nil {
return err
}
d.SetId(sensorId)
} else if sensorName != nil {
sensorName := sensorName.(string)
sensorId, _, err := sensors.GetSensorIdByName(connection, sensorName)
if err != nil {
return err
}
d.SetId(sensorId)
}
return nil
}