Commit 24ebc06fa4b70c06d40eb89141e7ce5d0714efde

Authored by YevhenBondarenko
1 parent c1223b0c

process ALARM_ACK msg in device state

... ... @@ -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");
... ...