Add countdown functionality and device type support across device man… (#323)

…agement views

<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->


## Description

<!--- Describe your changes in detail -->

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ]  New feature (non-breaking change which adds functionality)
- [x] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ]  Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 Code refactor
- [ ]  Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore
This commit is contained in:
mohammadnemer1
2025-06-30 15:22:28 +03:00
committed by GitHub
21 changed files with 255 additions and 180 deletions

View File

@ -57,6 +57,9 @@ class Status {
}; };
} }
factory Status.fromJson(String source) => Status.fromMap(json.decode(source));
String toJson() => json.encode(toMap());
Status copyWith({ Status copyWith({
String? code, String? code,
dynamic value, dynamic value,
@ -66,8 +69,4 @@ class Status {
value: value ?? this.value, value: value ?? this.value,
); );
} }
factory Status.fromJson(String source) => Status.fromMap(json.decode(source));
String toJson() => json.encode(toMap());
} }

View File

@ -62,9 +62,10 @@ class CurtainModuleItems extends StatelessWidget with HelperResponsiveLayout {
BlocProvider.of<CurtainModuleBloc>(context), BlocProvider.of<CurtainModuleBloc>(context),
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'CUR_2', category: 'timer',
code: 'control', code: 'control',
countdownCode: 'timer',
deviceType: 'CUR_2',
), ),
)); ));
}, },

View File

@ -90,6 +90,8 @@ class OneGangGlassSwitchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_1', category: 'switch_1',
deviceUuid: deviceId, deviceUuid: deviceId,
countdownCode: 'countdown_1',
deviceType: '1GT',
), ),
)); ));
}, },

View File

@ -80,6 +80,8 @@ class WallLightDeviceControl extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_1', category: 'switch_1',
deviceUuid: deviceId, deviceUuid: deviceId,
countdownCode: 'countdown_1',
deviceType: '1G',
), ),
)); ));
}, },

View File

@ -47,7 +47,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
final success = await RemoteControlDeviceService().controlDevice( final success = await RemoteControlDeviceService().controlDevice(
deviceUuid: deviceId, deviceUuid: deviceId,
status: Status( status: Status(
code: 'countdown_1', code: event.countdownCode,
value: 0, value: 0,
), ),
); );
@ -80,15 +80,18 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
) { ) {
if (state is ScheduleLoaded) { if (state is ScheduleLoaded) {
final currentState = state as ScheduleLoaded; final currentState = state as ScheduleLoaded;
emit(currentState.copyWith( emit(currentState.copyWith(
countdownSeconds: currentState.countdownSeconds,
selectedTime: currentState.selectedTime,
deviceId: deviceId,
scheduleMode: event.scheduleMode, scheduleMode: event.scheduleMode,
countdownRemaining: Duration.zero, countdownHours: currentState.countdownHours,
countdownHours: 0, countdownMinutes: currentState.countdownMinutes,
countdownMinutes: 0, inchingHours: currentState.inchingHours,
inchingHours: 0, inchingMinutes: currentState.inchingMinutes,
inchingMinutes: 0,
isCountdownActive: false,
isInchingActive: false, isInchingActive: false,
isCountdownActive: currentState.countdownRemaining > Duration.zero,
)); ));
} }
} }
@ -221,7 +224,6 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
deviceId, deviceId,
event.category, event.category,
); );
if (state is ScheduleLoaded) { if (state is ScheduleLoaded) {
final currentState = state as ScheduleLoaded; final currentState = state as ScheduleLoaded;
emit(currentState.copyWith( emit(currentState.copyWith(
@ -285,9 +287,8 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
) async { ) async {
try { try {
if (state is ScheduleLoaded) { if (state is ScheduleLoaded) {
final dateTime = DateTime.parse(event.time);
Status status = Status(code: '', value: ''); Status status = Status(code: '', value: '');
if (event.category == 'CUR_2') { if (event.deviceType == 'CUR_2') {
status = status.copyWith( status = status.copyWith(
code: 'control', code: 'control',
value: event.functionOn == true ? 'open' : 'close'); value: event.functionOn == true ? 'open' : 'close');
@ -295,6 +296,8 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
status = status =
status.copyWith(code: event.category, value: event.functionOn); status.copyWith(code: event.category, value: event.functionOn);
} }
final dateTime = DateTime.parse(event.time);
final updatedSchedule = ScheduleEntry( final updatedSchedule = ScheduleEntry(
scheduleId: event.scheduleId, scheduleId: event.scheduleId,
category: event.category, category: event.category,
@ -405,7 +408,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
final totalSeconds = final totalSeconds =
Duration(hours: event.hours, minutes: event.minutes).inSeconds; Duration(hours: event.hours, minutes: event.minutes).inSeconds;
final code = event.mode == ScheduleModes.countdown final code = event.mode == ScheduleModes.countdown
? 'countdown_1' ? event.countDownCode
: 'switch_inching'; : 'switch_inching';
final currentState = state as ScheduleLoaded; final currentState = state as ScheduleLoaded;
final duration = Duration(seconds: totalSeconds); final duration = Duration(seconds: totalSeconds);
@ -432,7 +435,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
); );
if (success) { if (success) {
if (code == 'countdown_1') { if (code == event.countDownCode) {
final countdownDuration = Duration(seconds: totalSeconds); final countdownDuration = Duration(seconds: totalSeconds);
emit( emit(
@ -446,7 +449,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
); );
if (countdownDuration.inSeconds > 0) { if (countdownDuration.inSeconds > 0) {
_startCountdownTimer(emit, countdownDuration); _startCountdownTimer(emit, countdownDuration, event.countDownCode);
} else { } else {
_countdownTimer?.cancel(); _countdownTimer?.cancel();
emit( emit(
@ -476,9 +479,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
} }
void _startCountdownTimer( void _startCountdownTimer(
Emitter<ScheduleState> emit, Emitter<ScheduleState> emit, Duration duration, String countdownCode) {
Duration duration,
) {
_countdownTimer?.cancel(); _countdownTimer?.cancel();
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) { _countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (_currentCountdown != null && _currentCountdown! > Duration.zero) { if (_currentCountdown != null && _currentCountdown! > Duration.zero) {
@ -488,6 +489,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
} else { } else {
timer.cancel(); timer.cancel();
add(StopScheduleEvent( add(StopScheduleEvent(
countdownCode: countdownCode,
mode: _currentCountdown == null mode: _currentCountdown == null
? ScheduleModes.countdown ? ScheduleModes.countdown
: ScheduleModes.inching, : ScheduleModes.inching,
@ -524,70 +526,75 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
try { try {
final status = final status =
await DevicesManagementApi().getDeviceStatus(event.deviceId); await DevicesManagementApi().getDeviceStatus(event.deviceId);
print(status.status); int totalSeconds = 0;
final countdownItem = status.status.firstWhere(
(item) => item.code == event.countdownCode,
orElse: () => Status(code: '', value: 0),
);
totalSeconds = (countdownItem.value as int?) ?? 0;
final countdownHours = totalSeconds ~/ 3600;
final countdownMinutes = (totalSeconds % 3600) ~/ 60;
final countdownSeconds = totalSeconds % 60;
final deviceStatus = final deviceStatus =
WaterHeaterStatusModel.fromJson(event.deviceId, status.status); WaterHeaterStatusModel.fromJson(event.deviceId, status.status);
final isCountdownActive = totalSeconds > 0;
final isInchingActive = !isCountdownActive &&
(deviceStatus.inchingHours > 0 || deviceStatus.inchingMinutes > 0);
final scheduleMode = final newState = state is ScheduleLoaded
deviceStatus.countdownHours > 0 || deviceStatus.countdownMinutes > 0 ? (state as ScheduleLoaded).copyWith(
? ScheduleModes.countdown scheduleMode: ScheduleModes.schedule,
: deviceStatus.inchingHours > 0 || deviceStatus.inchingMinutes > 0 countdownHours: countdownHours,
? ScheduleModes.inching countdownMinutes: countdownMinutes,
: ScheduleModes.schedule; countdownSeconds: countdownSeconds,
final isCountdown = scheduleMode == ScheduleModes.countdown;
final isInching = scheduleMode == ScheduleModes.inching;
Duration? countdownRemaining;
var isCountdownActive = false;
var isInchingActive = false;
if (isCountdown) {
countdownRemaining = Duration(
hours: deviceStatus.countdownHours,
minutes: deviceStatus.countdownMinutes,
);
isCountdownActive = countdownRemaining > Duration.zero;
} else if (isInching) {
isInchingActive = Duration(
hours: deviceStatus.inchingHours,
minutes: deviceStatus.inchingMinutes,
) >
Duration.zero;
}
if (state is ScheduleLoaded) {
final currentState = state as ScheduleLoaded;
emit(currentState.copyWith(
scheduleMode: scheduleMode,
countdownHours: deviceStatus.countdownHours,
countdownMinutes: deviceStatus.countdownMinutes,
inchingHours: deviceStatus.inchingHours, inchingHours: deviceStatus.inchingHours,
inchingMinutes: deviceStatus.inchingMinutes, inchingMinutes: deviceStatus.inchingMinutes,
isCountdownActive: isCountdownActive, isCountdownActive: isCountdownActive,
isInchingActive: isInchingActive, isInchingActive: isInchingActive,
countdownRemaining: countdownRemaining ?? Duration.zero, countdownRemaining: isCountdownActive
)); ? Duration(seconds: totalSeconds)
} else { : Duration.zero,
emit(ScheduleLoaded( )
: ScheduleLoaded(
scheduleMode: ScheduleModes.schedule,
schedules: const [], schedules: const [],
selectedTime: null, selectedTime: null,
selectedDays: List.filled(7, false), selectedDays: List.filled(7, false),
functionOn: false, functionOn: false,
isEditing: false, isEditing: false,
deviceId: deviceId, deviceId: event.deviceId,
scheduleMode: scheduleMode, countdownHours: countdownHours,
countdownHours: deviceStatus.countdownHours, countdownMinutes: countdownMinutes,
countdownMinutes: deviceStatus.countdownMinutes, countdownSeconds: countdownSeconds,
inchingHours: deviceStatus.inchingHours, inchingHours: deviceStatus.inchingHours,
inchingMinutes: deviceStatus.inchingMinutes, inchingMinutes: deviceStatus.inchingMinutes,
isCountdownActive: isCountdownActive, isCountdownActive: isCountdownActive,
isInchingActive: isInchingActive, isInchingActive: isInchingActive,
countdownRemaining: countdownRemaining ?? Duration.zero, countdownRemaining: isCountdownActive
? Duration(seconds: totalSeconds)
: Duration.zero,
);
emit(newState);
if (isCountdownActive) {
_countdownTimer?.cancel();
_currentCountdown = Duration(seconds: totalSeconds);
countdownRemaining = _currentCountdown!;
if (totalSeconds > 0) {
_startCountdownTimer(
emit, Duration(seconds: totalSeconds), event.countdownCode);
} else {
add(StopScheduleEvent(
countdownCode: event.countdownCode,
mode: ScheduleModes.countdown,
deviceId: event.deviceId,
)); ));
} }
} else {
// if (isCountdownActive && countdownRemaining != null) { _countdownTimer?.cancel();
// _startCountdownTimer(emit, countdownRemaining); }
// }
} catch (e) { } catch (e) {
emit(ScheduleError('Failed to fetch device status: $e')); emit(ScheduleError('Failed to fetch device status: $e'));
} }

View File

@ -91,6 +91,7 @@ class ScheduleEditEvent extends ScheduleEvent {
final String time; final String time;
final List<String> selectedDays; final List<String> selectedDays;
final bool functionOn; final bool functionOn;
final String deviceType;
const ScheduleEditEvent({ const ScheduleEditEvent({
required this.scheduleId, required this.scheduleId,
@ -98,6 +99,7 @@ class ScheduleEditEvent extends ScheduleEvent {
required this.time, required this.time,
required this.selectedDays, required this.selectedDays,
required this.functionOn, required this.functionOn,
required this.deviceType,
}); });
@override @override
@ -107,6 +109,7 @@ class ScheduleEditEvent extends ScheduleEvent {
time, time,
selectedDays, selectedDays,
functionOn, functionOn,
deviceType,
]; ];
} }
@ -138,11 +141,13 @@ class ScheduleUpdateEntryEvent extends ScheduleEvent {
class UpdateScheduleModeEvent extends ScheduleEvent { class UpdateScheduleModeEvent extends ScheduleEvent {
final ScheduleModes scheduleMode; final ScheduleModes scheduleMode;
final String countdownCode;
const UpdateScheduleModeEvent({required this.scheduleMode}); const UpdateScheduleModeEvent(
{required this.scheduleMode, required this.countdownCode});
@override @override
List<Object> get props => [scheduleMode]; List<Object> get props => [scheduleMode, countdownCode!];
} }
class UpdateCountdownTimeEvent extends ScheduleEvent { class UpdateCountdownTimeEvent extends ScheduleEvent {
@ -177,28 +182,32 @@ class StartScheduleEvent extends ScheduleEvent {
final ScheduleModes mode; final ScheduleModes mode;
final int hours; final int hours;
final int minutes; final int minutes;
final String countDownCode;
const StartScheduleEvent({ const StartScheduleEvent({
required this.mode, required this.mode,
required this.hours, required this.hours,
required this.minutes, required this.minutes,
required this.countDownCode,
}); });
@override @override
List<Object?> get props => [mode, hours, minutes]; List<Object?> get props => [mode, hours, minutes, countDownCode];
} }
class StopScheduleEvent extends ScheduleEvent { class StopScheduleEvent extends ScheduleEvent {
final ScheduleModes mode; final ScheduleModes mode;
final String deviceId; final String deviceId;
final String countdownCode;
const StopScheduleEvent({ const StopScheduleEvent({
required this.mode, required this.mode,
required this.deviceId, required this.deviceId,
required this.countdownCode,
}); });
@override @override
List<Object?> get props => [mode, deviceId]; List<Object?> get props => [mode, deviceId, countdownCode];
} }
class ScheduleDecrementCountdownEvent extends ScheduleEvent { class ScheduleDecrementCountdownEvent extends ScheduleEvent {
@ -210,11 +219,13 @@ class ScheduleDecrementCountdownEvent extends ScheduleEvent {
class ScheduleFetchStatusEvent extends ScheduleEvent { class ScheduleFetchStatusEvent extends ScheduleEvent {
final String deviceId; final String deviceId;
final String countdownCode;
const ScheduleFetchStatusEvent(this.deviceId); const ScheduleFetchStatusEvent(
{required this.deviceId, required this.countdownCode});
@override @override
List<Object> get props => [deviceId]; List<Object> get props => [deviceId, countdownCode];
} }
class DeleteScheduleEvent extends ScheduleEvent { class DeleteScheduleEvent extends ScheduleEvent {

View File

@ -29,7 +29,7 @@ class ScheduleLoaded extends ScheduleState {
final int inchingSeconds; final int inchingSeconds;
final bool isInchingActive; final bool isInchingActive;
final ScheduleModes scheduleMode; final ScheduleModes scheduleMode;
final Duration? countdownRemaining; final Duration countdownRemaining;
final int? countdownSeconds; final int? countdownSeconds;
const ScheduleLoaded({ const ScheduleLoaded({
@ -48,7 +48,7 @@ class ScheduleLoaded extends ScheduleState {
this.inchingMinutes = 0, this.inchingMinutes = 0,
this.isInchingActive = false, this.isInchingActive = false,
this.scheduleMode = ScheduleModes.countdown, this.scheduleMode = ScheduleModes.countdown,
this.countdownRemaining, this.countdownRemaining = Duration.zero,
}); });
ScheduleLoaded copyWith({ ScheduleLoaded copyWith({

View File

@ -11,6 +11,7 @@ class CountdownModeButtons extends StatelessWidget {
final String deviceId; final String deviceId;
final int hours; final int hours;
final int minutes; final int minutes;
final String countDownCode;
const CountdownModeButtons({ const CountdownModeButtons({
super.key, super.key,
@ -18,6 +19,7 @@ class CountdownModeButtons extends StatelessWidget {
required this.deviceId, required this.deviceId,
required this.hours, required this.hours,
required this.minutes, required this.minutes,
required this.countDownCode,
}); });
@override @override
@ -43,6 +45,7 @@ class CountdownModeButtons extends StatelessWidget {
StopScheduleEvent( StopScheduleEvent(
mode: ScheduleModes.countdown, mode: ScheduleModes.countdown,
deviceId: deviceId, deviceId: deviceId,
countdownCode: countDownCode,
), ),
); );
}, },
@ -57,7 +60,7 @@ class CountdownModeButtons extends StatelessWidget {
mode: ScheduleModes.countdown, mode: ScheduleModes.countdown,
hours: hours, hours: hours,
minutes: minutes, minutes: minutes,
), countDownCode: countDownCode),
); );
}, },
backgroundColor: ColorsManager.primaryColor, backgroundColor: ColorsManager.primaryColor,

View File

@ -75,23 +75,33 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
final isCountDown = state.scheduleMode == ScheduleModes.countdown; final isCountDown = state.scheduleMode == ScheduleModes.countdown;
final isActive = final isActive =
isCountDown ? state.isCountdownActive : state.isInchingActive; isCountDown ? state.isCountdownActive : state.isInchingActive;
final displayHours = isActive && state.countdownRemaining != null
? state.countdownRemaining!.inHours final displayHours =
isActive && state.countdownRemaining != Duration.zero
? state.countdownRemaining.inHours
: (isCountDown ? state.countdownHours : state.inchingHours); : (isCountDown ? state.countdownHours : state.inchingHours);
final displayMinutes = isActive && state.countdownRemaining != null
? state.countdownRemaining!.inMinutes.remainder(60) final displayMinutes =
isActive && state.countdownRemaining != Duration.zero
? state.countdownRemaining.inMinutes.remainder(60)
: (isCountDown ? state.countdownMinutes : state.inchingMinutes); : (isCountDown ? state.countdownMinutes : state.inchingMinutes);
final displaySeconds = isActive && state.countdownRemaining != null
? state.countdownRemaining!.inSeconds.remainder(60)
: (isCountDown ? state.countdownSeconds : state.inchingSeconds);
_updateControllers(displayHours, displayMinutes, displaySeconds!); final displaySeconds =
isActive && state.countdownRemaining != Duration.zero
? state.countdownRemaining.inSeconds.remainder(60)
: (isCountDown ? (state.countdownSeconds ?? 0) : 0);
if (displayHours == 0 && displayMinutes == 0 && displaySeconds == 0) { _updateControllers(displayHours, displayMinutes, displaySeconds);
if (isActive &&
displayHours == 0 &&
displayMinutes == 0 &&
displaySeconds == 0) {
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
StopScheduleEvent( StopScheduleEvent(
mode: ScheduleModes.countdown, mode: ScheduleModes.countdown,
deviceId: widget.deviceId, deviceId: widget.deviceId,
countdownCode: '',
), ),
); );
} }

View File

@ -43,7 +43,9 @@ class InchingModeButtons extends StatelessWidget {
onPressed: () { onPressed: () {
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
StopScheduleEvent( StopScheduleEvent(
deviceId: deviceId, mode: ScheduleModes.inching), deviceId: deviceId,
mode: ScheduleModes.inching,
countdownCode: ''),
); );
}, },
backgroundColor: Colors.red, backgroundColor: Colors.red,

View File

@ -18,11 +18,15 @@ class BuildScheduleView extends StatelessWidget {
super.key, super.key,
required this.deviceUuid, required this.deviceUuid,
required this.category, required this.category,
required this.countdownCode,
this.code, this.code,
required this.deviceType,
}); });
final String deviceUuid; final String deviceUuid;
final String category; final String category;
final String? code; final String? code;
final String? countdownCode;
final String deviceType;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -31,7 +35,8 @@ class BuildScheduleView extends StatelessWidget {
deviceId: deviceUuid, deviceId: deviceUuid,
) )
..add(ScheduleGetEvent(category: category)) ..add(ScheduleGetEvent(category: category))
..add(ScheduleFetchStatusEvent(deviceUuid)), ..add(ScheduleFetchStatusEvent(
deviceId: deviceUuid, countdownCode: countdownCode ?? '')),
child: Dialog( child: Dialog(
backgroundColor: Colors.white, backgroundColor: Colors.white,
insetPadding: const EdgeInsets.all(20), insetPadding: const EdgeInsets.all(20),
@ -52,21 +57,22 @@ class BuildScheduleView extends StatelessWidget {
children: [ children: [
const ScheduleHeader(), const ScheduleHeader(),
const SizedBox(height: 20), const SizedBox(height: 20),
if (category == 'CUR_2') if (deviceType == 'CUR_2')
const SizedBox() const SizedBox()
else else
ScheduleModeSelector( ScheduleModeSelector(
countdownCode: countdownCode ?? '',
currentMode: state.scheduleMode, currentMode: state.scheduleMode,
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
if (state.scheduleMode == ScheduleModes.schedule) if (state.scheduleMode == ScheduleModes.schedule)
ScheduleManagementUI( ScheduleManagementUI(
deviceType: deviceType,
category: category, category: category,
deviceUuid: deviceUuid, deviceUuid: deviceUuid,
onAddSchedule: () async { onAddSchedule: () async {
final entry = await ScheduleDialogHelper final entry = await ScheduleDialogHelper
.showAddScheduleDialog( .showAddScheduleDialog(context,
context,
schedule: ScheduleEntry( schedule: ScheduleEntry(
category: category, category: category,
time: '', time: '',
@ -76,7 +82,7 @@ class BuildScheduleView extends StatelessWidget {
), ),
isEdit: false, isEdit: false,
code: code, code: code,
); deviceType: deviceType);
if (entry != null) { if (entry != null) {
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
ScheduleAddEvent( ScheduleAddEvent(
@ -90,6 +96,7 @@ class BuildScheduleView extends StatelessWidget {
} }
}, },
), ),
if (deviceType != 'CUR_2')
if (state.scheduleMode == ScheduleModes.countdown || if (state.scheduleMode == ScheduleModes.countdown ||
state.scheduleMode == ScheduleModes.inching) state.scheduleMode == ScheduleModes.inching)
CountdownInchingView( CountdownInchingView(
@ -98,6 +105,7 @@ class BuildScheduleView extends StatelessWidget {
const SizedBox(height: 20), const SizedBox(height: 20),
if (state.scheduleMode == ScheduleModes.countdown) if (state.scheduleMode == ScheduleModes.countdown)
CountdownModeButtons( CountdownModeButtons(
countDownCode: countdownCode ?? '',
isActive: state.isCountdownActive, isActive: state.isCountdownActive,
deviceId: deviceUuid, deviceId: deviceUuid,
hours: state.countdownHours, hours: state.countdownHours,

View File

@ -8,11 +8,13 @@ class ScheduleManagementUI extends StatelessWidget {
final String deviceUuid; final String deviceUuid;
final VoidCallback onAddSchedule; final VoidCallback onAddSchedule;
final String category; final String category;
final String deviceType;
const ScheduleManagementUI({ const ScheduleManagementUI({
super.key, super.key,
required this.deviceUuid, required this.deviceUuid,
required this.onAddSchedule, required this.onAddSchedule,
required this.deviceType,
this.category = 'switch_1', this.category = 'switch_1',
}); });
@ -44,7 +46,11 @@ class ScheduleManagementUI extends StatelessWidget {
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
ScheduleTableWidget(deviceUuid: deviceUuid, category: category), ScheduleTableWidget(
deviceUuid: deviceUuid,
category: category,
deviceType: deviceType,
),
], ],
); );
} }

View File

@ -7,10 +7,12 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
class ScheduleModeSelector extends StatelessWidget { class ScheduleModeSelector extends StatelessWidget {
final ScheduleModes currentMode; final ScheduleModes currentMode;
final String countdownCode;
const ScheduleModeSelector({ const ScheduleModeSelector({
super.key, super.key,
required this.currentMode, required this.currentMode,
required this.countdownCode,
}); });
@override @override
@ -71,7 +73,8 @@ class ScheduleModeSelector extends StatelessWidget {
onChanged: (ScheduleModes? value) { onChanged: (ScheduleModes? value) {
if (value != null) { if (value != null) {
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
UpdateScheduleModeEvent(scheduleMode: value), UpdateScheduleModeEvent(
scheduleMode: value, countdownCode: countdownCode),
); );
if (value == ScheduleModes.schedule) { if (value == ScheduleModes.schedule) {
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(

View File

@ -12,11 +12,13 @@ import 'package:syncrow_web/utils/format_date_time.dart';
class ScheduleTableWidget extends StatelessWidget { class ScheduleTableWidget extends StatelessWidget {
final String deviceUuid; final String deviceUuid;
final String category; final String category;
final String deviceType;
const ScheduleTableWidget({ const ScheduleTableWidget({
super.key, super.key,
required this.deviceUuid, required this.deviceUuid,
this.category = 'switch_1', this.category = 'switch_1',
required this.deviceType,
}); });
@override @override
@ -25,13 +27,14 @@ class ScheduleTableWidget extends StatelessWidget {
create: (_) => ScheduleBloc( create: (_) => ScheduleBloc(
deviceId: deviceUuid, deviceId: deviceUuid,
)..add(ScheduleGetEvent(category: category)), )..add(ScheduleGetEvent(category: category)),
child: _ScheduleTableView(), child: _ScheduleTableView(deviceType),
); );
} }
} }
class _ScheduleTableView extends StatelessWidget { class _ScheduleTableView extends StatelessWidget {
const _ScheduleTableView(); final String deviceType;
const _ScheduleTableView(this.deviceType);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -81,7 +84,7 @@ class _ScheduleTableView extends StatelessWidget {
bottomLeft: Radius.circular(20), bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20)), bottomRight: Radius.circular(20)),
), ),
child: _buildTableBody(state.schedules, context)); child: _buildTableBody(state.schedules, context, deviceType));
} }
if (state is ScheduleError) { if (state is ScheduleError) {
return Center(child: Text(state.error)); return Center(child: Text(state.error));
@ -123,7 +126,8 @@ class _ScheduleTableView extends StatelessWidget {
); );
} }
Widget _buildTableBody(List<ScheduleModel> schedules, BuildContext context) { Widget _buildTableBody(
List<ScheduleModel> schedules, BuildContext context, String deviceType) {
return SizedBox( return SizedBox(
height: 200, height: 200,
child: SingleChildScrollView( child: SingleChildScrollView(
@ -132,7 +136,8 @@ class _ScheduleTableView extends StatelessWidget {
defaultVerticalAlignment: TableCellVerticalAlignment.middle, defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [ children: [
for (int i = 0; i < schedules.length; i++) for (int i = 0; i < schedules.length; i++)
_buildScheduleRow(schedules[i], i, context), _buildScheduleRow(schedules[i], i, context,
deviceType: deviceType),
], ],
), ),
), ),
@ -155,25 +160,19 @@ class _ScheduleTableView extends StatelessWidget {
} }
TableRow _buildScheduleRow( TableRow _buildScheduleRow(
ScheduleModel schedule, int index, BuildContext context) { ScheduleModel schedule, int index, BuildContext context,
{required String deviceType}) {
return TableRow( return TableRow(
children: [ children: [
Center( Center(
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
bool temp;
if (schedule.category == 'CUR_2') {
temp = schedule.function.value == 'open' ? true : false;
} else {
temp = schedule.function.value as bool;
}
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
ScheduleUpdateEntryEvent( ScheduleUpdateEntryEvent(
category: schedule.category, category: schedule.category,
scheduleId: schedule.scheduleId, scheduleId: schedule.scheduleId,
functionOn: temp, functionOn: schedule.function.value,
// schedule.function.value,
enable: !schedule.enable, enable: !schedule.enable,
), ),
); );
@ -195,8 +194,9 @@ class _ScheduleTableView extends StatelessWidget {
child: Text(_getSelectedDays( child: Text(_getSelectedDays(
ScheduleModel.parseSelectedDays(schedule.days)))), ScheduleModel.parseSelectedDays(schedule.days)))),
Center(child: Text(formatIsoStringToTime(schedule.time, context))), Center(child: Text(formatIsoStringToTime(schedule.time, context))),
if (schedule.category == 'CUR_2') if (deviceType == 'CUR_2')
Center(child: Text(schedule.function.value)) Center(
child: Text(schedule.function.value == true ? 'open' : 'close'))
else else
Center(child: Text(schedule.function.value ? 'On' : 'Off')), Center(child: Text(schedule.function.value ? 'On' : 'Off')),
Center( Center(
@ -206,14 +206,14 @@ class _ScheduleTableView extends StatelessWidget {
TextButton( TextButton(
style: TextButton.styleFrom(padding: EdgeInsets.zero), style: TextButton.styleFrom(padding: EdgeInsets.zero),
onPressed: () { onPressed: () {
ScheduleDialogHelper.showAddScheduleDialog( ScheduleDialogHelper.showAddScheduleDialog(context,
context,
schedule: ScheduleEntry.fromScheduleModel(schedule), schedule: ScheduleEntry.fromScheduleModel(schedule),
isEdit: true, isEdit: true,
).then((updatedSchedule) { deviceType: deviceType)
.then((updatedSchedule) {
if (updatedSchedule != null) { if (updatedSchedule != null) {
bool temp; bool temp;
if (schedule.category == 'CUR_2') { if (deviceType == 'CUR_2') {
updatedSchedule.function.value == 'open' updatedSchedule.function.value == 'open'
? temp = true ? temp = true
: temp = false; : temp = false;
@ -222,6 +222,7 @@ class _ScheduleTableView extends StatelessWidget {
} }
context.read<ScheduleBloc>().add( context.read<ScheduleBloc>().add(
ScheduleEditEvent( ScheduleEditEvent(
deviceType: deviceType,
scheduleId: schedule.scheduleId, scheduleId: schedule.scheduleId,
category: schedule.category, category: schedule.category,
time: updatedSchedule.time, time: updatedSchedule.time,

View File

@ -111,6 +111,8 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_1', category: 'switch_1',
deviceUuid: deviceId, deviceUuid: deviceId,
countdownCode: 'countdown_1',
deviceType: '3GT',
), ),
)); ));
}, },
@ -127,6 +129,8 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_2', category: 'switch_2',
deviceUuid: deviceId, deviceUuid: deviceId,
countdownCode: 'countdown_2',
deviceType: '3GT',
), ),
)); ));
}, },
@ -143,6 +147,8 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_3', category: 'switch_3',
deviceUuid: deviceId, deviceUuid: deviceId,
countdownCode: 'countdown_3',
deviceType: '3GT',
), ),
)); ));
}, },

View File

@ -102,6 +102,8 @@ class LivingRoomDeviceControlsView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_1', category: 'switch_1',
countdownCode: 'countdown_1',
deviceType: '3G',
), ),
)); ));
}, },
@ -118,6 +120,8 @@ class LivingRoomDeviceControlsView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_2', category: 'switch_2',
countdownCode: 'countdown_2',
deviceType: '3G',
), ),
)); ));
}, },
@ -134,6 +138,8 @@ class LivingRoomDeviceControlsView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_3', category: 'switch_3',
countdownCode: 'countdown_3',
deviceType: '3G',
), ),
)); ));
}, },

View File

@ -102,6 +102,8 @@ class TwoGangGlassSwitchControlView extends StatelessWidget
builder: (ctx) => BlocProvider.value( builder: (ctx) => BlocProvider.value(
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context), value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
child: BuildScheduleView( child: BuildScheduleView(
deviceType: '2GT',
countdownCode: 'countdown_1',
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_1', category: 'switch_1',
), ),
@ -118,6 +120,8 @@ class TwoGangGlassSwitchControlView extends StatelessWidget
builder: (ctx) => BlocProvider.value( builder: (ctx) => BlocProvider.value(
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context), value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
child: BuildScheduleView( child: BuildScheduleView(
deviceType: '2GT',
countdownCode: 'countdown_2',
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_2', category: 'switch_2',
), ),

View File

@ -97,6 +97,8 @@ class TwoGangBatchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_1', category: 'switch_1',
deviceUuid: deviceIds.first, deviceUuid: deviceIds.first,
countdownCode: 'countdown_1',
deviceType: '2G',
), ),
)); ));
}, },
@ -114,6 +116,8 @@ class TwoGangBatchControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
category: 'switch_2', category: 'switch_2',
deviceUuid: deviceIds.first, deviceUuid: deviceIds.first,
countdownCode: 'countdown_2',
deviceType: '2G',
), ),
)); ));
}, },
@ -121,10 +125,7 @@ class TwoGangBatchControlView extends StatelessWidget
subtitle: 'Scheduling', subtitle: 'Scheduling',
iconPath: Assets.scheduling, iconPath: Assets.scheduling,
), ),
// FirmwareUpdateWidget(
// deviceId: deviceIds.first,
// version: 12,
// ),
FactoryResetWidget(callFactoryReset: () { FactoryResetWidget(callFactoryReset: () {
context.read<TwoGangSwitchBloc>().add( context.read<TwoGangSwitchBloc>().add(
TwoGangFactoryReset( TwoGangFactoryReset(

View File

@ -103,6 +103,8 @@ class TwoGangDeviceControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_1', category: 'switch_1',
countdownCode: 'countdown_1',
deviceType: '2G',
), ),
)); ));
}, },
@ -125,6 +127,8 @@ class TwoGangDeviceControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: deviceId, deviceUuid: deviceId,
category: 'switch_2', category: 'switch_2',
countdownCode: 'countdown_2',
deviceType: '2G',
), ),
)); ));
}, },

View File

@ -18,9 +18,10 @@ class ScheduleDialogHelper {
ScheduleEntry? schedule, ScheduleEntry? schedule,
bool isEdit = false, bool isEdit = false,
String? code, String? code,
required String deviceType,
}) { }) {
bool temp; bool temp;
if (schedule?.category == 'CUR_2') { if (deviceType == 'CUR_2') {
temp = schedule!.function.value == 'open' ? true : false; temp = schedule!.function.value == 'open' ? true : false;
} else { } else {
temp = schedule!.function.value; temp = schedule!.function.value;
@ -103,8 +104,7 @@ class ScheduleDialogHelper {
setState(() => selectedDays[i] = v); setState(() => selectedDays[i] = v);
}), }),
const SizedBox(height: 16), const SizedBox(height: 16),
_buildFunctionSwitch(schedule!.category, ctx, functionOn!, _buildFunctionSwitch(deviceType, ctx, functionOn!, (v) {
(v) {
setState(() => functionOn = v); setState(() => functionOn = v);
}), }),
], ],
@ -124,28 +124,25 @@ class ScheduleDialogHelper {
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () {
dynamic temp; dynamic temp;
if (schedule?.category == 'CUR_2') { if (deviceType == 'CUR_2') {
temp = functionOn! ? 'open' : 'close'; temp = functionOn! ? 'open' : 'close';
} else { } else {
temp = functionOn; temp = functionOn;
} }
print(temp);
final entry = ScheduleEntry( final entry = ScheduleEntry(
category: schedule?.category ?? 'switch_1', category: schedule?.category ?? 'switch_1',
time: _formatTimeOfDayToISO(selectedTime), time: _formatTimeOfDayToISO(selectedTime),
function: Status( function: Status(
code: code ?? 'switch_1', code: code ?? 'switch_1',
value: temp, value: temp,
// functionOn,
), ),
days: _convertSelectedDaysToStrings(selectedDays), days: _convertSelectedDaysToStrings(selectedDays),
scheduleId: schedule?.scheduleId, scheduleId: schedule.scheduleId,
); );
Navigator.pop(ctx, entry); Navigator.pop(ctx, entry);
}, },
child: const Text('Save'), child: const Text('Save'),
), )),
),
], ],
); );
}, },

View File

@ -84,6 +84,8 @@ class WaterHeaterDeviceControlView extends StatelessWidget
child: BuildScheduleView( child: BuildScheduleView(
deviceUuid: device.uuid ?? '', deviceUuid: device.uuid ?? '',
category: 'switch_1', category: 'switch_1',
countdownCode: 'countdown_1',
deviceType: 'WH',
), ),
)); ));
}, },