HomeServer/frontend/lib/devices.dart

36 lines
792 B
Dart
Raw Normal View History

2023-10-05 12:54:11 +00:00
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class Category {
final String name;
List<Device> devices;
Category(this.name) : devices = [];
static Future<List<Category>> fetch(String base_url) async {
final response = await http.get(Uri.parse("$base_url/devices"));
if (response.statusCode == 200) {
List<Category> categories = [];
Map<String, Map<String, dynamic>> json = jsonDecode(response.body);
return categories;
} else {
throw Exception("Failed to fetch devices");
}
}
}
class Device {
final int device_id;
bool led_state;
bool power_state;
double power_draw;
Device(this.device_id, this.led_state, this.power_state, this.power_draw);
}