mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
ac device
This commit is contained in:
28
lib/pages/device_managment/ac/bloc/ac_bloc.dart
Normal file
28
lib/pages/device_managment/ac/bloc/ac_bloc.dart
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
|
||||
|
||||
class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
AcBloc() : super(AcsInitialState()) {
|
||||
on<AcFetchDeviceStatus>(_onFetchAcStatus);
|
||||
|
||||
}
|
||||
|
||||
FutureOr<void> _onFetchAcStatus(
|
||||
AcFetchDeviceStatus event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
emit(ACStatusLoaded(status));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState( error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
lib/pages/device_managment/ac/bloc/ac_event.dart
Normal file
32
lib/pages/device_managment/ac/bloc/ac_event.dart
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
sealed class AcsEvent extends Equatable {
|
||||
const AcsEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AcFetchDeviceStatus extends AcsEvent {
|
||||
final String deviceId;
|
||||
|
||||
const AcFetchDeviceStatus(this.deviceId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceId];
|
||||
}
|
||||
|
||||
class AcControl extends AcsEvent {
|
||||
final String deviceId;
|
||||
final String code;
|
||||
final bool value;
|
||||
|
||||
const AcControl(
|
||||
{required this.deviceId, required this.code, required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceId, code, value];
|
||||
}
|
||||
|
76
lib/pages/device_managment/ac/bloc/ac_state.dart
Normal file
76
lib/pages/device_managment/ac/bloc/ac_state.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
||||
|
||||
abstract class AcsState extends Equatable {
|
||||
const AcsState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AcsInitialState extends AcsState {}
|
||||
|
||||
class AcsLoadingState extends AcsState {}
|
||||
|
||||
|
||||
class ACStatusLoaded extends AcsState {
|
||||
final DeviceStatus status;
|
||||
|
||||
const ACStatusLoaded(this.status);
|
||||
|
||||
@override
|
||||
List<Object> get props => [status];
|
||||
}
|
||||
|
||||
class AcChangeLoading extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const AcChangeLoading({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class AcModifyingState extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const AcModifyingState({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class GetAcStatusState extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const GetAcStatusState({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class GetAllAcsStatusState extends AcsState {
|
||||
final List<AcStatusModel> allAcsStatues;
|
||||
final List<DeviceModel> allAcs;
|
||||
final bool allOn;
|
||||
final bool allTempSame;
|
||||
final int temp;
|
||||
|
||||
const GetAllAcsStatusState(
|
||||
{required this.allAcsStatues,
|
||||
required this.allAcs,
|
||||
required this.allOn,
|
||||
required this.allTempSame,
|
||||
required this.temp});
|
||||
|
||||
@override
|
||||
List<Object> get props => [allAcsStatues, allAcs, allAcs, allTempSame, temp];
|
||||
}
|
||||
|
||||
class AcsFailedState extends AcsState {
|
||||
final String error;
|
||||
|
||||
const AcsFailedState({required this.error});
|
||||
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
}
|
Reference in New Issue
Block a user