getResource method

Future<List<Map<String, dynamic>>?> getResource(
  1. ResourceType type
)

Fetch all resources of the given resource type from this bridge.

Will return null if:

  • This bridge does not have an IP address
  • This bridge does not have an application key
  • Any other unforeseen error

Implementation

Future<List<Map<String, dynamic>>?> getResource(ResourceType type) async {
  if (ipAddress == null) return null;
  if (applicationKey == null) return null;

  try {
    final Map<String, dynamic>? result = await HueHttpRepo.get(
      bridgeIpAddr: ipAddress!,
      applicationKey: applicationKey!,
      resourceType: type,
    );

    if (result == null) return null;

    return MiscTools.extractDataList(result);
  } catch (_) {
    return null;
  }
}