File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
src/main/java/io/github/hapjava Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 44import io .github .hapjava .services .impl .AccessoryInformationService ;
55import java .util .Collection ;
66import java .util .Collections ;
7+ import java .util .Iterator ;
78import java .util .concurrent .CompletableFuture ;
89
910/**
@@ -81,11 +82,18 @@ default Collection<Service> getServices() {
8182 };
8283
8384 /**
84- * default implementation which is sufficient if accessory has only one services
85+ * default implementation which is sufficient if accessory has only one service
8586 *
8687 * @return primary service
8788 */
8889 default Service getPrimaryService () {
89- return getServices ().isEmpty () ? null : getServices ().iterator ().next ();
90+ Iterator <Service > iterator = getServices ().iterator ();
91+ while (iterator .hasNext ()) {
92+ Service service = iterator .next ();
93+ if (!(service instanceof AccessoryInformationService )) {
94+ return service ;
95+ }
96+ }
97+ return null ;
9098 };
9199}
Original file line number Diff line number Diff line change @@ -42,8 +42,11 @@ public synchronized void reset() {
4242 List <Service > newServices ;
4343 try {
4444 newServices = new ArrayList <>(2 );
45- newServices .add (new AccessoryInformationService (accessory ));
46- for (Service service : accessory .getServices ()) {
45+ Collection <Service > services = accessory .getServices ();
46+ if (!services .stream ().anyMatch (s -> s instanceof AccessoryInformationService )) {
47+ newServices .add (new AccessoryInformationService (accessory ));
48+ }
49+ for (Service service : services ) {
4750 newServices .add (service );
4851 newServices .addAll (service .getLinkedServices ());
4952 }
You can’t perform that action at this time.
0 commit comments