getRelativeAsResource method

Resource getRelativeAsResource(
  1. Relative relative
)

Returns a Resource object that represents the relative of this Resource.

Throws MissingHueNetworkException if the hueNetwork is null, if the relative cannot be found on the hueNetwork, or if the relative's ResourceType cannot be found on the hueNetwork.

Implementation

Resource getRelativeAsResource(Relative relative) {
  if (hueNetwork == null) {
    throw const MissingHueNetworkException();
  }

  ResourceType type = relative.type;

  List<Resource>? resources = hueNetwork!.getListType(type);

  if (resources == null) {
    throw const MissingHueNetworkException();
  }

  Resource? resource = resources.firstWhereOrNull(
    (resource) => resource.id == relative.id,
  );

  if (resource == null) {
    throw const MissingHueNetworkException();
  }

  return resource;
}