Implement Two-Gang & One-Gang

This commit is contained in:
mohammad
2024-09-15 10:15:37 +03:00
parent b5842194ff
commit 46662b5bac
8 changed files with 34 additions and 51 deletions
@@ -69,7 +69,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
deviceName: devicesList[i].name ?? '',
firstSwitch: deviceStatus.firstSwitch,
secondSwitch: deviceStatus.secondSwitch,
));
)
);
}
if (groupTwoGangList.isNotEmpty) {
@@ -128,22 +129,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
emit(LoadingNewSate(twoGangModel: deviceStatus));
try {
if (twoGangGroup) {
bool allSwitchesValue = true;
groupTwoGangList.forEach((element) {
if (element.deviceId == event.deviceId) {
element.firstSwitch = !event.value;
}
if (!element.firstSwitch || !element.secondSwitch ) {
allSwitchesValue = false;
}
});
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
} else {
deviceStatus.firstSwitch = !event.value;
emit(UpdateState(twoGangModel: deviceStatus));
}
deviceStatus.firstSwitch = !event.value;
emit(UpdateState(twoGangModel: deviceStatus));
if (_timer != null) {
_timer!.cancel();
}
@@ -169,22 +156,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
emit(LoadingNewSate(twoGangModel: deviceStatus));
try {
if (twoGangGroup) {
bool allSwitchesValue = true;
groupTwoGangList.forEach((element) {
if (element.deviceId == event.deviceId) {
element.secondSwitch = !event.value;
}
if (!element.firstSwitch || !element.secondSwitch ) {
allSwitchesValue = false;
}
});
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
} else {
deviceStatus.secondSwitch = !event.value;
emit(UpdateState(twoGangModel: deviceStatus));
}
deviceStatus.secondSwitch = !event.value;
emit(UpdateState(twoGangModel: deviceStatus));
if (_timer != null) {
_timer!.cancel();
}
@@ -238,24 +211,23 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
void _allOn(AllOnEvent event, Emitter<TwoGangState> emit) async {
emit(LoadingNewSate(twoGangModel: deviceStatus));
try {
deviceStatus.firstSwitch = true;
deviceStatus.secondSwitch = true;
emit(UpdateState(twoGangModel: deviceStatus));
final response = await Future.wait([
DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
DeviceControlModel(
deviceId: twoGangId, code: 'switch_1',
value: deviceStatus.firstSwitch),
twoGangId),
DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
twoGangId),
DeviceControlModel(
deviceId: twoGangId,
code: 'switch_2',
value: deviceStatus.secondSwitch),
twoGangId),
]);
if (response.every((element) => !element['success'])) {
await Future.delayed(const Duration(milliseconds: 500));
add(const InitialEvent(groupScreen: false));
@@ -58,6 +58,10 @@ class DeviceModel {
tempIcon = Assets.assetsIcons3GangSwitch;
} else if (type == DeviceType.Gateway) {
tempIcon = Assets.assetsIconsGateway;
} else if (type == DeviceType.OneGang) {
tempIcon = Assets.oneGang;
} else if (type == DeviceType.TwoGang) {
tempIcon = Assets.twoGang;
} else {
tempIcon = Assets.assetsIconsLogo;
}
@@ -79,8 +79,7 @@ class DevicesViewBody extends StatelessWidget {
),
if (HomeCubit.getInstance().selectedSpace != null)
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
...HomeCubit.getInstance().selectedSpace!.rooms!.map(
(room) {
...HomeCubit.getInstance().selectedSpace!.rooms!.map((room) {
return RoomPage(
room: room,
);
@@ -22,6 +22,7 @@ class RoomsSlider extends StatelessWidget {
onPageChanged: (index) {
HomeCubit.getInstance().roomSliderPageChanged(index);
},
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
+3 -3
View File
@@ -1030,9 +1030,9 @@ class Assets {
static const String assetsPresenceState =
"assets/icons/functions_icons/automation_functions/presence_state.svg";
//assets/icons/functions_icons/automation_functions/presence_state.svg
static const String oneGang =
"assets/icons/1gang.svg";
static const String oneGang = "assets/icons/1gang.svg";
static const String twoGang = "assets/icons/2gang.svg";
}
+1 -1
View File
@@ -14,7 +14,7 @@ void main() {
//to catch all the errors in the app and send them to firebase
runZonedGuarded(() async {
//to load the environment variables
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'production');
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
await dotenv.load(fileName: '.env.$environment');
// //this is to make the app work with the self-signed certificate