mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 04:47:54 +00:00
Completed wall sensor implementation
This commit is contained in:
@@ -18,6 +18,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
on<ChangeIndicatorEvent>(_changeIndicator);
|
||||
on<ChangeValueEvent>(_changeValue);
|
||||
on<WallSensorUpdatedEvent>(_wallSensorUpdated);
|
||||
on<GetDeviceReportsEvent>(_getDeviceReports);
|
||||
}
|
||||
|
||||
void _fetchCeilingSensorStatus(InitialEvent event, Emitter<WallSensorState> emit) async {
|
||||
@@ -91,4 +92,17 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
} catch (_) {}
|
||||
emit(UpdateState(wallSensorModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _getDeviceReports(GetDeviceReportsEvent event, Emitter<WallSensorState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
|
||||
try {
|
||||
await DevicesAPI.getDeviceReports(deviceId, event.code).then((value) {
|
||||
emit(DeviceReportsState(deviceReport: value, code: event.code));
|
||||
});
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,3 +29,15 @@ class ChangeValueEvent extends WallSensorEvent {
|
||||
@override
|
||||
List<Object> get props => [value, code];
|
||||
}
|
||||
|
||||
class GetDeviceReportsEvent extends WallSensorEvent {
|
||||
final String deviceUuid;
|
||||
final String code;
|
||||
const GetDeviceReportsEvent({
|
||||
required this.deviceUuid,
|
||||
required this.code,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceUuid, code];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/wall_sensor_model.dart';
|
||||
|
||||
class WallSensorState extends Equatable {
|
||||
@@ -36,3 +37,9 @@ class FailedState extends WallSensorState {
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
}
|
||||
|
||||
class DeviceReportsState extends WallSensorState {
|
||||
final DeviceReport deviceReport;
|
||||
final String code;
|
||||
const DeviceReportsState({required this.deviceReport, required this.code});
|
||||
}
|
||||
|
||||
@@ -9,17 +9,18 @@ class WallSensorModel {
|
||||
int currentDistance;
|
||||
int illuminance;
|
||||
bool indicator;
|
||||
int noOneTime;
|
||||
|
||||
WallSensorModel({
|
||||
required this.presenceState,
|
||||
required this.farDetection,
|
||||
required this.presenceTime,
|
||||
required this.motionSensitivity,
|
||||
required this.motionlessSensitivity,
|
||||
required this.currentDistance,
|
||||
required this.illuminance,
|
||||
required this.indicator,
|
||||
});
|
||||
WallSensorModel(
|
||||
{required this.presenceState,
|
||||
required this.farDetection,
|
||||
required this.presenceTime,
|
||||
required this.motionSensitivity,
|
||||
required this.motionlessSensitivity,
|
||||
required this.currentDistance,
|
||||
required this.illuminance,
|
||||
required this.indicator,
|
||||
required this.noOneTime});
|
||||
|
||||
factory WallSensorModel.fromJson(List<StatusModel> jsonList) {
|
||||
late String _presenceState;
|
||||
@@ -30,6 +31,7 @@ class WallSensorModel {
|
||||
late int _currentDistance;
|
||||
late int _illuminance;
|
||||
late bool _indicator;
|
||||
late int _noOneTime;
|
||||
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
if (jsonList[i].code == 'presence_state') {
|
||||
@@ -48,6 +50,8 @@ class WallSensorModel {
|
||||
_illuminance = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'indicator') {
|
||||
_indicator = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'no_one_time') {
|
||||
_noOneTime = jsonList[i].value ?? 0;
|
||||
}
|
||||
}
|
||||
return WallSensorModel(
|
||||
@@ -58,6 +62,7 @@ class WallSensorModel {
|
||||
motionlessSensitivity: _motionlessSensitivity,
|
||||
currentDistance: _currentDistance,
|
||||
illuminance: _illuminance,
|
||||
indicator: _indicator);
|
||||
indicator: _indicator,
|
||||
noOneTime: _noOneTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +215,7 @@ class ParametersList extends StatelessWidget {
|
||||
{
|
||||
'icon': Assets.assetsIconsPresenceSensorAssetsEmpty,
|
||||
'title': 'Nobody Time',
|
||||
'code': null,
|
||||
//TODO: Implement the nobody time
|
||||
'code': 'no_one_time',
|
||||
},
|
||||
{
|
||||
'icon': Assets.assetsIconsPresenceSensorAssetsIndicator,
|
||||
@@ -231,7 +230,7 @@ class ParametersList extends StatelessWidget {
|
||||
{
|
||||
'icon': Assets.assetsIconsPresenceSensorAssetsIlluminanceRecord,
|
||||
'title': 'Illuminance Record',
|
||||
'code': null
|
||||
'code': 'illuminance_value'
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -240,6 +239,7 @@ Widget listItem(Map<String, Object?> wallSensorButton, BuildContext context, Dev
|
||||
WallSensorModel wallSensorStatus) {
|
||||
String? unit;
|
||||
dynamic value;
|
||||
int noBodyTimeValue;
|
||||
if (wallSensorButton['code'] != null) {
|
||||
// if (wallSensor.status.any((element) => element.code == wallSensorButton['code'] as String)) {
|
||||
// unit = unitsMap[wallSensorButton['code'] as String];
|
||||
@@ -256,12 +256,15 @@ Widget listItem(Map<String, Object?> wallSensorButton, BuildContext context, Dev
|
||||
} else if (wallSensorButton['code'] == 'illuminance_value') {
|
||||
unit = unitsMap[wallSensorButton['code'] as String];
|
||||
value = wallSensorStatus.illuminance;
|
||||
} else if (wallSensorButton['code'] == 'no_one_time') {
|
||||
unit = unitsMap[wallSensorButton['code'] as String];
|
||||
value = wallSensorStatus.noOneTime;
|
||||
}
|
||||
}
|
||||
return DefaultContainer(
|
||||
margin: const EdgeInsets.only(bottom: 5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
if (wallSensorButton['page'] != null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -270,6 +273,42 @@ Widget listItem(Map<String, Object?> wallSensorButton, BuildContext context, Dev
|
||||
),
|
||||
);
|
||||
}
|
||||
if (wallSensorButton['title'] == 'Presence Record') {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PresenceRecords(
|
||||
deviceId: wallSensor.uuid!,
|
||||
code: 'presence_state',
|
||||
title: 'Presence Record',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
if (wallSensorButton['title'] == 'Illuminance Record') {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PresenceRecords(
|
||||
deviceId: wallSensor.uuid!,
|
||||
code: 'illuminance_value',
|
||||
title: 'Illuminance Record',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
if (wallSensorButton['title'] == 'Nobody Time') {
|
||||
int noBodyTimeValue = value as int;
|
||||
String controlCode = 'no_one_time';
|
||||
final result = await showDialog(
|
||||
context: context,
|
||||
builder: (context) => ParameterControlDialog(
|
||||
title: 'Nobody Time', sensor: wallSensor, value: noBodyTimeValue, min: 0, max: 10000),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
BlocProvider.of<WallSensorBloc>(context)
|
||||
.add(ChangeValueEvent(value: result, code: controlCode));
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -9,6 +11,8 @@ import 'package:syncrow_app/features/devices/bloc/wall_sensor_bloc/wall_sensor_e
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/wall_sensor_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/garage_door/garage_records_screen.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/wall_sensor/persence_records.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
@@ -41,7 +45,8 @@ class WallMountedInterface extends StatelessWidget {
|
||||
motionlessSensitivity: 0,
|
||||
currentDistance: 0,
|
||||
illuminance: 0,
|
||||
indicator: false);
|
||||
indicator: false,
|
||||
noOneTime: 0);
|
||||
|
||||
if (state is UpdateState) {
|
||||
wallSensorModel = state.wallSensorModel;
|
||||
|
||||
Reference in New Issue
Block a user