discoverBridgesEndpoint static method
Searches the network for bridges using the endpoint method.
Implementation
static Future<List<DiscoveredBridge>> discoverBridgesEndpoint() async {
final List<DiscoveredBridge> bridges = [];
final Client client = Client();
Response response =
await client.get(Uri.parse("https://discovery.meethue.com"));
if (response.statusCode >= 200 && response.statusCode < 300) {
List<Map<String, dynamic>> results = List<Map<String, dynamic>>.from(
jsonDecode(response.body).map(
(result) => Map<String, dynamic>.from(result),
),
);
for (Map<String, dynamic> result in results) {
try {
final String rawIdFromEndpoint = result["id"];
final String ipAddress = result["internalipaddress"];
bridges.add(
DiscoveredBridge.fromEndpoint(
rawIdFromEndpoint: rawIdFromEndpoint,
ipAddress: ipAddress,
),
);
} catch (e) {
continue;
}
}
}
return bridges;
}