Skip to content

Commit

Permalink
Added scene support
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 5, 2024
1 parent a7c785b commit ae80a13
Show file tree
Hide file tree
Showing 35 changed files with 1,124 additions and 1,236 deletions.
13 changes: 7 additions & 6 deletions lib/domain/connections_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ abstract interface class ConnectionsService {

Future searchDevices();

void setEntityState({
required HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor,
required EntityProperties property,
required EntityActions actionType,
HashMap<ActionValues, dynamic>? value,
});
void setEntityState(ActionObject action);

Future setEtitiesToArea(String areaId, HashSet<String> entities);

Expand All @@ -72,4 +67,10 @@ abstract interface class ConnectionsService {
Future dispose();

Future setNewArea(AreaEntity area);

Future<HashMap<String, SceneCbjEntity>> getScenes();

Future activateScene(String id);

Future addScene(SceneCbjEntity scene);
}
1 change: 1 addition & 0 deletions lib/domain/device/i_device_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:rxdart/rxdart.dart';

part 'package:cybearjinni/infrastructure/device_repository.dart';

@Deprecated('Old architecture. Replaced by EntitiesService')
abstract interface class IDeviceRepository {
static IDeviceRepository? _instance;

Expand Down
3 changes: 3 additions & 0 deletions lib/domain/i_hub_connection_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import 'package:wifi_iot/wifi_iot.dart';

part 'package:cybearjinni/infrastructure/hub_client/hub_connection_repository.dart';

@Deprecated(
'Old architecture. Replaced with ConnectionsService. Delete after Re adding Hub comunication',
)
abstract class IHubConnectionRepository {
static IHubConnectionRepository? _instance;

Expand Down
24 changes: 12 additions & 12 deletions lib/infrastructure/connection_service/app_connection_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@ class _AppConnectionService implements ConnectionsService {
IcSynchronizer().areasChangesStream.stream;

@override
void setEntityState({
required HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor,
required EntityProperties property,
required EntityActions actionType,
HashMap<ActionValues, dynamic>? value,
}) =>
IcSynchronizer().setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
action: actionType,
property: property,
value: value,
);
void setEntityState(ActionObject action) =>
IcSynchronizer().setEntitiesState(action);

@override
Future dispose() async => searchDevicesInstance.dispose();
Expand All @@ -53,4 +43,14 @@ class _AppConnectionService implements ConnectionsService {
@override
Future setEtitiesToArea(String areaId, HashSet<String> entities) =>
IcSynchronizer().setEtitiesToArea(areaId, entities);

@override
Future<HashMap<String, SceneCbjEntity>> getScenes() async =>
IcSynchronizer().getScenes();

@override
Future activateScene(String id) => IcSynchronizer().activateScene(id);

@override
Future addScene(SceneCbjEntity scene) => IcSynchronizer().addScene(scene);
}
16 changes: 10 additions & 6 deletions lib/infrastructure/connection_service/demo_connection_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ class _DemoConnectionService implements ConnectionsService {
Future searchDevices() async {}

@override
void setEntityState({
required HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor,
required EntityProperties property,
required EntityActions actionType,
HashMap<ActionValues, dynamic>? value,
}) {}
void setEntityState(ActionObject action) {}

@override
Stream<MapEntry<String, DeviceEntityBase>> watchEntities() {
Expand All @@ -48,4 +43,13 @@ class _DemoConnectionService implements ConnectionsService {

@override
Future setEtitiesToArea(String areaId, HashSet entities) async {}

@override
Future addScene(SceneCbjEntity scene) async {}

@override
Future<HashMap<String, SceneCbjEntity>> getScenes() async => HashMap();

@override
Future activateScene(String id) async {}
}
16 changes: 10 additions & 6 deletions lib/infrastructure/connection_service/none_connection_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ class _NoneConnectionService implements ConnectionsService {
Future searchDevices() async {}

@override
void setEntityState({
required HashMap<VendorsAndServices, HashSet<String>> uniqueIdByVendor,
required EntityProperties property,
required EntityActions actionType,
HashMap<ActionValues, dynamic>? value,
}) {}
void setEntityState(ActionObject action) {}

@override
Stream<MapEntry<String, DeviceEntityBase>> watchEntities() {
Expand All @@ -48,4 +43,13 @@ class _NoneConnectionService implements ConnectionsService {

@override
Future setEtitiesToArea(String areaId, HashSet entities) async {}

@override
Future<HashMap<String, SceneCbjEntity>> getScenes() async => HashMap();

@override
Future addScene(SceneCbjEntity scene) async {}

@override
Future activateScene(String id) async {}
}
3 changes: 3 additions & 0 deletions lib/infrastructure/hub_client/hub_connection_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
part of 'package:cybearjinni/domain/i_hub_connection_repository.dart';

@Deprecated(
'Old architecture. Replaced with ConnectionsService. Delete after Re adding Hub comunication',
)
class _HubConnectionRepository implements IHubConnectionRepository {
_HubConnectionRepository() {
if (currentEnvApp == EnvApp.prod) {
Expand Down
3 changes: 3 additions & 0 deletions lib/infrastructure/hub_client/hub_requests_routing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import 'package:cybearjinni/infrastructure/core/injection.dart';
import 'package:cybearjinni/infrastructure/core/logger.dart';
import 'package:grpc/grpc.dart';

@Deprecated(
'Old architecture. Replaced with ConnectionsService. Delete after Re adding Hub comunication',
)
class HubRequestRouting {
static StreamSubscription<dynamic>? requestsFromHubSubscription;

Expand Down
1 change: 1 addition & 0 deletions lib/presentation/atoms/atoms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'circular_progress_indicator_atom.dart';
export 'icon_atom.dart';
export 'image_atom.dart';
export 'margined_expanded_atom.dart';
export 'scene_atom.dart';
export 'separator_atom.dart';
export 'switch_atom.dart';
export 'text_atom.dart';
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import 'package:cbj_integrations_controller/integrations_controller.dart';
import 'package:cybearjinni/domain/connections_service.dart';
import 'package:cybearjinni/presentation/atoms/atoms.dart';
import 'package:cybearjinni/presentation/core/snack_bar_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class SceneWidget extends StatefulWidget {
const SceneWidget(this.currentScene);
class SceneAtom extends StatefulWidget {
const SceneAtom(this.currentScene);

final SceneCbjEntity currentScene;

@override
State<SceneWidget> createState() => _SceneWidgetState();
State<SceneAtom> createState() => _SceneAtomState();
}

class _SceneWidgetState extends State<SceneWidget> {
class _SceneAtomState extends State<SceneAtom> {
late SceneCbjEntity sceneCbj;

Future<void> _activateScene() async {
ISceneCbjRepository.instance.activateScenes({sceneCbj});
}
Future<void> _activateScene() async => ConnectionsService.instance
.activateScene(widget.currentScene.uniqueId.getOrCrash());

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.fromLTRB(5, 0, 5, 10),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Color(
int.parse(widget.currentScene.backgroundColor.getOrCrash()),
),
backgroundColor: Colors.blue,
// Color(
// int.parse(widget.currentScene.backgroundColor.getOrCrash()),
// ),
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
Expand Down
8 changes: 5 additions & 3 deletions lib/presentation/molecules/devices/blind_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class _BlindMoleculeState extends State<BlindMolecule> {
);

ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.blindsSwitchState,
actionType: action,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.blindsSwitchState,
actionType: action,
),
);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/presentation/molecules/devices/boiler_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ class _BoilerMoleculeState extends State<BoilerMolecule> {
);

ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.boilerSwitchState,
actionType: action,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.boilerSwitchState,
actionType: action,
),
);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/presentation/molecules/devices/dimmable_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ class _DimmableLightMoleculeState extends State<DimmableLightMolecule> {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
),
);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/presentation/molecules/devices/light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class LightMolecule extends StatelessWidget {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/presentation/molecules/devices/rgb_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ class _RgbwLightMoleculeState extends State<RgbwLightMolecule> {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: entityProperties,
actionType: action,
value: value,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: entityProperties,
actionType: action,
value: value,
),
);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/presentation/molecules/devices/smart_plug_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class _SmartPlugsMoleculeState extends State<SmartPlugsMolecule> {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/presentation/molecules/devices/smart_tv_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: property,
actionType: action,
value: value,
),
);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/presentation/molecules/devices/switch_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class _SwitchMoleculeState extends State<SwitchMolecule> {
],
);
ConnectionsService.instance.setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
ActionObject(
uniqueIdByVendor: uniqueIdByVendor,
property: EntityProperties.lightSwitchState,
actionType: action,
),
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/presentation/molecules/molecules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export 'list_tile_molecule.dart';
export 'list_view_molecule.dart';
export 'loading_page_molecule.dart';
export 'top_bar_molecule.dart';
export 'scenes_grid.dart';
49 changes: 49 additions & 0 deletions lib/presentation/molecules/scenes_grid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:cbj_integrations_controller/integrations_controller.dart';
import 'package:cybearjinni/presentation/atoms/atoms.dart';
import 'package:flutter/material.dart';

class ScenesGrid extends StatefulWidget {
const ScenesGrid({required this.scenes});

final List<SceneCbjEntity> scenes;

@override
State<ScenesGrid> createState() => _ScenesGridState();
}

class _ScenesGridState extends State<ScenesGrid> {
late AreaEntity folderOfScenes;

@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;

int gridCrossAxisCount = 2;
if (screenSize.width > 700) {
gridCrossAxisCount = 4;
}

if (widget.scenes.isEmpty) {
return const Center(
child: TextAtom(
'You can add automations in the plus button',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
);
}
return GridView.builder(
reverse: true,
itemBuilder: (context, index) {
final SceneCbjEntity sceneCbj = widget.scenes[index];
return SceneAtom(sceneCbj);
},
itemCount: widget.scenes.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: gridCrossAxisCount,
),
);
}
}
Loading

0 comments on commit ae80a13

Please sign in to comment.