mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
69 lines
1.7 KiB
Dart
69 lines
1.7 KiB
Dart
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());
|
|
|
|
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 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
|
|
}
|