mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 15:47:56 +00:00
Refactor device status handling and update UI components
- Update device status handling from 'status' to 'isOnline' for consistency - Remove unused imports and redundant code related to light switches - Refactor UI components to use 'isOnline' instead of 'status' for device status
This commit is contained in:
@@ -12,7 +12,7 @@ import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights_switches/light_switches.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_switches.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
@@ -63,14 +63,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
switch (category.type) {
|
||||
case DeviceType.AC:
|
||||
return const ACsView();
|
||||
case DeviceType.Lights:
|
||||
case DeviceType.LightBulb:
|
||||
return const LightsView();
|
||||
case DeviceType.DoorLock:
|
||||
return const DoorView();
|
||||
case DeviceType.Curtain:
|
||||
return const CurtainView();
|
||||
case DeviceType.ThreeGang:
|
||||
return const LightSwitchesView();
|
||||
return const ThreeGangSwitchesView();
|
||||
case DeviceType.Gateway:
|
||||
return const GateWayView();
|
||||
default:
|
||||
@@ -125,14 +125,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
category.devicesStatus = !category.devicesStatus!;
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = category.devicesStatus;
|
||||
device.isOnline = category.devicesStatus;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
category.devicesStatus = true;
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
device.isOnline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
|
||||
turnOnOffDevice(DeviceModel device) {
|
||||
device.status = !device.status!;
|
||||
device.isOnline = !device.isOnline!;
|
||||
DevicesCategoryModel category = allCategories!.firstWhere((category) {
|
||||
if (category.devices != null) {
|
||||
return category.devices!.contains(device);
|
||||
@@ -157,10 +157,10 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
updateDevicesStatus(DevicesCategoryModel category) {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
bool? tempStatus = category.devices![0].status;
|
||||
bool? tempStatus = category.devices![0].isOnline;
|
||||
for (var ac in category.devices!) {
|
||||
//check if there any ac have a different status than the initial ==> turn off the universal switch
|
||||
if (ac.status != tempStatus) {
|
||||
if (ac.isOnline != tempStatus) {
|
||||
category.devicesStatus = null;
|
||||
emit(DeviceSwitchChanged());
|
||||
return;
|
||||
@@ -179,7 +179,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = false;
|
||||
device.isOnline = false;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
updateDevicesStatus(category);
|
||||
@@ -192,7 +192,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
device.isOnline = true;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
updateDevicesStatus(category);
|
||||
@@ -204,7 +204,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
areAllDevicesOff(DevicesCategoryModel category) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
if (device.status ?? false) {
|
||||
if (device.isOnline ?? false) {
|
||||
category.devicesStatus = false;
|
||||
emit(CategorySwitchChanged());
|
||||
return;
|
||||
@@ -276,7 +276,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// }
|
||||
//
|
||||
// toggleLight(DeviceModel light) {
|
||||
// light.status != null ? light.status = !light.status! : light.status = true;
|
||||
// light.isOnline != null ? light.isOnline = !light.isOnline! : light.isOnline = true;
|
||||
// emit(LightToggled(light));
|
||||
// }
|
||||
//
|
||||
@@ -296,45 +296,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// emit(LightBrightnessChanged(value));
|
||||
// }
|
||||
// }
|
||||
|
||||
///ACs
|
||||
// DeviceModel? getSelectedAC() {
|
||||
// for (var ac in category.devices) {
|
||||
// if (ac is DeviceModel && ac.isSelected) {
|
||||
// return ac;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// void setTempToAll(double temperature) {
|
||||
// for (DeviceModel ac in category.devices) {
|
||||
// if (ac is DeviceModel) {
|
||||
// if (ac.temperature != temperature &&
|
||||
// ac.bounds.min <= temperature &&
|
||||
// temperature <= ac.bounds.max) {
|
||||
// setACTemp(ac, temperature);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// universalACTemp = temperature;
|
||||
// emit(ACsTempChanged(temperature));
|
||||
// }
|
||||
//
|
||||
// void setACTemp(DeviceModel model, double temp) {
|
||||
// if (model.bounds.min <= temp && temp <= model.bounds.max) {
|
||||
// model.temperature = temp;
|
||||
// }
|
||||
// emit(ACsTempChanged(temp));
|
||||
// }
|
||||
//
|
||||
// double getTemp(int index) {
|
||||
// var device = category.devices[index];
|
||||
// if (device is DeviceModel) {
|
||||
// return device.temperature;
|
||||
// }
|
||||
// return 0.0; // or any default value you prefer
|
||||
// }
|
||||
}
|
||||
|
||||
enum LightMode {
|
||||
|
||||
Reference in New Issue
Block a user