//ignore_for_file: constant_identifier_names import 'package:syncrow_app/features/devices/model/function_model.dart'; import 'package:syncrow_app/generated/assets.dart'; abstract class Constants { static const String appName = "Syncrow App"; static const String languageCode = "en"; static const String countryCode = "US"; static const double appBarHeightPercentage = 0.12; static const double bottomNavBarHeightPercentage = 0.1175; static late double appBarHeight; static late double bottomNavBarHeight; static const double defaultPadding = 16; static const String token = ''; } enum SpaceType { Unit, Building, Floor, Room, Community } Map spaceTypesMap = { "unit": SpaceType.Unit, "building": SpaceType.Building, "floor": SpaceType.Floor, "room": SpaceType.Room, "community": SpaceType.Community, }; enum DeviceType { AC, LightBulb, DoorLock, Curtain, Blind, ThreeGang, Gateway, CeilingSensor, WallSensor, Other, } enum FunctionType { Boolean, Enum, Integer, Raw, String } enum ValueACRange { LOW, MIDDLE, HIGH, AUTO } Map functionTypesMap = { "Boolean": FunctionType.Boolean, "Enum": FunctionType.Enum, "Integer": FunctionType.Integer, "Raw": FunctionType.Raw, "String": FunctionType.String, }; Map devicesTypesMap = { "AC": DeviceType.AC, "GW": DeviceType.Gateway, "CPS": DeviceType.CeilingSensor, "DL": DeviceType.DoorLock, "WPS": DeviceType.WallSensor, "3G": DeviceType.ThreeGang, }; Map> devicesFunctionsMap = { DeviceType.AC: [ FunctionModel( code: 'switch', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'mode', type: functionTypesMap['Enum'], values: ValueModel.fromJson({ // "range": ["cold", "hot", "wind"] })), FunctionModel( code: 'temp_set', type: functionTypesMap['Integer'], values: ValueModel.fromJson( { // "unit": {"min": 200, "max": 300, "scale": 1, "step": 5}, }, ), ), FunctionModel( code: 'level', type: functionTypesMap['Enum'], values: ValueModel.fromJson({ // "range": ["low", "middle", "high", "auto"] })), FunctionModel( code: 'child_lock', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), ], DeviceType.Gateway: [ FunctionModel( code: 'switch_alarm_sound', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'master_state', type: functionTypesMap['Enum'], values: ValueModel.fromJson({ "range": ["normal", "alarm"] })), FunctionModel( code: 'factory_reset', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'alarm_active', type: functionTypesMap['String'], values: ValueModel.fromJson({"maxlen": 255})), ], DeviceType.CeilingSensor: [ FunctionModel( code: 'sensitivity', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "", "min": 1, "max": 10, "scale": 0, "step": 1})), ], DeviceType.DoorLock: [ FunctionModel( code: 'remote_no_pd_setkey', type: functionTypesMap['Raw'], values: ValueModel.fromJson({})), FunctionModel( code: 'remote_no_dp_key', type: functionTypesMap['Raw'], values: ValueModel.fromJson({})), FunctionModel( code: 'normal_open_switch', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), ], DeviceType.WallSensor: [ FunctionModel( code: 'far_detection', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "cm", "min": 75, "max": 600, "scale": 0, "step": 75})), FunctionModel( code: 'presence_time', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "Min", "min": 0, "max": 65535, "scale": 0, "step": 1})), FunctionModel( code: 'motion_sensitivity_value', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "", "min": 1, "max": 5, "scale": 0, "step": 1})), FunctionModel( code: 'motionless_sensitivity', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "", "min": 1, "max": 5, "scale": 0, "step": 1})), FunctionModel( code: 'indicator', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), ], DeviceType.ThreeGang: [ FunctionModel( code: 'switch_1', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'switch_2', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'switch_3', type: functionTypesMap['Boolean'], values: ValueModel.fromJson({})), FunctionModel( code: 'countdown_1', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "s", "min": 0, "max": 43200, "scale": 0, "step": 1})), FunctionModel( code: 'countdown_2', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "s", "min": 0, "max": 43200, "scale": 0, "step": 1})), FunctionModel( code: 'countdown_3', type: functionTypesMap['Integer'], values: ValueModel.fromJson( {"unit": "s", "min": 0, "max": 43200, "scale": 0, "step": 1})), ], }; enum TempModes { hot, cold, wind } enum FanSpeeds { auto, low, middle, high } final Map fanSpeedsIconMap = { FanSpeeds.auto: Assets.iconsFan0, FanSpeeds.low: Assets.iconsFan1, FanSpeeds.middle: Assets.iconsFan2, FanSpeeds.high: Assets.iconsFan3, }; final Map tempModesIconMap = { TempModes.hot: Assets.iconsSunnyMode, TempModes.cold: Assets.iconsColdMode, TempModes.wind: Assets.iconsWindyMode, }; final Map fanSpeedsMap = { 'auto': FanSpeeds.auto, 'low': FanSpeeds.low, 'middle': FanSpeeds.middle, 'high': FanSpeeds.high, }; final Map tempModesMap = { 'hot': TempModes.hot, 'cold': TempModes.cold, 'wind': TempModes.wind, }; final Map reversedFanSpeedsMap = fanSpeedsMap.map((key, value) => MapEntry(value, key)); final Map reversedTempModesMap = tempModesMap.map((key, value) => MapEntry(value, key)); String getNextFanSpeedKey(FanSpeeds currentFanSpeed) { const List speeds = FanSpeeds.values; final int currentIndex = speeds.indexOf(currentFanSpeed); // Return null if currentFanSpeed is the last value if (currentIndex == speeds.length - 1) { return reversedFanSpeedsMap[FanSpeeds.auto]!; } final FanSpeeds nextSpeed = speeds[currentIndex + 1]; return reversedFanSpeedsMap[nextSpeed]!; } K? getNextItem(Map map, V value) { // Iterate over the map entries for (var entry in map.entries) { // If the current value matches the provided value if (entry.value == value) { // Get the index of the current entry final index = map.keys.toList().indexOf(entry.key); // If the index is not the last item, return the next item if (index < map.length - 1) { return map.keys.elementAt(index + 1); } // If it's the last item, return null return map.keys.elementAt(0); } } // If the value is not found, return null return null; }