优化代码
This commit is contained in:
@@ -57,7 +57,7 @@ func (g *GeneralDeviceService) Switch(device *models.Device, action DeviceAction
|
||||
return fmt.Errorf("解析设备 %v(id=%v) 配置失败: %v", device.Name, device.ID, err)
|
||||
}
|
||||
|
||||
// TODO 这种校验放自检里 (已通过 SelfCheck 保证其为纯数字,此处仅进行类型转换)
|
||||
// 已通过 SelfCheck 保证其为纯数字,此处仅进行类型转换
|
||||
busNumber, _ := strconv.Atoi(fmt.Sprintf("%v", deviceInfo[models.BusNumber]))
|
||||
busAddress, _ := strconv.Atoi(fmt.Sprintf("%v", deviceInfo[models.BusAddress]))
|
||||
relayChannel, _ := strconv.Atoi(fmt.Sprintf("%v", deviceInfo[models.RelayChannel]))
|
||||
|
||||
@@ -118,7 +118,6 @@ func (d *Device) ParseProperties(v interface{}) error {
|
||||
|
||||
// SelfCheck 进行参数自检, 返回检测结果
|
||||
// 方法会根据自身类型进行参数检查, 参数不全时返回false
|
||||
// TODO 没写单测
|
||||
func (d *Device) SelfCheck() bool {
|
||||
// 使用清晰的 switch 结构,确保所有情况都被覆盖
|
||||
switch d.Type {
|
||||
|
||||
@@ -64,7 +64,7 @@ func (c *ChirpStackTransport) Send(address string, payload []byte) (*transport.S
|
||||
// - WithQueueItemDevEui 指定目标设备的 EUI。
|
||||
// - WithBody 设置请求体。
|
||||
params := device_service.NewDeviceServiceEnqueueParams().
|
||||
WithTimeout(5 * time.Second). // TODO 这里应该从配置文件里读
|
||||
WithTimeout(time.Duration(c.config.APITimeout) * time.Second).
|
||||
WithQueueItemDevEui(address).
|
||||
WithBody(body)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user