mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
216 lines
5.8 KiB
Dart
216 lines
5.8 KiB
Dart
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);
|
|
|
|
*/
|