mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
indentation and formatting of WaterHeaterBloc
.
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
// water_heater_bloc.dart
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
@ -49,7 +47,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
on<StatusUpdated>(_onStatusUpdated);
|
||||
}
|
||||
|
||||
FutureOr<void> _initializeAddSchedule(
|
||||
void _initializeAddSchedule(
|
||||
InitializeAddScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
@ -71,7 +69,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _updateSelectedTime(
|
||||
void _updateSelectedTime(
|
||||
UpdateSelectedTimeEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
@ -80,7 +78,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
emit(currentState.copyWith(selectedTime: event.selectedTime));
|
||||
}
|
||||
|
||||
FutureOr<void> _updateSelectedDay(
|
||||
void _updateSelectedDay(
|
||||
UpdateSelectedDayEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
@ -91,7 +89,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
|
||||
}
|
||||
|
||||
FutureOr<void> _updateFunctionOn(
|
||||
void _updateFunctionOn(
|
||||
UpdateFunctionOnEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
@ -100,16 +98,18 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
functionOn: event.isOn, selectedTime: currentState.selectedTime));
|
||||
}
|
||||
|
||||
FutureOr<void> _updateScheduleEvent(
|
||||
Future<void> _updateScheduleEvent(
|
||||
UpdateScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
if (currentState is WaterHeaterDeviceStatusLoaded) {
|
||||
if (event.scheduleMode == ScheduleModes.schedule) {
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
scheduleMode: ScheduleModes.schedule,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
if (event.scheduleMode == ScheduleModes.countdown) {
|
||||
final countdownRemaining =
|
||||
@ -129,17 +129,19 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
} else if (event.scheduleMode == ScheduleModes.inching) {
|
||||
final inchingDuration = Duration(hours: event.hours, minutes: event.minutes);
|
||||
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
scheduleMode: ScheduleModes.inching,
|
||||
inchingHours: inchingDuration.inHours,
|
||||
inchingMinutes: inchingDuration.inMinutes % 60,
|
||||
isInchingActive: currentState.isInchingActive,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _controlWaterHeater(
|
||||
Future<void> _controlWaterHeater(
|
||||
ToggleWaterHeaterEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -148,9 +150,11 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
|
||||
_updateLocalValue(event.code, event.value);
|
||||
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
status: deviceStatus,
|
||||
));
|
||||
),
|
||||
);
|
||||
|
||||
final success = await controlDeviceService.controlDevice(
|
||||
deviceUuid: event.deviceId,
|
||||
@ -164,37 +168,43 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
if (event.code == "countdown_1") {
|
||||
final countdownDuration = Duration(seconds: event.value);
|
||||
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
countdownHours: countdownDuration.inHours,
|
||||
countdownMinutes: countdownDuration.inMinutes % 60,
|
||||
countdownRemaining: countdownDuration,
|
||||
isCountdownActive: true,
|
||||
));
|
||||
),
|
||||
);
|
||||
|
||||
if (countdownDuration.inSeconds > 0) {
|
||||
_startCountdownTimer(emit, countdownDuration);
|
||||
} else {
|
||||
_countdownTimer?.cancel();
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
countdownHours: 0,
|
||||
countdownMinutes: 0,
|
||||
countdownRemaining: Duration.zero,
|
||||
isCountdownActive: false,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (event.code == "switch_inching") {
|
||||
final inchingDuration = Duration(seconds: event.value);
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
inchingHours: inchingDuration.inHours,
|
||||
inchingMinutes: inchingDuration.inMinutes % 60,
|
||||
isInchingActive: true,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _stopScheduleEvent(
|
||||
Future<void> _stopScheduleEvent(
|
||||
StopScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -205,18 +215,22 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
_countdownTimer?.cancel();
|
||||
|
||||
if (isCountDown) {
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
countdownHours: 0,
|
||||
countdownMinutes: 0,
|
||||
countdownRemaining: Duration.zero,
|
||||
isCountdownActive: false,
|
||||
));
|
||||
),
|
||||
);
|
||||
} else if (currentState.scheduleMode == ScheduleModes.inching) {
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
inchingHours: 0,
|
||||
inchingMinutes: 0,
|
||||
isInchingActive: false,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -233,7 +247,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _fetchWaterHeaterStatus(
|
||||
Future<void> _fetchWaterHeaterStatus(
|
||||
WaterHeaterFetchStatusEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -334,7 +348,10 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
void _onStatusUpdated(StatusUpdated event, Emitter<WaterHeaterState> emit) {
|
||||
void _onStatusUpdated(
|
||||
StatusUpdated event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
deviceStatus = event.deviceStatus;
|
||||
emit(WaterHeaterDeviceStatusLoaded(deviceStatus));
|
||||
}
|
||||
@ -345,12 +362,13 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
) {
|
||||
_countdownTimer?.cancel();
|
||||
|
||||
_countdownTimer = Timer.periodic(const Duration(minutes: 1), (timer) {
|
||||
add(DecrementCountdownEvent());
|
||||
});
|
||||
_countdownTimer = Timer.periodic(
|
||||
const Duration(minutes: 1),
|
||||
(timer) => add(DecrementCountdownEvent()),
|
||||
);
|
||||
}
|
||||
|
||||
_onDecrementCountdown(
|
||||
void _onDecrementCountdown(
|
||||
DecrementCountdownEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) {
|
||||
@ -364,25 +382,28 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
|
||||
if (newRemaining <= Duration.zero) {
|
||||
_countdownTimer?.cancel();
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
countdownHours: 0,
|
||||
countdownMinutes: 0,
|
||||
isCountdownActive: false,
|
||||
countdownRemaining: Duration.zero,
|
||||
));
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
int totalSeconds = newRemaining.inSeconds;
|
||||
final totalSeconds = newRemaining.inSeconds;
|
||||
final newHours = totalSeconds ~/ 3600;
|
||||
final newMinutes = (totalSeconds % 3600) ~/ 60;
|
||||
|
||||
int newHours = totalSeconds ~/ 3600;
|
||||
int newMinutes = (totalSeconds % 3600) ~/ 60;
|
||||
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
countdownHours: newHours,
|
||||
countdownMinutes: newMinutes,
|
||||
countdownRemaining: newRemaining,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -422,13 +443,17 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
return super.close();
|
||||
}
|
||||
|
||||
FutureOr<void> _getSchedule(
|
||||
GetSchedulesEvent event, Emitter<WaterHeaterState> emit) async {
|
||||
Future<void> _getSchedule(
|
||||
GetSchedulesEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
emit(ScheduleLoadingState());
|
||||
|
||||
try {
|
||||
List<ScheduleModel> schedules = await DevicesManagementApi()
|
||||
.getDeviceSchedules(deviceStatus.uuid, event.category);
|
||||
final schedules = await DevicesManagementApi().getDeviceSchedules(
|
||||
deviceStatus.uuid,
|
||||
event.category,
|
||||
);
|
||||
|
||||
emit(WaterHeaterDeviceStatusLoaded(
|
||||
deviceStatus,
|
||||
@ -436,7 +461,6 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
scheduleMode: ScheduleModes.schedule,
|
||||
));
|
||||
} catch (e) {
|
||||
//(const WaterHeaterFailedState(error: 'Failed to fetch schedules.'));
|
||||
emit(WaterHeaterDeviceStatusLoaded(
|
||||
deviceStatus,
|
||||
schedules: const [],
|
||||
@ -444,7 +468,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onAddSchedule(
|
||||
Future<void> _onAddSchedule(
|
||||
AddScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -458,8 +482,6 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
|
||||
);
|
||||
|
||||
// emit(ScheduleLoadingState());
|
||||
|
||||
bool success = await DevicesManagementApi()
|
||||
.addScheduleRecord(newSchedule, currentState.status.uuid);
|
||||
|
||||
@ -467,12 +489,11 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
add(GetSchedulesEvent(category: 'switch_1', uuid: deviceStatus.uuid));
|
||||
} else {
|
||||
emit(currentState);
|
||||
//emit(const WaterHeaterFailedState(error: 'Failed to add schedule.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onEditSchedule(
|
||||
Future<void> _onEditSchedule(
|
||||
EditWaterHeaterScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -500,7 +521,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onUpdateSchedule(
|
||||
Future<void> _onUpdateSchedule(
|
||||
UpdateScheduleEntryEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -531,7 +552,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onDeleteSchedule(
|
||||
Future<void> _onDeleteSchedule(
|
||||
DeleteScheduleEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
@ -553,12 +574,16 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _batchFetchWaterHeater(
|
||||
FetchWaterHeaterBatchStatusEvent event, Emitter<WaterHeaterState> emit) async {
|
||||
Future<void> _batchFetchWaterHeater(
|
||||
FetchWaterHeaterBatchStatusEvent event,
|
||||
Emitter<WaterHeaterState> emit,
|
||||
) async {
|
||||
emit(WaterHeaterLoadingState());
|
||||
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesUuid);
|
||||
final status = await DevicesManagementApi().getBatchStatus(
|
||||
event.devicesUuid,
|
||||
);
|
||||
deviceStatus =
|
||||
WaterHeaterStatusModel.fromJson(event.devicesUuid.first, status.status);
|
||||
|
||||
@ -568,7 +593,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _batchControlWaterHeater(
|
||||
Future<void> _batchControlWaterHeater(
|
||||
ControlWaterHeaterBatchEvent event, Emitter<WaterHeaterState> emit) async {
|
||||
if (state is WaterHeaterDeviceStatusLoaded) {
|
||||
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
||||
|
@ -1,5 +1,3 @@
|
||||
// water_heater_state.dart
|
||||
|
||||
part of 'water_heater_bloc.dart';
|
||||
|
||||
sealed class WaterHeaterState extends Equatable {
|
||||
|
Reference in New Issue
Block a user