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.

71 lines
1.7 KiB

package common_models
import (
"encoding/json"
"fmt"
)
type DeviceMeta struct {
Id string `json:"id"`
Name string `json:"name"`
Model string `json:"model"`
Properties []iotaProperty `json:"properties"`
Capabilities []iotaCapability `json:"capabilities"`
}
// "meta" : {
// "windspeed" : "风速(m/s)",
// "pm25" : "PM2.5(ug/m³)",
// "pm10" : "PM10(ug/m³)",
// "noise" : "噪声(db)",
// "winddir" : "风向(°)",
// "humidity" : "湿度(%)",
// "temp" : "温度(℃)"
// }
func (m *DeviceMeta) GetOutputProps() (out map[string]string) {
out = make(map[string]string)
if len(m.Capabilities) == 0 {
return
}
for _, property := range m.Capabilities[0].Properties {
info := fmt.Sprintf("%s(%s)", property.ShowName, property.Unit)
out[property.Name] = info
}
return
}
func (m *DeviceMeta) GetOutputUnit() (out map[string]string) {
out = make(map[string]string)
if len(m.Capabilities) == 0 {
return
}
for _, property := range m.Capabilities[0].Properties {
out[property.Name] = property.Unit
}
return
}
// redis序列化
func (m *DeviceMeta) MarshalBinary() (data []byte, err error) {
return json.Marshal(m)
}
// redis序列化
func (m *DeviceMeta) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}
type iotaCapability struct {
CapabilityCategoryId int `json:"capabilityCategoryId"`
Id string `json:"id"`
Name string `json:"name"`
Properties []iotaProperty `json:"properties"`
}
type iotaProperty struct {
Category string `json:"category"`
Name string `json:"name"`
ShowName string `json:"showName"`
Unit string `json:"unit"`
}