put method

Future<void> put({
  1. String? token,
})

Sends a PUT request to the bridge for each resource in the list.

token is the remote access token.

NOTE: This method will not send a PUT request for a resource that has a null bridge property.

Implementation

Future<void> put({String? token}) async {
  List<List<Resource>> nonPuttableResources = [
    bridgeHomes,
    behaviorScripts,
    matterFabrics,
  ];

  for (List<Resource> resourceList in resources) {
    if (nonPuttableResources.contains(resourceList)) continue;

    for (Resource resource in resourceList) {
      // Skip resources that don't have an update.
      if (!resource.hasUpdate) continue;

      Map<String, dynamic> data = resource.toJson();

      if (data.isEmpty) continue;

      if (resource.bridge != null) {
        await resource.bridge!.put(resource, token: token);
      }
    }
  }
}