39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
/// Модель "дома" -- один физический сервер Ignis.
|
||
/// Каждый дом имеет свой URL и API-ключ.
|
||
class HomeConfig {
|
||
final String id; // уникальный идентификатор (uuid или timestamp)
|
||
final String name; // человекочитаемое название ("Квартира", "Дача")
|
||
final String url; // адрес сервера (например ignis.akokos.ru)
|
||
final String apiKey; // ключ авторизации
|
||
|
||
HomeConfig({
|
||
required this.id,
|
||
required this.name,
|
||
required this.url,
|
||
required this.apiKey,
|
||
});
|
||
|
||
/// Сериализация в JSON для хранения в SharedPreferences
|
||
Map<String, dynamic> toJson() => {
|
||
'id': id,
|
||
'name': name,
|
||
'url': url,
|
||
'apiKey': apiKey,
|
||
};
|
||
|
||
factory HomeConfig.fromJson(Map<String, dynamic> json) => HomeConfig(
|
||
id: json['id'] as String,
|
||
name: json['name'] as String,
|
||
url: json['url'] as String,
|
||
apiKey: json['apiKey'] as String,
|
||
);
|
||
|
||
/// Копирование с изменениями
|
||
HomeConfig copyWith({String? name, String? url, String? apiKey}) => HomeConfig(
|
||
id: id,
|
||
name: name ?? this.name,
|
||
url: url ?? this.url,
|
||
apiKey: apiKey ?? this.apiKey,
|
||
);
|
||
}
|