Refactor AC interface temp unit control logic

Refactor the control logic in the AC interface temp unit widget to handle
device control actions more efficiently and improve code readability.
This commit is contained in:
Mohammad Salameh
2024-04-04 00:45:54 +03:00
parent 13bfcdfb4d
commit 20ded336d3
@@ -88,8 +88,12 @@ class AcInterfaceTempUnit extends StatelessWidget {
if (valueAsString.endsWith(".0") ||
valueAsString.endsWith(".5")) {
value = double.parse(valueAsString);
// DevicesCubit.getInstance()
// .setACTemp(DeviceModel, value);
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: acDevice.id,
code: 'temp_set',
value: value * 10),
acDevice.id!);
}
},
),
@@ -104,6 +108,15 @@ class AcInterfaceTempUnit extends StatelessWidget {
dimension: 24,
child: InkWell(
onTap: () {
//TODO refactor the loading check
if (state is GetDeviceStatusLoading &&
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set') {
return;
}
if (setToTemp > 20) {
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
@@ -124,8 +137,14 @@ class AcInterfaceTempUnit extends StatelessWidget {
// text: "${DeviceModel.coolTo}° C",
text: '$setToTemp° C',
style: context.bodyLarge.copyWith(
color:
ColorsManager.primaryColor.withOpacity(0.6),
color: state is GetDeviceStatusLoading &&
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set'
? Colors.grey
: ColorsManager.primaryColor.withOpacity(0.6),
fontWeight: FontsManager.bold,
fontSize: 30,
height: 0),
@@ -140,10 +159,14 @@ class AcInterfaceTempUnit extends StatelessWidget {
dimension: 24,
child: InkWell(
onTap: () {
// DevicesCubit.getInstance()
// .setACTemp(DeviceModel, DeviceModel.coolTo);
// DeviceModel.coolTo += .5;
if (state is GetDeviceStatusLoading &&
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set') {
return;
}
if (setToTemp < 30) {
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(