| | |
| | | package com.battery.device.model; |
| | | |
| | | import java.time.Instant; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | /** 厂商无关的一次通道观测结果。不得携带测试、持久化或传输层对象。 */ |
| | | public record DeviceObservation( |
| | |
| | | channelWorkStatus = channelWorkStatus == null ? DeviceWorkStatus.UNOBSERVABLE : channelWorkStatus; |
| | | plannedSteps = plannedSteps == null ? List.of() : List.copyOf(plannedSteps); |
| | | measurements = measurements == null ? Map.of() : Map.copyOf(measurements); |
| | | failureReason = failureReason; |
| | | if (connectionStatus == DeviceConnectionStatus.ONLINE && failureReason != null) |
| | | throw new IllegalArgumentException("online observation cannot contain a failure reason"); |
| | | } |
| | |
| | | if (value != null) measurements.putIfAbsent(code, new Measurement(code, value, null, unit, "DEVICE")); |
| | | } |
| | | |
| | | /** 返回本次观测是否确认设备在线。 */ |
| | | public boolean online() |
| | | { |
| | | return connectionStatus == DeviceConnectionStatus.ONLINE; |
| | |
| | | return channelWorkStatus; |
| | | } |
| | | |
| | | /** 创建不携带过期设备事实的离线观测。 */ |
| | | public static DeviceObservation offline(ChannelIdentity channel, String failureReason) |
| | | { |
| | | Objects.requireNonNull(channel, "channel"); |