Refactor device filtering logic to improve code readability

This commit is contained in:
mohammad
2025-04-17 10:38:25 +03:00
parent 7005d8ba83
commit 5493ca6fb0

View File

@ -170,26 +170,18 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
} }
List<DeviceModel> _getOnlyImplementedDevices(List<DeviceModel> devices) { List<DeviceModel> _getOnlyImplementedDevices(List<DeviceModel> devices) {
List<DeviceModel> implementedDevices = []; const allowedDeviceTypes = {
const allowedDevices = <DeviceType>{
DeviceType.OneGang,
DeviceType.TwoGang,
DeviceType.ThreeGang,
DeviceType.AC, DeviceType.AC,
DeviceType.DoorLock, DeviceType.DoorLock,
DeviceType.Gateway, DeviceType.Gateway,
DeviceType.WallSensor, DeviceType.WallSensor,
DeviceType.CeilingSensor DeviceType.CeilingSensor,
DeviceType.ThreeGang,
DeviceType.OneGang,
}; };
for (final device in devices) { return devices
final isDeviceAllowed = allowedDevices.contains(device.productType); .where((device) => allowedDeviceTypes.contains(device.productType))
if (isDeviceAllowed) { .toList();
implementedDevices.add(device);
}
return implementedDevices;
}
return implementedDevices;
} }
} }