Skip to content

Commit

Permalink
Added preset support
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 25, 2024
1 parent 6c94c3b commit a784195
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 195 deletions.
20 changes: 3 additions & 17 deletions lib/presentation/molecules/devices/ac_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@ class _AcMoleculeState extends State<AcMolecule> {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> entitiesId =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: entitiesId,
property: EntityProperties.acSwitchState,
actionType: action,
),
Expand Down
21 changes: 3 additions & 18 deletions lib/presentation/molecules/devices/blind_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,12 @@ class _BlindMoleculeState extends State<BlindMolecule> {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}

final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: EntityProperties.blindsSwitchState,
actionType: action,
),
Expand Down
20 changes: 3 additions & 17 deletions lib/presentation/molecules/devices/boiler_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@ class _BoilerMoleculeState extends State<BoilerMolecule> {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: EntityProperties.boilerSwitchState,
actionType: action,
),
Expand Down
20 changes: 3 additions & 17 deletions lib/presentation/molecules/devices/dimmable_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,12 @@ class _DimmableLightMoleculeState extends State<DimmableLightMolecule> {
EntityActions action, {
HashMap<ActionValues, dynamic>? value,
}) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
Expand Down
19 changes: 3 additions & 16 deletions lib/presentation/molecules/devices/light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@ class LightMolecule extends StatelessWidget {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashSet<String> uniqueIdByVendor =
HashSet.from([entity.deviceCbjUniqueId.getOrCrash()]);

final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()..addAll([entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
Expand Down
44 changes: 8 additions & 36 deletions lib/presentation/molecules/devices/rgb_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,12 @@ class _RgbwLightMoleculeState extends State<RgbwLightMolecule> {
EntityActions action, {
HashMap<ActionValues, dynamic>? value,
}) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: entityProperties,
actionType: action,
value: value,
Expand Down Expand Up @@ -212,26 +198,12 @@ class _LightColorMods extends State<LightColorMods> {
EntityActions action, {
HashMap<ActionValues, dynamic>? value,
}) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: entityProperties,
actionType: action,
value: value,
Expand All @@ -246,7 +218,7 @@ class _LightColorMods extends State<LightColorMods> {
setEntityState(
EntityProperties.lightColorTemperature,
EntityActions.changeTemperature,
value: HashMap.from({ActionValues.temperature: newColorTemperature}),
value: HashMap.from({ActionValues.colorTemperature: newColorTemperature}),
);
}

Expand All @@ -262,7 +234,7 @@ class _LightColorMods extends State<LightColorMods> {
ActionValues.alpha: newHsvColor.alpha,
ActionValues.hue: newHsvColor.hue,
ActionValues.saturation: newHsvColor.saturation,
ActionValues.value: newHsvColor.value,
ActionValues.colorValue: newHsvColor.value,
}),
);
}
Expand Down
21 changes: 4 additions & 17 deletions lib/presentation/molecules/devices/smart_plug_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,12 @@ class _SmartPlugsMoleculeState extends State<SmartPlugsMolecule> {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
Expand Down
21 changes: 4 additions & 17 deletions lib/presentation/molecules/devices/smart_tv_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,12 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
EntityActions action, {
HashMap<ActionValues, dynamic>? value,
}) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
Expand Down
21 changes: 4 additions & 17 deletions lib/presentation/molecules/devices/switch_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,12 @@ class _SwitchMoleculeState extends State<SwitchMolecule> {
}

void setEntityState(EntityActions action) {
final VendorsAndServices? vendor =
widget.entity.cbjDeviceVendor.vendorsAndServices;
if (vendor == null) {
return;
}
final HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor =
HashMap();
uniqueIdByVendor.addEntries(
[
MapEntry(
vendor,
HashSet<String>()
..addAll([widget.entity.deviceCbjUniqueId.getOrCrash()]),
),
],
);
final HashSet<String> uniqueIdByVendor =
HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]);

ConnectionsService.instance.setEntityState(
RequestActionObject(
uniqueIdByVendor: uniqueIdByVendor,
entityIds: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
Expand Down
32 changes: 15 additions & 17 deletions lib/presentation/pages/add_new_area_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
AreaBackground background = AreaBackground(
'https://live.staticflickr.com/5220/5486044345_f67abff3e9_h.jpg',
);
AreaTypes areaTypes = AreaTypes(const {});
AreaPurposes areaTypes = AreaPurposes(const {});
AreaEntitiesId areaDevicesId = AreaEntitiesId(const {});
AreaScenesId areaScenesId = AreaScenesId(const {});
AreaRoutinesId areaRoutinesId = AreaRoutinesId(const {});
Expand Down Expand Up @@ -63,15 +63,15 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
Future _createArea() async {
final AreaEntity areaEntity = AreaEntity(
uniqueId: AreaUniqueId.fromUniqueString(areaUniqueId.getOrCrash()),
cbjEntityName: AreaDefaultName(cbjEntityName.getOrCrash()),
background: AreaBackground(background.getOrCrash()),
areaTypes: AreaTypes(areaTypes.getOrCrash()),
entitiesId: AreaEntitiesId(areaDevicesId.getOrCrash()),
areaScenesId: AreaScenesId(areaScenesId.getOrCrash()),
areaRoutinesId: AreaRoutinesId(areaRoutinesId.getOrCrash()),
areaBindingsId: AreaBindingsId(areaBindingsId.getOrCrash()),
areaMostUsedBy: AreaMostUsedBy(areaMostUsedBy.getOrCrash()),
areaPermissions: AreaPermissions(areaPermissions.getOrCrash()),
cbjEntityName: cbjEntityName,
background: background,
purposes: areaTypes,
entitiesId: areaDevicesId,
scenesId: areaScenesId,
routinesId: areaRoutinesId,
bindingsId: areaBindingsId,
areaMostUsedBy: areaMostUsedBy,
areaPermissions: areaPermissions,
);

ConnectionsService.instance.setNewArea(areaEntity);
Expand All @@ -83,9 +83,9 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
});
}

Future _areaTypesChanged(Set<String> value) async {
Future _areaTypesChanged(Set<AreaPurposesTypes> value) async {
setState(() {
areaTypes = AreaTypes(value);
areaTypes = AreaPurposes(value);
});
}

Expand Down Expand Up @@ -148,15 +148,13 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
}

return MultiSelectItem(
areaPurposeType.name,
areaPurposeType,
areaNameEdited,
);
}).toList(),
listType: MultiSelectListType.CHIP,
onConfirm: (List<String> values) {
_areaTypesChanged(
values.map((e) => e).toSet(),
);
onConfirm: (List<AreaPurposesTypes> values) {
_areaTypesChanged(values.toSet());
},
),
],
Expand Down
Loading

0 comments on commit a784195

Please sign in to comment.