Каркас приложения: авторизация, зоны/устройства/правила, управление устройствами
HTTP-клиент к /api/v1 с Sanctum-токеном (хранится в secure storage), модели зеркалят Laravel API Resources. Экраны: логин, список устройств с живым статусом, детальная страница устройства (история телеметрии, turn-on/turn-off/set-level с проверкой capability), списки зон и правил автоматизации (пока только чтение — формы создания/редактирования впереди).
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import 'device.dart';
|
||||
import 'zone.dart';
|
||||
|
||||
class AutomationRule {
|
||||
AutomationRule({
|
||||
required this.id,
|
||||
required this.conditionSensorType,
|
||||
required this.conditionOperator,
|
||||
required this.conditionValue,
|
||||
required this.actionType,
|
||||
required this.actionParams,
|
||||
required this.isActive,
|
||||
this.zone,
|
||||
this.targetDevice,
|
||||
this.conditionSourceDevice,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final Zone? zone;
|
||||
final Device? targetDevice;
|
||||
final Device? conditionSourceDevice;
|
||||
final String conditionSensorType;
|
||||
final String conditionOperator; // ">", "<", ">=", "<=", "=="
|
||||
final double conditionValue;
|
||||
final String actionType; // "turn_on", "turn_off", "set_level", ...
|
||||
final Map<String, dynamic> actionParams;
|
||||
final bool isActive;
|
||||
|
||||
/// `action_params.level` for `set_level` rules, if present.
|
||||
num? get level => actionParams['level'] as num?;
|
||||
|
||||
factory AutomationRule.fromJson(Map<String, dynamic> json) => AutomationRule(
|
||||
id: json['id'] as int,
|
||||
zone: json['zone'] is Map ? Zone.fromJson(json['zone'] as Map<String, dynamic>) : null,
|
||||
targetDevice:
|
||||
json['target_device'] is Map ? Device.fromJson(json['target_device'] as Map<String, dynamic>) : null,
|
||||
conditionSourceDevice: json['condition_source_device'] is Map
|
||||
? Device.fromJson(json['condition_source_device'] as Map<String, dynamic>)
|
||||
: null,
|
||||
conditionSensorType: json['condition_sensor_type'] as String,
|
||||
conditionOperator: json['condition_operator'] as String,
|
||||
conditionValue: (json['condition_value'] as num).toDouble(),
|
||||
actionType: json['action_type'] as String,
|
||||
actionParams: Map<String, dynamic>.from(json['action_params'] as Map? ?? const {}),
|
||||
isActive: json['is_active'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user