-func (nsi SpaceInfo) UpdateSensorData(what, where, value string) {
- if nsi["sensors"] == nil {
- sensorlist := make([]SpaceInfo, 1)
- sensorlist[0] = SpaceInfo{what: SpaceInfo{where: value}}
- nsi["sensors"] = sensorlist
- } else {
- sensorlist, ok := nsi["sensors"].([]SpaceInfo) //type assertion (panics if false)
- if ok {
- for _, sensor := range sensorlist {
- if sensor[what] != nil {
- sensorinfo, ok2 := sensor[what].(SpaceInfo)
- if ok2 {
- sensorinfo[where] = value
- return
- } else {
- panic("Wrong Type of sensorinfo: Should never happen")
- }
- }
- }
- //else
- nsi["sensors"] = append(sensorlist, SpaceInfo{what: SpaceInfo{where: value}})
- } else {
- panic("Wrong Type of sensorlist: Should never happen")
- }
+type SpaceDoorLockSensor struct {
+ value bool
+ location string
+ name string
+ description string
+}
+
+type SpaceDoorAjarSensor struct {
+ value bool
+ location string
+ name string
+ description string
+}
+
+func MakeTempSensor(name, where, unit string, value float64) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "unit": unit,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"temperature": listofwhats}
+}
+
+func MakeTempCSensor(name, where string, value float64) SpaceInfo {
+ return MakeTempSensor(name,where,"\u00b0C",value)
+}
+
+func MakeIlluminationSensor(name, where, unit string, value int64) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "unit": unit,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"ext_illumination": listofwhats}
+}
+
+func MakePowerConsumptionSensor(name, where, unit string, value int64) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "unit": unit,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"power_consumption": listofwhats}
+}
+
+func MakeNetworkConnectionsSensor(name, where, nettype string, value, machines int64) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "type": nettype,
+ "machines": machines,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"network_connections": listofwhats}
+}
+
+func MakeMemberCountSensor(name, where string, value int64) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"total_member_count": listofwhats}
+}
+
+func MakeDoorLockSensor(name, where string, value bool) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"door_locked": listofwhats}
+}
+
+func MakeDoorAjarSensor(name, where string, value bool) SpaceInfo {
+ listofwhats := make([]SpaceInfo, 1)
+ listofwhats[0] = SpaceInfo{
+ "value": value,
+ "location": where,
+ "name": name,
+ "description": ""}
+ return SpaceInfo{"ext_door_ajar": listofwhats}
+}
+
+func (nsi SpaceInfo) MergeInSensor(sensorinfo SpaceInfo) {
+ if nsi["sensors"] == nil {
+ nsi["sensors"] = SpaceInfo{}
+ //~ listofwhats := make([]SpaceInfo, 1)
+ //~ listofwhats[0] = sensortype.(SpaceInfo)
+ //~ sensorobj := SpaceInfo{what: listofwhats}
+ //~ nsi["sensors"] = sensorobj