mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 22:47:54 +00:00
garage Alarm
This commit is contained in:
@@ -34,11 +34,14 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
on<ToggleDoorEvent>(openCloseGarageDoor);
|
||||
on<GetCounterEvent>(_getCounterValue);
|
||||
on<SetCounterValue>(_setCounterValue);
|
||||
on<SetTimeOutValue>(_setTimeOutAlarm);
|
||||
on<TickTimer>(_onTickTimer);
|
||||
on<InitialWizardEvent>(_fetchWizardStatus);
|
||||
on<GroupAllOnEvent>(_groupAllOn);
|
||||
on<GroupAllOffEvent>(_groupAllOff);
|
||||
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
||||
on<ToggleAlarmEvent>(_toggleAlarmEvent);
|
||||
//_toggleAlarmEvent
|
||||
}
|
||||
void _onClose(OnClose event, Emitter<GarageDoorSensorState> emit) {
|
||||
_timer?.cancel();
|
||||
@@ -84,6 +87,32 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleAlarmEvent(
|
||||
ToggleAlarmEvent event,
|
||||
Emitter<GarageDoorSensorState> emit,
|
||||
) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
|
||||
try {
|
||||
deviceStatus.doorState1 = event.isEnabled;
|
||||
|
||||
emit(UpdateState(garageSensor: deviceStatus));
|
||||
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: GDId,
|
||||
code: 'door_state_1',
|
||||
value: event.isEnabled,
|
||||
),
|
||||
GDId,
|
||||
);
|
||||
|
||||
emit(UpdateState(garageSensor: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleClosingReminder(ToggleClosingReminderEvent event,
|
||||
Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
@@ -563,4 +592,29 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
add(InitialEvent(groupScreen: oneGangGroup));
|
||||
}
|
||||
}
|
||||
|
||||
void _setTimeOutAlarm(
|
||||
SetTimeOutValue event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: GDId, code: 'countdown_alarm', value: seconds),
|
||||
GDId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.countdownAlarm = seconds;
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
add(GetScheduleEvent());
|
||||
} else {
|
||||
emit(const GarageDoorFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ class GetCounterEvent extends GarageDoorEvent {
|
||||
List<Object> get props => [deviceCode];
|
||||
}
|
||||
|
||||
class ToggleLowBatteryEvent extends GarageDoorEvent {
|
||||
final bool isLowBatteryEnabled;
|
||||
class ToggleAlarmEvent extends GarageDoorEvent {
|
||||
final String isEnabled;
|
||||
|
||||
const ToggleLowBatteryEvent(this.isLowBatteryEnabled);
|
||||
const ToggleAlarmEvent(this.isEnabled);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isLowBatteryEnabled];
|
||||
List<Object> get props => [isEnabled];
|
||||
}
|
||||
|
||||
class ToggleClosingReminderEvent extends GarageDoorEvent {
|
||||
@@ -74,6 +74,14 @@ class SetCounterValue extends GarageDoorEvent {
|
||||
List<Object> get props => [duration, deviceCode];
|
||||
}
|
||||
|
||||
class SetTimeOutValue extends GarageDoorEvent {
|
||||
final Duration duration;
|
||||
final String deviceCode;
|
||||
const SetTimeOutValue({required this.duration, required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [duration, deviceCode];
|
||||
}
|
||||
|
||||
class StartTimer extends GarageDoorEvent {
|
||||
final int duration;
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
}
|
||||
|
||||
void _fetchCeilingSensorStatus(
|
||||
InitialEvent event, Emitter<WallSensorState> emit) async {
|
||||
InitialEvent event,
|
||||
Emitter<WallSensorState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
||||
|
||||
Reference in New Issue
Block a user