Skip to content

Commit

Permalink
Refined color light bulb
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 27, 2024
1 parent a784195 commit 9b40e05
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/presentation/core/entities_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/device_by_type_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _DimmableLightMoleculeState extends State<DimmableLightMolecule> {

setEntityState(
EntityProperties.lightBrightness,
EntityActions.actionNotSupported,
EntityActions.undefined,
value: hashValue,
);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/presentation/molecules/devices/printer_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class _PrinterMoleculeState extends State<PrinterMolecule> {
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,
);
}
Expand Down
57 changes: 25 additions & 32 deletions lib/presentation/molecules/devices/rgb_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _RgbwLightMoleculeState extends State<RgbwLightMolecule> {
});
setEntityState(
EntityProperties.lightBrightness,
EntityActions.actionNotSupported,
EntityActions.undefined,
value: HashMap.from({ActionValues.brightness: value.round()}),
);
}
Expand Down Expand Up @@ -160,13 +160,18 @@ class _LightColorMods extends State<LightColorMods> {
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();
}

Expand Down Expand Up @@ -239,9 +244,6 @@ class _LightColorMods extends State<LightColorMods> {
);
}

late Widget colorModeWidget;
int colorModFocus = 0;

Widget getWhiteModeWidget() {
return Container(
height: 100,
Expand Down Expand Up @@ -281,21 +283,27 @@ class _LightColorMods extends State<LightColorMods> {
);
}

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;

Expand All @@ -310,44 +318,29 @@ class _LightColorMods extends State<LightColorMods> {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class _VendorsListState extends State<VendorsList> {
final List<VendorEntityInformation> temp =
await ConnectionsService.instance.getVendors();
temp.removeWhere(
(element) =>
element.vendorsAndServices ==
VendorsAndServices.vendorsAndServicesNotSupported,
(element) => element.vendorsAndServices == VendorsAndServices.undefined,
);
setState(() {
vendorsList = temp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ class _ConfigureNewCbjCompWidgetsState
final List<Widget> 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(() => ''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/pages/add_scene/add_scene_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _AddScenePageState extends State<AddScenePage> {
compUuid: SceneCbjCompUuid(''),
entityStateGRPC: SceneCbjDeviceStateGRPC(EntityStateGRPC.ack.name),
actions: actions,
areaPurposeType: AreaPurposesTypes.undefinedType,
areaPurposeType: AreaPurposesTypes.undefined,
);

ConnectionsService.instance.addScene(scene);
Expand Down
3 changes: 1 addition & 2 deletions lib/presentation/pages/entities_in_area_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class _EntitiesInAreaPageState extends State<EntitiesInAreaPage> {
}

bool supportedEntityType(EntityTypes type) {
return !(type == EntityTypes.smartTypeNotSupported ||
type == EntityTypes.emptyEntity);
return !(type == EntityTypes.undefined || type == EntityTypes.emptyEntity);
}

@override
Expand Down
5 changes: 2 additions & 3 deletions lib/presentation/pages/home_page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class _HomePageState extends State<HomePage> {
await ConnectionsService.instance.getEntities;
entitiesTemp.removeWhere(
(key, value) =>
value.entityTypes.type == EntityTypes.smartTypeNotSupported ||
value.entityTypes.type == EntityTypes.undefined ||
value.entityTypes.type == EntityTypes.emptyEntity,
);
setState(() {
Expand All @@ -123,8 +123,7 @@ class _HomePageState extends State<HomePage> {
}

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
Expand Down

0 comments on commit 9b40e05

Please sign in to comment.