mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 22:07:55 +00:00
count_down_ac
This commit is contained in:
@@ -14,6 +14,7 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final String acId;
|
||||
AcStatusModel deviceStatus = AcStatusModel(
|
||||
countdown1: 0,
|
||||
uuid: '',
|
||||
acSwitch: true,
|
||||
modeString: 'hot',
|
||||
@@ -41,6 +42,12 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
on<IncreaseAllTemp>(_increaseAllTemp);
|
||||
on<DecreaseAllTemp>(_decreaseAllTemp);
|
||||
on<AcUpdated>(_onAcUpdated);
|
||||
on<OnClose>(_onClose);
|
||||
on<GetCounterEvent>(_getCounterValue);
|
||||
on<SetCounterValue>(_setCounterValue);
|
||||
on<TickTimer>(_onTickTimer);
|
||||
|
||||
// on<SetTimeOutValue>(_setTimeOutAlarm);
|
||||
}
|
||||
|
||||
void _fetchAcsStatus(AcsInitial event, Emitter<AcsState> emit) async {
|
||||
@@ -61,7 +68,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
@@ -74,18 +82,22 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$acId');
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$acId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) {
|
||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
List<StatusModel> statusList = [];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||
statusList
|
||||
.add(StatusModel(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus = AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
add(AcUpdated());
|
||||
});
|
||||
} catch (_) {}
|
||||
@@ -102,12 +114,14 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
var response =
|
||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatusList.add(AcStatusModel.fromJson(response['productUuid'], statusModelList));
|
||||
deviceStatusList.add(
|
||||
AcStatusModel.fromJson(response['productUuid'], statusModelList));
|
||||
}
|
||||
_setAllAcsTempsAndSwitches();
|
||||
}
|
||||
@@ -129,7 +143,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'switch', value: acSwitchValue);
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: event.deviceId, code: 'switch', value: acSwitchValue);
|
||||
}
|
||||
|
||||
void _changeAllAcSwitch(ChangeAllSwitch event, Emitter<AcsState> emit) async {
|
||||
@@ -190,7 +205,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
deviceStatus.childLock = lockValue;
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
|
||||
await _runDeBouncerForOneDevice(deviceId: acId, code: 'child_lock', value: lockValue);
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: acId, code: 'child_lock', value: lockValue);
|
||||
}
|
||||
|
||||
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
@@ -218,7 +234,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||
}
|
||||
|
||||
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
@@ -246,7 +263,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: event.deviceId, code: 'temp_set', value: value);
|
||||
}
|
||||
|
||||
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||
@@ -268,7 +286,9 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
}
|
||||
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: event.deviceId, code: 'mode', value: getACModeString(tempMode));
|
||||
deviceId: event.deviceId,
|
||||
code: 'mode',
|
||||
value: getACModeString(tempMode));
|
||||
}
|
||||
|
||||
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||
@@ -281,19 +301,23 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
for (AcStatusModel ac in deviceStatusList) {
|
||||
if (ac.uuid == event.productId) {
|
||||
ac.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
||||
ac.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
ac.acFanSpeed =
|
||||
AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
}
|
||||
}
|
||||
_emitAcsStatus(emit);
|
||||
} else {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
||||
deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
deviceStatus.acFanSpeed =
|
||||
AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
await _runDeBouncerForOneDevice(
|
||||
deviceId: event.deviceId, code: 'level', value: getNextFanSpeedKey(fanSpeed));
|
||||
deviceId: event.deviceId,
|
||||
code: 'level',
|
||||
value: getNextFanSpeedKey(fanSpeed));
|
||||
}
|
||||
|
||||
String getACModeString(TempModes value) {
|
||||
@@ -338,7 +362,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
for (int i = 0; i < deviceStatusList.length; i++) {
|
||||
try {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: devicesList[i].uuid, code: code, value: value),
|
||||
DeviceControlModel(
|
||||
deviceId: devicesList[i].uuid, code: code, value: value),
|
||||
devicesList[i].uuid ?? '');
|
||||
} catch (_) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
@@ -360,7 +385,10 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
_timer = Timer(const Duration(seconds: 1), () async {
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: allAcsPage ? deviceId : acId, code: code, value: value),
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? deviceId : acId,
|
||||
code: code,
|
||||
value: value),
|
||||
allAcsPage ? deviceId : acId);
|
||||
|
||||
if (!response['success']) {
|
||||
@@ -377,7 +405,8 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
if (value >= 20 && value <= 30) {
|
||||
return true;
|
||||
} else {
|
||||
emit(const AcsFailedState(errorMessage: 'The temperature must be between 20 and 30'));
|
||||
emit(const AcsFailedState(
|
||||
errorMessage: 'The temperature must be between 20 and 30'));
|
||||
emit(GetAllAcsStatusState(
|
||||
allAcsStatues: deviceStatusList,
|
||||
allAcs: devicesList,
|
||||
@@ -396,4 +425,90 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
allTempSame: allTempSame,
|
||||
temp: globalTemp));
|
||||
}
|
||||
|
||||
void _setCounterValue(SetCounterValue event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.seconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: acId, code: 'countdown_time', value: event.duration),
|
||||
acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.countdown1 = seconds;
|
||||
|
||||
emit(UpdateTimerState(seconds: deviceStatus.countdown1));
|
||||
} else {
|
||||
emit(const AcsFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
if (seconds > 0) {
|
||||
_onStartTimer(seconds);
|
||||
} else {
|
||||
_timer?.cancel();
|
||||
emit(TimerRunComplete());
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<AcsState> emit) async {
|
||||
try {
|
||||
emit(AcsLoadingState());
|
||||
var response = await DevicesAPI.getDeviceStatus(acId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(response['productUuid'], statusModelList);
|
||||
|
||||
if (event.deviceCode == 'countdown_time') {
|
||||
deviceStatus.countdown1 > 0
|
||||
? _onStartTimer(deviceStatus.countdown1)
|
||||
: emit(UpdateTimerState(seconds: deviceStatus.countdown1));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _onStartTimer(int seconds) {
|
||||
_timer?.cancel(); // Cancel any existing timer
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
final remainingTime = seconds - timer.tick;
|
||||
if (remainingTime > 0) {
|
||||
if (!isClosed) {
|
||||
// Check if the Bloc is still active
|
||||
add(TickTimer(remainingTime: remainingTime));
|
||||
}
|
||||
} else {
|
||||
_timer?.cancel();
|
||||
if (!isClosed) {
|
||||
emit(TimerRunComplete());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onTickTimer(TickTimer event, Emitter<AcsState> emit) {
|
||||
if (!isClosed) {
|
||||
// Check if the Bloc is still active
|
||||
if (event.remainingTime > 0) {
|
||||
emit(TimerRunInProgress(event.remainingTime));
|
||||
} else {
|
||||
_timer?.cancel();
|
||||
emit(TimerRunComplete());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onClose(OnClose event, Emitter<AcsState> emit) {
|
||||
_timer?.cancel(); // Cancel the timer
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ class AcSwitch extends AcsEvent {
|
||||
final bool acSwitch;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const AcSwitch({required this.acSwitch, this.deviceId = '', this.productId = ''});
|
||||
const AcSwitch(
|
||||
{required this.acSwitch, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acSwitch, deviceId, productId];
|
||||
@@ -35,7 +36,8 @@ class IncreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const IncreaseCoolToTemp({required this.value, this.deviceId = '', this.productId = ''});
|
||||
const IncreaseCoolToTemp(
|
||||
{required this.value, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value, deviceId];
|
||||
@@ -46,7 +48,8 @@ class DecreaseCoolToTemp extends AcsEvent {
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
|
||||
const DecreaseCoolToTemp({required this.value, this.deviceId = '', this.productId = ''});
|
||||
const DecreaseCoolToTemp(
|
||||
{required this.value, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value, deviceId];
|
||||
@@ -56,7 +59,8 @@ class ChangeAcMode extends AcsEvent {
|
||||
final TempModes tempModes;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const ChangeAcMode({required this.tempModes, this.deviceId = '', this.productId = ''});
|
||||
const ChangeAcMode(
|
||||
{required this.tempModes, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes, deviceId, productId];
|
||||
@@ -67,7 +71,8 @@ class ChangeFanSpeed extends AcsEvent {
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
|
||||
const ChangeFanSpeed({required this.fanSpeeds, this.deviceId = '', this.productId = ''});
|
||||
const ChangeFanSpeed(
|
||||
{required this.fanSpeeds, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds, deviceId, productId];
|
||||
@@ -104,3 +109,52 @@ class DecreaseAllTemp extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class SetCounterValue extends AcsEvent {
|
||||
final int duration;
|
||||
final String deviceCode;
|
||||
final int seconds;
|
||||
const SetCounterValue(
|
||||
{required this.duration,
|
||||
required this.deviceCode,
|
||||
required this.seconds});
|
||||
@override
|
||||
List<Object> get props => [duration, deviceCode, seconds];
|
||||
}
|
||||
|
||||
class SetTimeOutValue extends AcsEvent {
|
||||
final Duration duration;
|
||||
final String deviceCode;
|
||||
const SetTimeOutValue({required this.duration, required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [duration, deviceCode];
|
||||
}
|
||||
|
||||
class StartTimer extends AcsEvent {
|
||||
final int duration;
|
||||
|
||||
const StartTimer(this.duration);
|
||||
|
||||
@override
|
||||
List<Object> get props => [duration];
|
||||
}
|
||||
|
||||
class TickTimer extends AcsEvent {
|
||||
final int remainingTime;
|
||||
|
||||
const TickTimer({required this.remainingTime});
|
||||
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
class StopTimer extends AcsEvent {}
|
||||
|
||||
class GetCounterEvent extends AcsEvent {
|
||||
final String deviceCode;
|
||||
const GetCounterEvent({required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [deviceCode];
|
||||
}
|
||||
|
||||
class OnClose extends AcsEvent {}
|
||||
|
||||
@@ -63,3 +63,22 @@ class AcsFailedState extends AcsState {
|
||||
@override
|
||||
List<Object> get props => [errorMessage];
|
||||
}
|
||||
|
||||
class UpdateTimerState extends AcsState {
|
||||
final int seconds;
|
||||
const UpdateTimerState({required this.seconds});
|
||||
|
||||
@override
|
||||
List<Object> get props => [seconds];
|
||||
}
|
||||
|
||||
class TimerRunInProgress extends AcsState {
|
||||
final int remainingTime;
|
||||
|
||||
const TimerRunInProgress(this.remainingTime);
|
||||
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
class TimerRunComplete extends AcsState {}
|
||||
|
||||
@@ -65,7 +65,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
batteryPercentage: 0,
|
||||
);
|
||||
|
||||
void _fetchStatus(GarageDoorInitial event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _fetchStatus(
|
||||
GarageDoorInitial event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(GarageDoorLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(GDId);
|
||||
@@ -113,8 +114,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleClosingReminder(
|
||||
ToggleClosingReminderEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _toggleClosingReminder(ToggleClosingReminderEvent event,
|
||||
Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
try {
|
||||
closingReminder = event.isClosingReminderEnabled;
|
||||
@@ -132,7 +133,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleDoorAlarm(ToggleDoorAlarmEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _toggleDoorAlarm(
|
||||
ToggleDoorAlarmEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
try {
|
||||
doorAlarm = event.isDoorAlarmEnabled;
|
||||
@@ -150,7 +152,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
DeviceReport recordGroups = DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
DeviceReport recordGroups =
|
||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
|
||||
Future<void> fetchLogsForLastMonth(
|
||||
ReportLogsInitial event, Emitter<GarageDoorSensorState> emit) async {
|
||||
@@ -179,14 +182,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$GDId');
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$GDId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) async {
|
||||
if (_timer != null) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
List<StatusModel> statusList = [];
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(StatusModel(code: element['code'], value: true));
|
||||
@@ -261,7 +266,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
deviceId: GDId,
|
||||
);
|
||||
List<dynamic> jsonData = response;
|
||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
listSchedule =
|
||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
emit(UpdateState(garageSensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
@@ -272,12 +278,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
|
||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||
if (dateTime == null) return null;
|
||||
DateTime dateTimeWithoutSeconds =
|
||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||
dateTime.day, dateTime.hour, dateTime.minute);
|
||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
|
||||
Future toggleChange(ToggleScheduleEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
Future toggleChange(
|
||||
ToggleScheduleEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
try {
|
||||
emit(GarageDoorLoadingState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@@ -295,7 +302,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
try {
|
||||
emit(GarageDoorLoadingState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@@ -314,13 +322,15 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<GarageDoorSensorState> emit) {
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<GarageDoorSensorState> emit) {
|
||||
emit(GarageDoorLoadingState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<GarageDoorSensorState> emit) {
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<GarageDoorSensorState> emit) {
|
||||
emit(GarageDoorLoadingState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
@@ -337,13 +347,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
|
||||
int secondSelected = 0;
|
||||
bool toggleDoor = false;
|
||||
Future<void> selectSeconds(SelectSecondsEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
Future<void> selectSeconds(
|
||||
SelectSecondsEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
try {
|
||||
emit(GarageDoorLoadingState());
|
||||
secondSelected = event.seconds;
|
||||
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: GDId, code: 'tr_timecon', value: secondSelected), GDId);
|
||||
DeviceControlModel(
|
||||
deviceId: GDId, code: 'tr_timecon', value: secondSelected),
|
||||
GDId);
|
||||
emit(UpdateState(garageSensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
@@ -352,12 +365,15 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
openCloseGarageDoor(ToggleDoorEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
openCloseGarageDoor(
|
||||
ToggleDoorEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(GarageDoorLoadingState());
|
||||
try {
|
||||
toggleDoor = !event.toggle;
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: GDId, code: 'switch_1', value: toggleDoor), GDId);
|
||||
DeviceControlModel(
|
||||
deviceId: GDId, code: 'switch_1', value: toggleDoor),
|
||||
GDId);
|
||||
add(const GarageDoorInitial());
|
||||
emit(UpdateState(garageSensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
@@ -367,13 +383,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _setCounterValue(SetCounterValue event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _setCounterValue(
|
||||
SetCounterValue 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_1', value: seconds), GDId);
|
||||
DeviceControlModel(
|
||||
deviceId: GDId, code: 'countdown_1', value: seconds),
|
||||
GDId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.countdown1 = seconds;
|
||||
@@ -393,7 +412,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(GDId);
|
||||
@@ -434,7 +454,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
List<GroupGarageModel> groupList = [];
|
||||
bool allSwitchesOn = true;
|
||||
|
||||
void _fetchWizardStatus(InitialWizardEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _fetchWizardStatus(
|
||||
InitialWizardEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
devicesList = [];
|
||||
@@ -444,7 +465,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', 'GD');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
var response =
|
||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
@@ -473,7 +495,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _groupAllOn(GroupAllOnEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _groupAllOn(
|
||||
GroupAllOnEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
try {
|
||||
// Set all switches (firstSwitch and secondSwitch) based on the event value (on/off)
|
||||
@@ -485,7 +508,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
emit(UpdateGroupState(garageList: groupList, allSwitches: true));
|
||||
|
||||
// Get a list of all device IDs
|
||||
List<String> allDeviceIds = groupList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds =
|
||||
groupList.map((device) => device.deviceId).toList();
|
||||
|
||||
// First call for switch_1
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
@@ -505,7 +529,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _groupAllOff(GroupAllOffEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _groupAllOff(
|
||||
GroupAllOffEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
try {
|
||||
// Set all switches (firstSwitch and secondSwitch) based on the event value (on/off)
|
||||
@@ -517,7 +542,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
emit(UpdateGroupState(garageList: groupList, allSwitches: false));
|
||||
|
||||
// Get a list of all device IDs
|
||||
List<String> allDeviceIds = groupList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds =
|
||||
groupList.map((device) => device.deviceId).toList();
|
||||
|
||||
// First call for switch_1
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
@@ -538,8 +564,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFirstWizardSwitch(
|
||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||
Emitter<GarageDoorSensorState> emit) async {
|
||||
emit(LoadingNewSate(doorSensor: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@@ -552,7 +578,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
});
|
||||
|
||||
emit(UpdateGroupState(garageList: groupList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(
|
||||
garageList: groupList, allSwitches: allSwitchesValue));
|
||||
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@@ -568,13 +595,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _setTimeOutAlarm(SetTimeOutValue event, Emitter<GarageDoorSensorState> emit) async {
|
||||
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);
|
||||
DeviceControlModel(
|
||||
deviceId: GDId, code: 'countdown_alarm', value: seconds),
|
||||
GDId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.countdownAlarm = seconds;
|
||||
|
||||
Reference in New Issue
Block a user