finished ac devices

This commit is contained in:
ashrafzarkanisala
2024-11-23 21:51:20 +03:00
parent 5e91d7c03a
commit 7dccfb5a76
25 changed files with 810 additions and 770 deletions
+14 -76
View File
@@ -1,25 +1,17 @@
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/app_enum.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);
required super.deviceId,
required super.deviceName,
required super.code,
required super.operationName,
required super.icon,
});
List<ACOperationalValue> getOperationalValues();
}
@@ -32,11 +24,6 @@ class SwitchFunction extends ACFunction {
icon: Assets.assetsAcPower,
);
@override
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
return currentStatus.copyWith(acSwitch: newValue as bool);
}
@override
List<ACOperationalValue> getOperationalValues() => [
ACOperationalValue(
@@ -60,27 +47,22 @@ class ModeFunction extends ACFunction {
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,
value: TempModes.cold.name,
),
ACOperationalValue(
icon: Assets.assetsAcHeating,
description: "Heating",
value: TempModes.hot,
value: TempModes.hot.name,
),
ACOperationalValue(
icon: Assets.assetsFanSpeed,
description: "Ventilation",
value: TempModes.wind,
value: TempModes.wind.name,
),
];
}
@@ -100,11 +82,6 @@ class TempSetFunction extends ACFunction {
icon: Assets.assetsTempreture,
);
@override
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
return currentStatus.copyWith(tempSet: newValue as int);
}
@override
List<ACOperationalValue> getOperationalValues() {
List<ACOperationalValue> values = [];
@@ -127,32 +104,27 @@ class LevelFunction extends ACFunction {
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,
value: FanSpeeds.low.name,
),
ACOperationalValue(
icon: Assets.assetsAcFanMiddle,
description: "MIDDLE",
value: FanSpeeds.middle,
value: FanSpeeds.middle.name,
),
ACOperationalValue(
icon: Assets.assetsAcFanHigh,
description: "HIGH",
value: FanSpeeds.high,
value: FanSpeeds.high.name,
),
ACOperationalValue(
icon: Assets.assetsAcFanAuto,
description: "AUTO",
value: FanSpeeds.auto,
value: FanSpeeds.auto.name,
),
];
}
@@ -165,11 +137,6 @@ class ChildLockFunction extends ACFunction {
icon: Assets.assetsChildLock,
);
@override
AcStatusModel execute(AcStatusModel currentStatus, dynamic newValue) {
return currentStatus.copyWith(childLock: newValue as bool);
}
@override
List<ACOperationalValue> getOperationalValues() => [
ACOperationalValue(
@@ -184,32 +151,3 @@ class ChildLockFunction extends ACFunction {
),
];
}
/*
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 -10
View File
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
abstract class DeviceFunction<T> {
final String deviceId;
final String deviceName;
@@ -12,34 +14,33 @@ abstract class DeviceFunction<T> {
required this.operationName,
required this.icon,
});
T execute(T currentStatus, dynamic newValue);
}
class DeviceFunctionData {
final String entityId;
final String actionExecutor;
final String function;
final String functionCode;
final String operationName;
final dynamic value;
final String? condition;
final String? valueDescription;
final UniqueKey uniqueKey;
DeviceFunctionData({
required this.entityId,
this.actionExecutor = 'function',
required this.function,
this.actionExecutor = 'device_issue',
required this.functionCode,
required this.operationName,
required this.value,
this.condition,
this.valueDescription,
});
}) : uniqueKey = UniqueKey();
Map<String, dynamic> toJson() {
return {
'entityId': entityId,
'actionExecutor': actionExecutor,
'function': function,
'function': functionCode,
'operationName': operationName,
'value': value,
if (condition != null) 'condition': condition,
@@ -51,7 +52,7 @@ class DeviceFunctionData {
return DeviceFunctionData(
entityId: json['entityId'],
actionExecutor: json['actionExecutor'] ?? 'function',
function: json['function'],
functionCode: json['function'],
operationName: json['operationName'],
value: json['value'],
condition: json['condition'],
@@ -66,7 +67,7 @@ class DeviceFunctionData {
return other is DeviceFunctionData &&
other.entityId == entityId &&
other.actionExecutor == actionExecutor &&
other.function == function &&
other.functionCode == functionCode &&
other.operationName == operationName &&
other.value == value &&
other.condition == condition &&
@@ -77,7 +78,7 @@ class DeviceFunctionData {
int get hashCode {
return entityId.hashCode ^
actionExecutor.hashCode ^
function.hashCode ^
functionCode.hashCode ^
operationName.hashCode ^
value.hashCode ^
condition.hashCode ^
@@ -10,8 +10,5 @@ abstract class BaseSwitchFunction extends DeviceFunction<bool> {
required super.icon,
});
@override
bool execute(bool currentStatus, dynamic newValue);
List<SwitchOperationalValue> getOperationalValues();
}
@@ -10,11 +10,6 @@ class OneGangSwitchFunction extends BaseSwitchFunction {
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -38,11 +33,6 @@ class OneGangCountdownFunction extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -10,11 +10,6 @@ class ThreeGangSwitch1Function extends BaseSwitchFunction {
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -39,11 +34,6 @@ class ThreeGangCountdown1Function extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -65,11 +55,6 @@ class ThreeGangSwitch2Function extends BaseSwitchFunction {
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -94,11 +79,6 @@ class ThreeGangCountdown2Function extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -120,11 +100,6 @@ class ThreeGangSwitch3Function extends BaseSwitchFunction {
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -149,11 +124,6 @@ class ThreeGangCountdown3Function extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -10,11 +10,6 @@ class TwoGangSwitch1Function extends BaseSwitchFunction {
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -31,20 +26,13 @@ class TwoGangSwitch1Function extends BaseSwitchFunction {
}
class TwoGangSwitch2Function extends BaseSwitchFunction {
TwoGangSwitch2Function({required String deviceId, required String deviceName})
TwoGangSwitch2Function({required super.deviceId, required super.deviceName})
: super(
deviceId: deviceId,
deviceName: deviceName,
code: 'switch_2',
operationName: 'Light 2 Switch',
icon: Assets.assetsAcPower,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -69,11 +57,6 @@ class TwoGangCountdown1Function extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(
@@ -96,11 +79,6 @@ class TwoGangCountdown2Function extends BaseSwitchFunction {
icon: Assets.assetsLightCountdown,
);
@override
bool execute(bool currentStatus, dynamic newValue) {
return newValue as bool;
}
@override
List<SwitchOperationalValue> getOperationalValues() => [
SwitchOperationalValue(