From 9b40e057def1af05802df9e24118aa59397e65df Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 27 Jan 2024 20:37:54 +0200 Subject: [PATCH] Refined color light bulb --- lib/presentation/core/entities_utils.dart | 2 +- .../molecules/device_by_type_molecule.dart | 2 +- .../devices/dimmable_light_molecule.dart | 2 +- .../molecules/devices/printer_molecule.dart | 5 +- .../molecules/devices/rgb_light_molecule.dart | 57 ++++++++----------- .../widgets/vendors_list.dart | 4 +- .../configure_new_cbj_comp_widget.dart | 3 +- .../cbj_comp_card_with_devices_controll.dart | 2 +- .../pages/add_scene/add_scene_page.dart | 2 +- .../pages/entities_in_area_page.dart | 3 +- .../pages/home_page/home_page.dart | 5 +- 11 files changed, 38 insertions(+), 49 deletions(-) diff --git a/lib/presentation/core/entities_utils.dart b/lib/presentation/core/entities_utils.dart index 912d3b0a..e3ef9a37 100644 --- a/lib/presentation/core/entities_utils.dart +++ b/lib/presentation/core/entities_utils.dart @@ -30,7 +30,7 @@ class EntitiesUtils { return MdiIcons.airConditioner; case EntityTypes.emptyEntity: case EntityTypes.pingEntity: - case EntityTypes.smartTypeNotSupported: + case EntityTypes.undefined: return Icons.question_mark; } } diff --git a/lib/presentation/molecules/device_by_type_molecule.dart b/lib/presentation/molecules/device_by_type_molecule.dart index de7fec35..17f6d75a 100644 --- a/lib/presentation/molecules/device_by_type_molecule.dart +++ b/lib/presentation/molecules/device_by_type_molecule.dart @@ -37,7 +37,7 @@ class DeviceByTypeMolecule extends StatelessWidget { return SecurityCameraMolecule(entity as GenericSecurityCameraDE); case EntityTypes.ac: return AcMolecule(entity as GenericAcDE); - case EntityTypes.smartTypeNotSupported: + case EntityTypes.undefined: case EntityTypes.emptyEntity: case EntityTypes.pingEntity: case null: diff --git a/lib/presentation/molecules/devices/dimmable_light_molecule.dart b/lib/presentation/molecules/devices/dimmable_light_molecule.dart index e6fd0a22..e1f034f0 100644 --- a/lib/presentation/molecules/devices/dimmable_light_molecule.dart +++ b/lib/presentation/molecules/devices/dimmable_light_molecule.dart @@ -55,7 +55,7 @@ class _DimmableLightMoleculeState extends State { setEntityState( EntityProperties.lightBrightness, - EntityActions.actionNotSupported, + EntityActions.undefined, value: hashValue, ); } diff --git a/lib/presentation/molecules/devices/printer_molecule.dart b/lib/presentation/molecules/devices/printer_molecule.dart index e0e3cfec..de2d9f15 100644 --- a/lib/presentation/molecules/devices/printer_molecule.dart +++ b/lib/presentation/molecules/devices/printer_molecule.dart @@ -24,9 +24,10 @@ class _PrinterMoleculeState extends State { linearProgressIndicator: const LinearProgressIndicator(), ).show(context); - final String printerIp = widget.entity.deviceLastKnownIp.getOrCrash()!; + final String printerAddress = widget.entity.srvTarget.getOrCrash() ?? + widget.entity.deviceLastKnownIp.getOrCrash()!; launchUrl( - Uri.parse('http://$printerIp'), + Uri.parse('http://$printerAddress'), mode: LaunchMode.externalApplication, ); } diff --git a/lib/presentation/molecules/devices/rgb_light_molecule.dart b/lib/presentation/molecules/devices/rgb_light_molecule.dart index 8b331fa1..c8539aa4 100644 --- a/lib/presentation/molecules/devices/rgb_light_molecule.dart +++ b/lib/presentation/molecules/devices/rgb_light_molecule.dart @@ -84,7 +84,7 @@ class _RgbwLightMoleculeState extends State { }); setEntityState( EntityProperties.lightBrightness, - EntityActions.actionNotSupported, + EntityActions.undefined, value: HashMap.from({ActionValues.brightness: value.round()}), ); } @@ -160,13 +160,18 @@ class _LightColorMods extends State { late int colorTemperature; late HSVColor hsvColor; late double brightness; + late ColorMode colorMode; + late Widget colorModeWidget; @override void initState() { super.initState(); + colorMode = widget.entity.colorMode.mode; hsvColor = widget.hsvColor ?? HSVColor.fromColor(Colors.white); colorTemperature = widget.colorTemperature; brightness = widget.brightness; + colorModeWidget = getColorModeWidget(colorMode); + _initialized(); } @@ -239,9 +244,6 @@ class _LightColorMods extends State { ); } - late Widget colorModeWidget; - int colorModFocus = 0; - Widget getWhiteModeWidget() { return Container( height: 100, @@ -281,21 +283,27 @@ class _LightColorMods extends State { ); } - Future _showWhiteMode() async { - setState(() { - colorModFocus = 0; - colorModeWidget = getWhiteModeWidget(); - }); + Widget getColorModeWidget(ColorMode colorMode) { + switch (colorMode) { + case ColorMode.undefined: + return const SizedBox(); + case ColorMode.rgb: + return getHsvColorModeWidget(); + case ColorMode.white: + return getWhiteModeWidget(); + } } - Future _showColorMode() async { + void setColorModeState(ColorMode colorMode) { + final Widget colorModeWidget = getColorModeWidget(colorMode); setState(() { - colorModFocus = 1; - colorModeWidget = getHsvColorModeWidget(); + this.colorMode = colorMode; + this.colorModeWidget = colorModeWidget; }); } - Widget lightModBarFocus() { + @override + Widget build(BuildContext context) { final ThemeData themeData = Theme.of(context); final ColorScheme colorScheme = themeData.colorScheme; @@ -310,44 +318,29 @@ class _LightColorMods extends State { child: TextAtom( 'White', style: TextStyle( - color: (colorModFocus == 0) + color: (colorMode == ColorMode.white) ? colorScheme.primary : colorScheme.onBackground, fontSize: 18, ), ), - onPressed: () { - _showWhiteMode(); - }, + onPressed: () => setColorModeState(ColorMode.white), ), OutlinedButton( child: TextAtom( 'Color', style: TextStyle( - color: (colorModFocus == 1) + color: (colorMode == ColorMode.rgb) ? colorScheme.primary : colorScheme.onBackground, fontSize: 18, ), ), - onPressed: () { - _showColorMode(); - }, + onPressed: () => setColorModeState(ColorMode.rgb), ), ], ), ], ); } - - @override - Widget build(BuildContext context) { - if (colorModFocus == 0) { - colorModeWidget = getWhiteModeWidget(); - } else { - colorModeWidget = getHsvColorModeWidget(); - } - - return lightModBarFocus(); - } } diff --git a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart index ffcc0553..f59c6113 100644 --- a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart +++ b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart @@ -22,9 +22,7 @@ class _VendorsListState extends State { final List temp = await ConnectionsService.instance.getVendors(); temp.removeWhere( - (element) => - element.vendorsAndServices == - VendorsAndServices.vendorsAndServicesNotSupported, + (element) => element.vendorsAndServices == VendorsAndServices.undefined, ); setState(() { vendorsList = temp; diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index 982fb7d2..d22b8324 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -149,8 +149,7 @@ class _ConfigureNewCbjCompWidgetsState final List widgetList = []; for (final GenericLightDE device in devicesList) { - if (device.entityTypes.getOrCrash() != - EntityTypes.smartTypeNotSupported.toString()) { + if (device.entityTypes.getOrCrash() != EntityTypes.undefined.toString()) { final TextEditingController textEditingControllerTemp = TextEditingController( text: device.cbjEntityName.value.getOrElse(() => ''), diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart index a51554c5..4af47166 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart @@ -21,7 +21,7 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { for (final GenericLightDE deviceEntity in deviceEntityList.asList()) { // if (deviceEntity.entityTypes.getOrCrash() != - EntityTypes.smartTypeNotSupported.toString()) { + EntityTypes.undefined.toString()) { typesList.add( ColoredBox( color: Colors.yellowAccent.withOpacity(0.3), diff --git a/lib/presentation/pages/add_scene/add_scene_page.dart b/lib/presentation/pages/add_scene/add_scene_page.dart index db49ffe0..58301d95 100644 --- a/lib/presentation/pages/add_scene/add_scene_page.dart +++ b/lib/presentation/pages/add_scene/add_scene_page.dart @@ -75,7 +75,7 @@ class _AddScenePageState extends State { compUuid: SceneCbjCompUuid(''), entityStateGRPC: SceneCbjDeviceStateGRPC(EntityStateGRPC.ack.name), actions: actions, - areaPurposeType: AreaPurposesTypes.undefinedType, + areaPurposeType: AreaPurposesTypes.undefined, ); ConnectionsService.instance.addScene(scene); diff --git a/lib/presentation/pages/entities_in_area_page.dart b/lib/presentation/pages/entities_in_area_page.dart index 315fd83b..731936b9 100644 --- a/lib/presentation/pages/entities_in_area_page.dart +++ b/lib/presentation/pages/entities_in_area_page.dart @@ -55,8 +55,7 @@ class _EntitiesInAreaPageState extends State { } bool supportedEntityType(EntityTypes type) { - return !(type == EntityTypes.smartTypeNotSupported || - type == EntityTypes.emptyEntity); + return !(type == EntityTypes.undefined || type == EntityTypes.emptyEntity); } @override diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index 11419604..72d130e4 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -104,7 +104,7 @@ class _HomePageState extends State { await ConnectionsService.instance.getEntities; entitiesTemp.removeWhere( (key, value) => - value.entityTypes.type == EntityTypes.smartTypeNotSupported || + value.entityTypes.type == EntityTypes.undefined || value.entityTypes.type == EntityTypes.emptyEntity, ); setState(() { @@ -123,8 +123,7 @@ class _HomePageState extends State { } bool unSupportedEntityType(EntityTypes type) { - return type == EntityTypes.smartTypeNotSupported || - type == EntityTypes.emptyEntity; + return type == EntityTypes.undefined || type == EntityTypes.emptyEntity; } /// Tab num, value will be the default tab to show