mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 13:07:56 +00:00
Converted all the devices models to extends from DeviceModel for the purpose of unifying.
Initialized Lights feature.
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
|
||||
part 'ac_state.dart';
|
||||
|
||||
class AcCubit extends Cubit<AcState> {
|
||||
AcCubit() : super(AcInitial()) {
|
||||
updateACsStatus();
|
||||
}
|
||||
|
||||
static AcCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
void selectAC(ACModel model) {
|
||||
model.isSelected = !model.isSelected;
|
||||
emit(ACSelected());
|
||||
}
|
||||
|
||||
ACModel? getSelectedAC() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
if (ac is ACModel && ac.isSelected) {
|
||||
return ac;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void turnACOn(ACModel model) {
|
||||
if (model.status == false) {
|
||||
model.status = true;
|
||||
updateACsStatus();
|
||||
emit(ACTurnedOn());
|
||||
}
|
||||
}
|
||||
|
||||
void turnACOff(ACModel model) {
|
||||
if (model.status == true) {
|
||||
model.status = false;
|
||||
updateACsStatus();
|
||||
emit(ACTurnedOff());
|
||||
}
|
||||
}
|
||||
|
||||
void updateACsStatus() {
|
||||
bool tempStatus = DevicesCubit.categories[0].devices[0].status ?? false;
|
||||
for (var AC in DevicesCubit.categories[0].devices) {
|
||||
//check if there any AC have a different status than the initial ==> turn off the universal switch
|
||||
if (AC.status != tempStatus) {
|
||||
DevicesCubit.categories[0].devicesStatus = false;
|
||||
emit(ACsStatusChanged());
|
||||
return;
|
||||
}
|
||||
DevicesCubit.categories[0].devicesStatus = tempStatus;
|
||||
emit(ACsStatusChanged());
|
||||
}
|
||||
}
|
||||
|
||||
void turnAllACsOff() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.status = false;
|
||||
}
|
||||
updateACsStatus();
|
||||
emit(SwitchACsOff());
|
||||
}
|
||||
|
||||
void turnAllACsOn() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.status = true;
|
||||
}
|
||||
updateACsStatus();
|
||||
emit(SwitchACsOn());
|
||||
}
|
||||
|
||||
void setTempToAll(double temperature) {
|
||||
for (var element in DevicesCubit.categories[0].devices) {
|
||||
if (element is ACModel) {
|
||||
element.temperature = temperature;
|
||||
}
|
||||
}
|
||||
emit(ACsTempChanged(temperature));
|
||||
}
|
||||
|
||||
void increaseACTemp(int index) {
|
||||
var device = DevicesCubit.categories[0].devices[index];
|
||||
if (device is ACModel) {
|
||||
device.temperature += 0.5;
|
||||
emit(ACsTempChanged(device.temperature));
|
||||
}
|
||||
}
|
||||
|
||||
void decreaseACTemp(int index) {
|
||||
var device = DevicesCubit.categories[0].devices[index];
|
||||
if (device is ACModel) {
|
||||
device.temperature -= 0.5;
|
||||
emit(ACsTempChanged(device.temperature));
|
||||
}
|
||||
}
|
||||
|
||||
void setACTemp(ACModel model, double temp) {
|
||||
model.temperature = temp;
|
||||
emit(ACsTempChanged(temp));
|
||||
}
|
||||
|
||||
double getTemp(int index) {
|
||||
var device = DevicesCubit.categories[0].devices[index];
|
||||
if (device is ACModel) {
|
||||
return device.temperature;
|
||||
}
|
||||
return 0.0; // or any default value you prefer
|
||||
}
|
||||
|
||||
static double averageTemp = 0;
|
||||
|
||||
/// implement the fan speed and temp mode change
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'ac_cubit.dart';
|
||||
|
||||
@immutable
|
||||
abstract class AcState {}
|
||||
|
||||
class AcInitial extends AcState {}
|
||||
|
||||
class ACsStatusChanged extends AcState {}
|
||||
|
||||
class SwitchACsOff extends AcState {}
|
||||
|
||||
class SwitchACsOn extends AcState {}
|
||||
|
||||
class ACsTempChanged extends AcState {
|
||||
final double temperature;
|
||||
|
||||
ACsTempChanged(this.temperature);
|
||||
}
|
||||
|
||||
class ACsAverageTemp extends AcState {}
|
||||
|
||||
class ACsFanSpeedChanged extends AcState {}
|
||||
|
||||
class ACsTempModeChanged extends AcState {}
|
||||
|
||||
class ACTurnedOn extends AcState {}
|
||||
|
||||
class ACTurnedOff extends AcState {}
|
||||
|
||||
class ACSelected extends AcState {}
|
||||
Reference in New Issue
Block a user