hue_dart 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

hue_dart #

A library for creating Philips Hue apps in Flutter and/or AngularDart.

This library aims to make it easier to handle with the Philips Hue bridge.

Using #

Discovery #

Import the library and search for bridges.

import 'package:http/http.dart';
import 'package:hue_dart/hue_dart.dart';

final client = Client();
final discovery = BridgeDiscovery(client);

List<DiscoveryResult> discoverResults = await discovery.automatic();
final discoveryResult = discoverResults.first;

final bridge = Bridge(client, discoveryResult.ipAddress);

For web, use the BrowserClient.

import 'package:http/browser_client.dart';
import 'package:hue_dart/hue_dart.dart';

final client = BrowserClient();
final discovery = BridgeDiscovery(client);

List<DiscoveryResult> discoverResults = await discovery.automatic();
final discoveryResult = discoverResults.first;

final bridge = Bridge(client, discoveryResult.ipAddress);

Searching for a bridge by entering an IP address is also supported.

import package:hue_dart/hue.dart;

final client = Client();
final discovery = BridgeDiscovery(client);

DiscoveryResult discoverResult = await discovery.manual('192.168.1.2');

final bridge = Bridge(client, discoveryResult.ipAddress);

Create a new user #

To create a user press the push link button before calling the createUser method

final bridge = Bridge(client, discoveryResult.ipAddress);
final whiteListItem = bridge.createUser('hue_dart');
bridge.username = whiteListItem.username;

Lights #

To get the current lights on the bridge, create a Bridge, set a username and

final lights = bridge.lights();

Changing a light's color while respecting its current color mode is done by using the Light#changeColor method.

final light = lights.first.changeColor(red: 1.0, green: 0.5, blue: 1.0);
LightState state = lightStateForColorOnly(light);
await bridge.updateLightState(light.rebuild(
    (l) => l..state = state.toBuilder(),
));

Different light state attributes can also be changed.

final light = lights.first;
LightState state = LightState((s) => s
    ..brightness = 100,
);
await bridge.updateLightState(light.rebuild(
    (l) => l..state = state.toBuilder(),
));

To get the light's current color in rgb values (and other known means) use the Light#colors method

final light = lights.first;
HueColor colors = light.colors();
print('red:${colors.red}, green: ${colors.green}, blue:${colors.blue}');

[0.2.1] - 15-12-2019 #

  • Updated README

[0.2.0] - 03-11-2019 #

  • Updated dependencies
  • Use built_value instead of json_serializable

[0.1.2] - 04-09-2018 #

  • Fixed dependencies and formatting
  • Tweaked the parsing of some classes

[0.1.1] - 28-07-2018 #

  • Bumped sdk version

[0.1.0] - 28-07-2018 #

  • Initial version

example/example.dart

import 'package:http/http.dart';
import 'package:hue_dart/src/core/bridge.dart';
import 'package:hue_dart/src/core/bridge_discovery.dart';
import 'package:hue_dart/src/core/discovery_result.dart';
import 'package:hue_dart/src/core/shared_functions.dart';
import 'package:hue_dart/src/light/light.dart';
import 'package:hue_dart/src/light/light_state.dart';

main(List<String> arguments) async {
  final client = Client();

  /// search for bridges
  final discovery = BridgeDiscovery(client);

  List<DiscoveryResult> discoverResults = await discovery.automatic();
  final discoveryResult = discoverResults.first;

  //create bridge
  var bridge = Bridge(client, discoveryResult.ipAddress);

  /// create a user, press the push link button before calling this
  final whiteListItem = await bridge.createUser('dart_hue#example');

  // use username for consequent calls to the bridge
  bridge.username = whiteListItem.username;

  /// get lights
  List<Light> lights = await bridge.lights();

  // update light state
  final light = lights.first.changeColor(red: 1.0, green: 0.5, blue: 1.0);
  LightState state = lightStateForColorOnly(light);
  state = state.rebuild(
    (s) => s
      ..on = true
      ..brightness = 10,
  );
  await bridge.updateLightState(light.rebuild(
    (l) => l..state = state.toBuilder(),
  ));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  hue_dart: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:hue_dart/hue_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.1 <3.0.0
built_collection ^4.2.2 4.3.2
built_value ^7.0.0 7.0.9
http ^0.12.0+2 0.12.0+4
intl ^0.16.0 0.16.1
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
fixnum 0.10.11
http_parser 3.1.4
matcher 0.12.6
meta 1.1.8
path 1.6.4
pedantic 1.9.0
quiver 2.1.3
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
built_value_generator ^7.0.0
mockito ^4.1.1
test ^1.9.3