Skip to content

Commit

Permalink
[tuya] add status DP to remote schema parsing (#395)
Browse files Browse the repository at this point in the history
* [tuya] add status DP to remote schema parsing and update schema.json

Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Aug 20, 2022
1 parent 578f6fc commit d674589
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.smarthomej.binding.tuya.internal.TuyaBindingConstants.PROPERTY_MAC;
import static org.smarthomej.binding.tuya.internal.TuyaBindingConstants.THING_TYPE_TUYA_DEVICE;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -28,6 +29,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -114,7 +116,12 @@ private void processDevice(DeviceListInfo device, TuyaOpenAPI api) {
.withRepresentationProperty(CONFIG_DEVICE_ID).withProperties(properties).build();

api.getDeviceSchema(device.id).thenAccept(schema -> {
List<SchemaDp> schemaDps = schema.functions.stream().map(fcn -> SchemaDp.fromRemoteSchema(gson, fcn))
List<SchemaDp> functionDps = schema.functions.stream().map(fcn -> SchemaDp.fromRemoteSchema(gson, fcn))
.collect(Collectors.toList());
List<SchemaDp> statusDps = schema.status.stream()
.filter(status -> functionDps.stream().noneMatch(functionDp -> functionDp.id == status.dp_id))
.map(status -> SchemaDp.fromRemoteSchema(gson, status)).collect(Collectors.toList());
List<SchemaDp> schemaDps = Stream.of(functionDps, statusDps).flatMap(Collection::stream)
.collect(Collectors.toList());
storage.put(device.id, gson.toJson(schemaDps));
});
Expand Down

0 comments on commit d674589

Please sign in to comment.