|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeviceInfo struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Structure Structure `json:"structure"`
|
|
|
|
DeviceMeta DeviceMeta `json:"device_meta"`
|
|
|
|
RefreshTime time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeviceMeta struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Model string `json:"model"`
|
|
|
|
Properties []IotaProperty `json:"properties"`
|
|
|
|
Capabilities []IotaCapability `json:"capabilities"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|