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> implementedDevices = [];
const allowedDevices = <DeviceType>{
DeviceType.OneGang,
DeviceType.TwoGang,
DeviceType.ThreeGang,
const allowedDeviceTypes = {
DeviceType.AC,
DeviceType.DoorLock,
DeviceType.Gateway,
DeviceType.WallSensor,
DeviceType.CeilingSensor
DeviceType.CeilingSensor,
DeviceType.ThreeGang,
DeviceType.OneGang,
};
for (final device in devices) {
final isDeviceAllowed = allowedDevices.contains(device.productType);
if (isDeviceAllowed) {
implementedDevices.add(device);
}
return implementedDevices;
}
return implementedDevices;
return devices
.where((device) => allowedDeviceTypes.contains(device.productType))
.toList();
}
}