Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link object in network #6

Closed
babincc opened this issue Apr 7, 2023 · 1 comment
Closed

Link object in network #6

babincc opened this issue Apr 7, 2023 · 1 comment
Labels
enhanced desired feature Functionality that absolutely should be added to the program (program technically works without it) package: flutter_hue This issue has to do with the "flutter_hue" package

Comments

@babincc
Copy link
Owner

babincc commented Apr 7, 2023

Right now, the HueNetwork object just contains a bunch of objects. They aren't really connected in any simple way. Putting them together is clunky and leaves room for error. There needs to be a simple way to connect objects.

Example:

Rather than doing all of this to get a GroupedLight from a Room:

// Figure out which group is the one you want
Relative myRelative = myRoom
	.services
	.firstWhere((service) => 
		service.type == ResourceType.groupedLight);

// Get the group who's ID was just found
GroupedLight myGroupedLight = myHueNetwork.groupedLights.firstWhere(
  (groupedLight) => groupedLight.id == myRelative.id,
);

It should look something more like this:

GroupedLight myGroupedLight = myRoom
        .groupedLights
        .first;
@babincc babincc added enhanced desired feature Functionality that absolutely should be added to the program (program technically works without it) package: flutter_hue This issue has to do with the "flutter_hue" package labels Apr 7, 2023
@babincc
Copy link
Owner Author

babincc commented Apr 19, 2023

Added in update 1.2.0

Now, instead of

// Figure out which group is the one you want
// Get network from example 3
Relative myRelative = myHueNetwork
    .rooms
    .first
    .services
    .firstWhere((service) => 
        service.type == ResourceType.groupedLight);

// Get the group whose ID was just found
GroupedLight myGroupedLight = myHueNetwork.groupedLights.firstWhere(
    (groupedLight) => groupedLight.id == myRelative.id,
);

// Toggle the on/off state
myGroupedLight.on.isOn = !myGroupedLight.on.isOn;

// PUT the new state
myBridge.put(myGroupedLight);

you can instead do

// Get the grouped light from the room
GroupedLight myGroupedLight = myHueNetwork!.rooms.first.servicesAsResources
        .firstWhere((resource) => resource is GroupedLight) as GroupedLight;

// Toggle the on/off state
myGroupedLight.on.isOn = !myGroupedLight.on.isOn;

// PUT the new state
myBridge!.put(myGroupedLight);

@babincc babincc closed this as completed Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhanced desired feature Functionality that absolutely should be added to the program (program technically works without it) package: flutter_hue This issue has to do with the "flutter_hue" package
Projects
None yet
Development

No branches or pull requests

1 participant