Skip to content

Commit

Permalink
event should be stored in array for java/android (#22909)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Jan 29, 2024
1 parent 94d4cdd commit 3820435
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ class WildcardFragment : Fragment() {
val attributeName = ChipIdLookup.attributeIdToName(clusterId, attributeId)
stringBuilder.append("\t\t$attributeName: ${attributeState.value}\n")
}
clusterState.eventStates.forEach { (eventId, eventState) ->
stringBuilder.append("\t\teventNumber: ${eventState.eventNumber}\n")
stringBuilder.append("\t\tpriorityLevel: ${eventState.priorityLevel}\n")
stringBuilder.append("\t\tsystemTimeStamp: ${eventState.systemTimeStamp}\n")

val eventName = ChipIdLookup.eventIdToName(clusterId, eventId)
stringBuilder.append("\t\t$eventName: ${eventState.value}\n")
clusterState.eventStates.forEach { (eventId, events) ->
for (event in events)
{
stringBuilder.append("\t\teventNumber: ${event.eventNumber}\n")
stringBuilder.append("\t\tpriorityLevel: ${event.priorityLevel}\n")
stringBuilder.append("\t\tsystemTimeStamp: ${event.systemTimeStamp}\n")

val eventName = ChipIdLookup.eventIdToName(clusterId, eventId)
stringBuilder.append("\t\t$eventName: ${event.value}\n")
}
}
stringBuilder.append("\t}\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
package chip.devicecontroller.model;

import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Map;
import java.util.Optional;

/** Class for tracking CHIP cluster state in a hierarchical manner. */
public final class ClusterState {
private Map<Long, AttributeState> attributes;
private Map<Long, EventState> events;
private Map<Long, ArrayList<EventState>> events;
private Optional<Integer> dataVersion;

public ClusterState(Map<Long, AttributeState> attributes, Map<Long, EventState> events) {
public ClusterState(
Map<Long, AttributeState> attributes, Map<Long, ArrayList<EventState>> events) {
this.attributes = attributes;
this.events = events;
this.dataVersion = Optional.empty();
Expand All @@ -37,7 +39,7 @@ public Map<Long, AttributeState> getAttributeStates() {
return attributes;
}

public Map<Long, EventState> getEventStates() {
public Map<Long, ArrayList<EventState>> getEventStates() {
return events;
}

Expand All @@ -60,12 +62,12 @@ public AttributeState getAttributeState(long attributeId) {
}

/**
* Convenience utility for getting an {@code EventState}.
* Convenience utility for getting an {@code ArrayList<EventState> }.
*
* @return the {@code EventState} for the specified id, or null if not found.
* @return the {@code ArrayList<EventState>} for the specified id, or null if not found.
*/
@Nullable
public EventState getEventState(long eventId) {
public ArrayList<EventState> getEventState(long eventId) {
return events.get(eventId);
}

Expand All @@ -82,12 +84,16 @@ public String toString() {
builder.append("\n");
});
events.forEach(
(eventId, eventState) -> {
builder.append("Event ");
builder.append(eventId);
builder.append(": ");
builder.append(eventState.getValue() == null ? "null" : eventState.getValue().toString());
builder.append("\n");
(eventId, eventStates) -> {
eventStates.forEach(
(eventState) -> {
builder.append("Event ");
builder.append(eventId);
builder.append(": ");
builder.append(
eventState.getValue() == null ? "null" : eventState.getValue().toString());
builder.append("\n");
});
});
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package chip.devicecontroller.model;

import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -75,8 +76,10 @@ private void addEvent(int endpointId, long clusterId, long eventId, EventState e
endpointState.getClusterStates().put(clusterId, clusterState);
}

// This will overwrite previous events.
clusterState.getEventStates().put(eventId, eventStateToAdd);
if (!clusterState.getEventStates().containsKey(eventId)) {
clusterState.getEventStates().put(eventId, new ArrayList<EventState>());
}
clusterState.getEventStates().get(eventId).add(eventStateToAdd);
}

@Override
Expand Down

0 comments on commit 3820435

Please sign in to comment.