mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00

AC Cubit Add New Devices Cubit Arch will be used Devices Cubit (for devices categories, and devices page) { AC cubit, Lights cubit. ... } Replaced AssetsManager with Assets Class (auto generated)
58 lines
1.3 KiB
Dart
58 lines
1.3 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:meta/meta.dart';
|
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
|
|
part 'ac_state.dart';
|
|
|
|
class AcCubit extends Cubit<AcState> {
|
|
AcCubit() : super(AcInitial());
|
|
|
|
static AcCubit get(context) => BlocProvider.of(context);
|
|
|
|
bool areAllACsOff() {
|
|
for (var ac in DevicesCubit.categories[0].devices) {
|
|
if (ac.status) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void turnAllACsOff() {
|
|
for (var ac in DevicesCubit.categories[0].devices) {
|
|
ac.status = false;
|
|
}
|
|
emit(SwitchACsOff());
|
|
}
|
|
|
|
void turnAllACsOn() {
|
|
for (var ac in DevicesCubit.categories[0].devices) {
|
|
ac.status = true;
|
|
}
|
|
emit(SwitchACsOn());
|
|
}
|
|
|
|
void setTempToAll(double temperature) {
|
|
for (var ac in DevicesCubit.categories[0].devices) {
|
|
ac.temperature = temperature;
|
|
}
|
|
emit(ACsTempChanged());
|
|
}
|
|
|
|
double averageTempForAll() {
|
|
double allTemp = 0;
|
|
for (var ac in DevicesCubit.categories[0].devices) {
|
|
allTemp += ac.temperature;
|
|
}
|
|
emit(ACsTempChanged());
|
|
|
|
double averageTemp = allTemp / DevicesCubit.categories[0].devices.length;
|
|
|
|
averageTemp = (averageTemp * 2).round() / 2;
|
|
|
|
return averageTemp;
|
|
}
|
|
|
|
/// implement the fan speed and temp mode change
|
|
}
|