Commit 1db24fbd52069bbaed4286ee6ef45145d1772ca6
Committed by
GitHub
Merge pull request #3970 from YevhenBondarenko/fix-device-state
process ALARM_ACK msg in device state
Showing
2 changed files
with
19 additions
and
0 deletions
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/AlarmState.java
... | ... | @@ -291,4 +291,11 @@ class AlarmState { |
291 | 291 | } |
292 | 292 | return updated; |
293 | 293 | } |
294 | + | |
295 | + public void processAckAlarm(Alarm alarm) { | |
296 | + if (currentAlarm != null && currentAlarm.getId().equals(alarm.getId())) { | |
297 | + currentAlarm.setStatus(alarm.getStatus()); | |
298 | + currentAlarm.setAckTs(alarm.getAckTs()); | |
299 | + } | |
300 | + } | |
294 | 301 | } | ... | ... |
... | ... | @@ -140,6 +140,8 @@ class DeviceState { |
140 | 140 | stateChanged = processAttributesDeleteNotification(ctx, msg); |
141 | 141 | } else if (msg.getType().equals(DataConstants.ALARM_CLEAR)) { |
142 | 142 | stateChanged = processAlarmClearNotification(ctx, msg); |
143 | + } else if (msg.getType().equals(DataConstants.ALARM_ACK)) { | |
144 | + processAlarmAckNotification(ctx, msg); | |
143 | 145 | } else { |
144 | 146 | ctx.tellSuccess(msg); |
145 | 147 | } |
... | ... | @@ -161,6 +163,16 @@ class DeviceState { |
161 | 163 | return stateChanged; |
162 | 164 | } |
163 | 165 | |
166 | + private void processAlarmAckNotification(TbContext ctx, TbMsg msg) { | |
167 | + Alarm alarmNf = JacksonUtil.fromString(msg.getData(), Alarm.class); | |
168 | + for (DeviceProfileAlarm alarm : deviceProfile.getAlarmSettings()) { | |
169 | + AlarmState alarmState = alarmStates.computeIfAbsent(alarm.getId(), | |
170 | + a -> new AlarmState(this.deviceProfile, deviceId, alarm, getOrInitPersistedAlarmState(alarm))); | |
171 | + alarmState.processAckAlarm(alarmNf); | |
172 | + } | |
173 | + ctx.tellSuccess(msg); | |
174 | + } | |
175 | + | |
164 | 176 | private boolean processAttributesUpdateNotification(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException { |
165 | 177 | Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(msg.getData())); |
166 | 178 | String scope = msg.getMetaData().getValue("scope"); | ... | ... |