[优化] 设置状态监控

This commit is contained in:
PandaX-Go
2024-12-04 21:47:24 +08:00
parent 7c021f8be9
commit ffe6e859af
18 changed files with 314 additions and 410 deletions

View File

@@ -1,40 +1,30 @@
package shadow
import (
"pandax/apps/device/services"
"pandax/pkg/global"
"time"
)
// Device 设备结构
type Device struct {
Name string // 设备名称
ProductName string // 设备模型名称
AttributesPoints map[string]DevicePoint // 设备属性点位列表 key 作为属性
TelemetryPoints map[string]DevicePoint // 设备遥测点位列表 key 作为属性
online bool // 在线状态
updatedAt time.Time // 更新时间
Name string // 设备名称
online bool // 在线状态
updatedAt time.Time // 更新时间
}
// DevicePoint 设备点位结构
type DevicePoint struct {
Name string // 点位名称
Value interface{} // 点位值
UpdatedAt time.Time
}
func NewDevice(deviceName string, productName string, attributes, telemetry map[string]DevicePoint) Device {
func NewDevice(deviceName string) Device {
return Device{
Name: deviceName,
ProductName: productName,
AttributesPoints: attributes,
TelemetryPoints: telemetry,
online: true,
Name: deviceName,
online: true,
updatedAt: time.Now(),
}
}
func NewDevicePoint(pointName string, value interface{}) DevicePoint {
return DevicePoint{
Name: pointName,
Value: value,
UpdatedAt: time.Now(),
func deviceHandler(deviceName string, online bool) {
if online {
services.DeviceModelDao.UpdateStatus(deviceName, global.ONLINE)
} else {
services.DeviceModelDao.UpdateStatus(deviceName, global.OFFLINE)
}
}