mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 17:44:56 +00:00
push add ac fucntions and handle doplicate adding to the then or if items
This commit is contained in:
215
lib/pages/routiens/models/ac/ac_function.dart
Normal file
215
lib/pages/routiens/models/ac/ac_function.dart
Normal file
@ -0,0 +1,215 @@
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/routiens/models/ac/ac_operational_value.dart';
|
||||
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
abstract class ACFunction extends DeviceFunction<AcStatusModel> {
|
||||
ACFunction({
|
||||
required String deviceId,
|
||||
required String deviceName,
|
||||
required String code,
|
||||
required String operationName,
|
||||
required String icon,
|
||||
}) : super(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
code: code,
|
||||
operationName: operationName,
|
||||
icon: icon,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue);
|
||||
|
||||
List<ACOperationalValue> getOperationalValues();
|
||||
}
|
||||
|
||||
class SwitchFunction extends ACFunction {
|
||||
SwitchFunction({required super.deviceId, required super.deviceName})
|
||||
: super(
|
||||
code: 'switch',
|
||||
operationName: 'Power',
|
||||
icon: Assets.assetsAcPower,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
|
||||
return currentStatus.copyWith(acSwitch: newValue as bool);
|
||||
}
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() => [
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcPower,
|
||||
description: "ON",
|
||||
value: true,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF,
|
||||
description: "OFF",
|
||||
value: false,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class ModeFunction extends ACFunction {
|
||||
ModeFunction({required super.deviceId, required super.deviceName})
|
||||
: super(
|
||||
code: 'mode',
|
||||
operationName: 'Mode',
|
||||
icon: Assets.assetsFreezing,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
|
||||
return currentStatus.copyWith(modeString: (newValue as TempModes).toString().split('.').last);
|
||||
}
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() => [
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcCooling,
|
||||
description: "Cooling",
|
||||
value: TempModes.cold,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcHeating,
|
||||
description: "Heating",
|
||||
value: TempModes.hot,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsFanSpeed,
|
||||
description: "Ventilation",
|
||||
value: TempModes.wind,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class TempSetFunction extends ACFunction {
|
||||
final int min;
|
||||
final int max;
|
||||
final int step;
|
||||
|
||||
TempSetFunction({required super.deviceId, required super.deviceName})
|
||||
: min = 200,
|
||||
max = 300,
|
||||
step = 5,
|
||||
super(
|
||||
code: 'temp_set',
|
||||
operationName: 'Set Temperature',
|
||||
icon: Assets.assetsTempreture,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
|
||||
return currentStatus.copyWith(tempSet: newValue as int);
|
||||
}
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() {
|
||||
List<ACOperationalValue> values = [];
|
||||
for (int temp = min; temp <= max; temp += step) {
|
||||
values.add(ACOperationalValue(
|
||||
icon: Assets.assetsTempreture,
|
||||
description: "${temp / 10}°C",
|
||||
value: temp,
|
||||
));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
class LevelFunction extends ACFunction {
|
||||
LevelFunction({required super.deviceId, required super.deviceName})
|
||||
: super(
|
||||
code: 'level',
|
||||
operationName: 'Fan Speed',
|
||||
icon: Assets.assetsFanSpeed,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
|
||||
return currentStatus.copyWith(fanSpeedsString: (newValue as FanSpeeds).toString().split('.').last);
|
||||
}
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() => [
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcFanLow,
|
||||
description: "LOW",
|
||||
value: FanSpeeds.low,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcFanMiddle,
|
||||
description: "MIDDLE",
|
||||
value: FanSpeeds.middle,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcFanHigh,
|
||||
description: "HIGH",
|
||||
value: FanSpeeds.high,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsAcFanAuto,
|
||||
description: "AUTO",
|
||||
value: FanSpeeds.auto,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class ChildLockFunction extends ACFunction {
|
||||
ChildLockFunction({required super.deviceId, required super.deviceName})
|
||||
: super(
|
||||
code: 'child_lock',
|
||||
operationName: 'Child Lock',
|
||||
icon: Assets.assetsChildLock,
|
||||
);
|
||||
|
||||
@override
|
||||
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
|
||||
return currentStatus.copyWith(childLock: newValue as bool);
|
||||
}
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() => [
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsSceneChildLock,
|
||||
description: "Lock",
|
||||
value: true,
|
||||
),
|
||||
ACOperationalValue(
|
||||
icon: Assets.assetsSceneChildUnlock,
|
||||
description: "Unlock",
|
||||
value: false,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
final deviceId = 'AC001';
|
||||
final deviceName = 'Living Room AC';
|
||||
|
||||
// Initial AC status
|
||||
var acStatus = AcStatusModel(
|
||||
uuid: deviceId,
|
||||
acSwitch: false,
|
||||
modeString: 'cold',
|
||||
tempSet: 220,
|
||||
currentTemp: 250,
|
||||
fanSpeedsString: 'auto',
|
||||
childLock: false,
|
||||
);
|
||||
|
||||
// Get all AC functions
|
||||
final acFunctions = getACFunctions(deviceId, deviceName);
|
||||
|
||||
// Example: Turn on the AC
|
||||
final switchFunction = acFunctions.firstWhere((f) => f is SwitchFunction) as SwitchFunction;
|
||||
acStatus = switchFunction.execute(acStatus, true);
|
||||
|
||||
// Example: Change mode to heat
|
||||
final modeFunction = acFunctions.firstWhere((f) => f is ModeFunction) as ModeFunction;
|
||||
acStatus = modeFunction.execute(acStatus, TempModes.hot);
|
||||
|
||||
*/
|
||||
11
lib/pages/routiens/models/ac/ac_operational_value.dart
Normal file
11
lib/pages/routiens/models/ac/ac_operational_value.dart
Normal file
@ -0,0 +1,11 @@
|
||||
class ACOperationalValue {
|
||||
final String icon;
|
||||
final String description;
|
||||
final dynamic value;
|
||||
|
||||
ACOperationalValue({
|
||||
required this.icon,
|
||||
required this.description,
|
||||
required this.value,
|
||||
});
|
||||
}
|
||||
17
lib/pages/routiens/models/device_functions.dart
Normal file
17
lib/pages/routiens/models/device_functions.dart
Normal file
@ -0,0 +1,17 @@
|
||||
abstract class DeviceFunction<T> {
|
||||
final String deviceId;
|
||||
final String deviceName;
|
||||
final String code;
|
||||
final String operationName;
|
||||
final String icon;
|
||||
|
||||
DeviceFunction({
|
||||
required this.deviceId,
|
||||
required this.deviceName,
|
||||
required this.code,
|
||||
required this.operationName,
|
||||
required this.icon,
|
||||
});
|
||||
|
||||
T execute(T currentStatus, dynamic newValue);
|
||||
}
|
||||
29
lib/pages/routiens/models/routine_item.dart
Normal file
29
lib/pages/routiens/models/routine_item.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
|
||||
class RoutineItem {
|
||||
final AllDevicesModel device;
|
||||
final String? function;
|
||||
final dynamic value;
|
||||
|
||||
RoutineItem({
|
||||
required this.device,
|
||||
this.function,
|
||||
this.value,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'device': device,
|
||||
'function': function,
|
||||
'value': value,
|
||||
};
|
||||
}
|
||||
|
||||
factory RoutineItem.fromMap(Map<String, dynamic> map) {
|
||||
return RoutineItem(
|
||||
device: map['device'] as AllDevicesModel,
|
||||
function: map['function'],
|
||||
value: map['value'],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user