Files
syncrow-app/lib/features/devices/model/light_model.dart
2024-03-14 00:38:00 +03:00

63 lines
1.5 KiB
Dart

import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
class LightModel extends DeviceModel {
late double brightness;
late int color;
late int lightingMode;
late List<int> recentColors;
LightModel({
required this.brightness,
required this.color,
required this.lightingMode,
required this.recentColors,
required super.id,
required super.name,
required super.type,
required super.status,
required super.image,
required super.timer,
required super.functions,
});
Map<String, dynamic> toJson() {
return {
'luminance': brightness,
'color': color,
'lightingMode': lightingMode,
'timer': timer,
'recentColors': recentColors,
'id': id,
'name': name,
'status': status,
'type': type,
'image': image,
};
}
factory LightModel.fromJson(Map<String, dynamic> json) {
List<FunctionModel> func = [];
if (json['functions'] != null) {
json['functions'].forEach((v) {
func.add(FunctionModel.fromJson(v));
});
}
return LightModel(
id: json['id'],
name: json['name'],
status: json['status'],
brightness: json['luminance'],
color: json['color'],
lightingMode: json['lightingMode'],
timer: json['timer'],
type: json['type'],
image: json['image'],
recentColors: json['recentColors'],
functions: func,
);
}
}