mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 08:54:54 +00:00
Refactor device filtering logic and improve code readability
- Extracted the logic for filtering implemented devices into a separate method `_getOnlyImplementedDevices` - Created a set `allowedDevices` to store the allowed device types - Updated the filtering logic to use the `allowedDevices` set for checking device types - Removed unnecessary conditions for filtering devices Fix nullability issues in `Action` model - Added null checks for `actionExecutor`, `entityId`, `name`, `type`, and `productType` properties in the `fromJson` method of the `Action` model - Set default values for `actionExecutor` and `entityId` if they are null - Updated the type casting for `name`, `type`, and `productType` properties to avoid potential nullability issues
This commit is contained in:
@ -169,18 +169,26 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getOnlyImplementedDevices(List<DeviceModel> devices) {
|
List<DeviceModel> _getOnlyImplementedDevices(List<DeviceModel> devices) {
|
||||||
List<DeviceModel> implementedDevices = [];
|
List<DeviceModel> implementedDevices = [];
|
||||||
for (int i = 0; i < devices.length; i++) {
|
|
||||||
if (devices[i].productType == DeviceType.AC ||
|
const allowedDevices = <DeviceType>{
|
||||||
devices[i].productType == DeviceType.DoorLock ||
|
DeviceType.OneGang,
|
||||||
devices[i].productType == DeviceType.Gateway ||
|
DeviceType.TwoGang,
|
||||||
devices[i].productType == DeviceType.WallSensor ||
|
DeviceType.ThreeGang,
|
||||||
devices[i].productType == DeviceType.CeilingSensor ||
|
DeviceType.AC,
|
||||||
devices[i].productType == DeviceType.ThreeGang ||
|
DeviceType.DoorLock,
|
||||||
devices[i].productType == DeviceType.OneGang) {
|
DeviceType.Gateway,
|
||||||
implementedDevices.add(devices[i]);
|
DeviceType.WallSensor,
|
||||||
|
DeviceType.CeilingSensor
|
||||||
|
};
|
||||||
|
|
||||||
|
for (final device in devices) {
|
||||||
|
final isDeviceAllowed = allowedDevices.contains(device.productType);
|
||||||
|
if (isDeviceAllowed) {
|
||||||
|
implementedDevices.add(device);
|
||||||
}
|
}
|
||||||
|
return implementedDevices;
|
||||||
}
|
}
|
||||||
return implementedDevices;
|
return implementedDevices;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,11 +90,11 @@ class Action {
|
|||||||
static Action? fromJson(Map<String, dynamic> json) {
|
static Action? fromJson(Map<String, dynamic> json) {
|
||||||
if (json['name'] != null && json['type'] != null) {
|
if (json['name'] != null && json['type'] != null) {
|
||||||
return Action(
|
return Action(
|
||||||
actionExecutor: json["actionExecutor"],
|
actionExecutor: json["actionExecutor"] ?? '',
|
||||||
entityId: json["entityId"],
|
entityId: json["entityId"] ?? '',
|
||||||
name: json['name'],
|
name: json['name'] as String?,
|
||||||
type: json['type'],
|
type: json['type'] as String?,
|
||||||
productType: json['productType'],
|
productType: json['productType'] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (json["executorProperty"] == null) {
|
if (json["executorProperty"] == null) {
|
||||||
@ -102,10 +102,10 @@ class Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Action(
|
return Action(
|
||||||
actionExecutor: json["actionExecutor"],
|
actionExecutor: json["actionExecutor"] ?? '',
|
||||||
entityId: json["entityId"],
|
entityId: json["entityId"] ?? '',
|
||||||
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||||
productType: json['productType'],
|
productType: json['productType'] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user