Files
ignis_app/lib/models/home_config.dart

39 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// Модель "дома" -- один физический сервер 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,
);
}