Skip to content

Commit

Permalink
Merge pull request #721 from CyBear-Jinni/Changing_grpc
Browse files Browse the repository at this point in the history
Made vendor login generic
  • Loading branch information
guyluz11 authored Jan 10, 2024
2 parents 610f052 + 8bbb82f commit b7c2920
Show file tree
Hide file tree
Showing 25 changed files with 284 additions and 519 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
flutter_channel: 'stable' # or: 'dev' or 'beta'
flutter_version: '3.13.6'
flutter_version: '3.16.5'

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions lib/domain/connections_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ abstract interface class ConnectionsService {
Future activateScene(String id);

Future addScene(SceneCbjEntity scene);

Future<void> loginVendor(VendorLoginEntity value);

Future<List<VendorEntityInformation>> getVendors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ class _AppConnectionService implements ConnectionsService {

@override
Future addScene(SceneCbjEntity scene) => IcSynchronizer().addScene(scene);

@override
Future loginVendor(VendorLoginEntity value) async =>
IcSynchronizer().loginVendor(value);

@override
Future<List<VendorEntityInformation>> getVendors() async =>
IcSynchronizer().getVendors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ class _DemoConnectionService implements ConnectionsService {

@override
Future activateScene(String id) async {}

@override
Future<void> loginVendor(VendorLoginEntity value) async {}

@override
Future<List<VendorEntityInformation>> getVendors() async => [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ class _NoneConnectionService implements ConnectionsService {

@override
Future activateScene(String id) async {}

@override
Future<void> loginVendor(VendorLoginEntity value) async {}

@override
Future<List<VendorEntityInformation>> getVendors() async => [];
}
4 changes: 4 additions & 0 deletions lib/presentation/atoms/switch_atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class _SwitchAtomState extends State<SwitchAtom> {
case SwitchVariant.switchVariant:
activeIcon = MdiIcons.lightSwitch;
inactiveIcon = MdiIcons.lightSwitch;
case SwitchVariant.ac:
activeIcon = MdiIcons.airConditioner;
inactiveIcon = MdiIcons.airConditioner;
}

return SizedBox(
Expand Down Expand Up @@ -115,5 +118,6 @@ enum SwitchVariant {
boiler,
smartPlug,
switchVariant,
ac,
;
}
40 changes: 6 additions & 34 deletions lib/presentation/core/entities_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,12 @@ class EntitiesUtils {
return FontAwesomeIcons.alignJustify;
case EntityTypes.boiler:
return FontAwesomeIcons.temperatureThreeQuarters;
case EntityTypes.browserApp:
// TODO: Handle this case.
break;
case EntityTypes.button:
return Icons.smart_button;
case EntityTypes.computerApp:
return Icons.computer;
case EntityTypes.emptyEntity:
// TODO: Handle this case.
break;
case EntityTypes.hub:
// TODO: Handle this case.
break;
case EntityTypes.light:
case EntityTypes.dimmableLight:
case EntityTypes.rgbLights:
case EntityTypes.rgbcctLights:
case EntityTypes.rgbwLights:
case EntityTypes.cctLight:
return FontAwesomeIcons.lightbulb;
case EntityTypes.phoneApp:
return Icons.phone;
case EntityTypes.pingEntity:
// TODO: Handle this case.
break;
case EntityTypes.playerEntity:
// TODO: Handle this case.
break;
case EntityTypes.printer:
case EntityTypes.scanner:
case EntityTypes.printerWithScanner:
return Icons.print;
case EntityTypes.routerEntity:
return Icons.router;
case EntityTypes.securityCamera:
return Icons.camera;
case EntityTypes.smartComputer:
Expand All @@ -52,14 +24,14 @@ class EntitiesUtils {
return MdiIcons.powerSocketAu;
case EntityTypes.smartTV:
return Icons.tv;
case EntityTypes.smartTypeNotSupported:
// TODO: Handle this case.
break;
case EntityTypes.switch_:
return MdiIcons.lightSwitch;
case EntityTypes.voiceAssistant:
return MdiIcons.voicemail;
case EntityTypes.ac:
return MdiIcons.airConditioner;
case EntityTypes.emptyEntity:
case EntityTypes.pingEntity:
case EntityTypes.smartTypeNotSupported:
return Icons.question_mark;
}
return Icons.question_mark;
}
}
4 changes: 1 addition & 3 deletions lib/presentation/core/routes/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ class AppRouter extends $AppRouter {
AutoRoute(page: AddActionRoute.page),
AutoRoute(page: ChooseAutomationTypeToAddRoute.page),
AutoRoute(page: ChooseDeviceVendorToAddRoute.page),
AutoRoute(page: AddLifxVendorRoute.page),
AutoRoute(page: AddEspHomeVendorRoute.page),
AutoRoute(page: AddEwelinkVendorRoute.page),
AutoRoute(page: ConnectToHomeWifiRoute.page),
AutoRoute(page: OpenAccessPointRoute.page),
AutoRoute(page: ScanForNewCBJCompsRoute.page),
AutoRoute(page: ConfigureNewCbjCompRoute.page),
AutoRoute(page: ComputerConnectionCheckRoute.page),
AutoRoute(page: EntitiesInNetworkRoute.page),
AutoRoute(page: EntitiesInAreaRoute.page),
AutoRoute(page: LoginVendorRoute.page),

// Pages from packages
AutoRoute(page: SmartCameraContainerRoute.page),
Expand Down
11 changes: 7 additions & 4 deletions lib/presentation/molecules/device_by_type_molecule.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:cbj_integrations_controller/integrations_controller.dart';
import 'package:cybearjinni/presentation/atoms/atoms.dart';
import 'package:cybearjinni/presentation/molecules/molecules.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -36,9 +35,13 @@ class DeviceByTypeMolecule extends StatelessWidget {
return DimmableLightMolecule(entity as GenericDimmableLightDE);
case EntityTypes.securityCamera:
return SecurityCameraMolecule(entity as GenericSecurityCameraDE);

default:
return TextAtom('Entity type is unsupported ${type?.name ?? 'null'}');
case EntityTypes.ac:
return AcMolecule(entity as GenericAcDE);
case EntityTypes.smartTypeNotSupported:
case EntityTypes.emptyEntity:
case EntityTypes.pingEntity:
case null:
return const SizedBox();
}
}
}
87 changes: 87 additions & 0 deletions lib/presentation/molecules/devices/ac_molecule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'dart:collection';

import 'package:another_flushbar/flushbar_helper.dart';
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/molecules/molecules.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';

class AcMolecule extends StatefulWidget {
const AcMolecule(this.entity);

final GenericAcDE entity;

@override
State<AcMolecule> createState() => _AcMoleculeState();
}

class _AcMoleculeState extends State<AcMolecule> {
Future<void> _turnOnAllAcs() async {
FlushbarHelper.createLoading(
message: 'Turning_On_ac'.tr(),
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

setEntityState(EntityActions.on);
// IDeviceRepository.instance.moveUpStateDevices(devicesId: blindsIdToTurnUp);
}

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()]),
),
],
);

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

Future<void> _turnOffAllAcs() async {
FlushbarHelper.createLoading(
message: 'Turning_Off_ac'.tr(),
linearProgressIndicator: const LinearProgressIndicator(),
).show(context);

setEntityState(EntityActions.off);
}

void _onChange(bool value) {
if (value) {
_turnOnAllAcs();
} else {
_turnOffAllAcs();
}
}

@override
Widget build(BuildContext context) {
return DeviceNameRow(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.ac,
onToggle: _onChange,
action: widget.entity.acSwitchState.action!,
state: widget.entity.entityStateGRPC.state,
),
);
}
}
3 changes: 2 additions & 1 deletion lib/presentation/molecules/molecules.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export 'bottom_navigation_bar_molecule.dart';
export 'device_by_type_molecule.dart';
export 'device_name_row.dart';
export 'devices/ac_molecule.dart';
export 'devices/blind_molecule.dart';
export 'devices/blinds_card_molecule.dart';
export 'devices/boiler_molecule.dart';
Expand All @@ -17,5 +18,5 @@ export 'devices/switch_molecule.dart';
export 'list_tile_molecule.dart';
export 'list_view_molecule.dart';
export 'loading_page_molecule.dart';
export 'top_bar_molecule.dart';
export 'scenes_grid.dart';
export 'top_bar_molecule.dart';
4 changes: 0 additions & 4 deletions lib/presentation/organisms/devices_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ class DevicesListView extends StatelessWidget {

HashSet<EntityTypes> getReleatedTypes(EntityTypes type) {
if (type == EntityTypes.light ||
type == EntityTypes.rgbLights ||
type == EntityTypes.rgbwLights ||
type == EntityTypes.cctLight ||
type == EntityTypes.dimmableLight) {
return HashSet.from({
EntityTypes.light,
EntityTypes.rgbLights,
EntityTypes.rgbwLights,
EntityTypes.cctLight,
EntityTypes.dimmableLight,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,25 @@ import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

class VendorWidget extends StatelessWidget {
const VendorWidget(this.vendor);
const VendorWidget(this.vendorInformation);

final VendorData vendor;
final VendorEntityInformation vendorInformation;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
final String vendorName = vendor.name
.getOrCrash()
.toLowerCase()
.replaceAll(' ', '')
.replaceAll('_', '');

if (vendorName == VendorsAndServices.lifx.name.toLowerCase()) {
context.router.push(AddLifxVendorRoute(vendor: vendor));
} else if (vendorName ==
VendorsAndServices.espHome.name.toLowerCase()) {
context.router.push(AddEspHomeVendorRoute(vendor: vendor));
} else if (vendorName ==
VendorsAndServices.sonoffEweLink.name.toLowerCase()) {
context.router.push(AddEwelinkVendorRoute(vendor: vendor));
} else if (vendorName ==
VendorsAndServices.philipsHue.name.toLowerCase()) {
if (vendorInformation.loginType == VendorLoginTypes.notNeeded) {
SnackBarService().show(
context,
'Please press the button on top of the Philips Hue Hub for and wait 20s',
);
} else {
SnackBarService().show(
context,
'${vendor.name.getOrCrash()} devices will be add automatically'
'${vendorInformation.displayName} devices will be add automatically'
' for you',
);
return;
}

context.router
.push(LoginVendorRoute(vendorInformation: vendorInformation));
},
child: Container(
height: 100,
Expand All @@ -54,10 +38,7 @@ class VendorWidget extends StatelessWidget {
height: 180,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
vendor.image ??
'http://www.clker.com/cliparts/f/Z/G/4/h/Q/no-image-available-th.png',
),
image: NetworkImage(vendorInformation.imageUrl),
fit: BoxFit.fitHeight,
),
),
Expand All @@ -66,7 +47,7 @@ class VendorWidget extends StatelessWidget {
width: 10,
),
TextAtom(
vendor.name.getOrCrash(),
vendorInformation.displayName,
style: const TextStyle(
color: Colors.black,
fontSize: 22,
Expand Down
Loading

0 comments on commit b7c2920

Please sign in to comment.