hue_dart 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

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 = new Client();
final discovery = new BridgeDiscovery(client);

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

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

For web, use the BrowserClient.

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

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

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

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

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

import package:hue_dart/hue.dart;

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

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

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

Create a new user #

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

final bridge = new 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;
light.changeColor(red: 1.0, green: 0.3, blue: 1.0);
await bridge.updateLightState(light);

Different light state attributes can also be changed.

final light = lights.first;
light.state.brightness = 100;
await bridge.updateLightState(light);

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.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/light/light.dart';

main(List<String> arguments) async {

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

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

  //create bridge
  var bridge = new 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;
  light.state.on = true;
  light.state.brightness = 10;
  await bridge.updateLightState(light);
}

Use this package as a library

1. Depend on it

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


dependencies:
  hue_dart: ^0.1.2

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]
44
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
57
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:hue_dart/hue_dart.dart.

Health suggestions

Fix lib/src/scene/scene_api.dart. (-1 points)

Analysis of lib/src/scene/scene_api.dart reported 2 hints:

line 14 col 3: Avoid return types on setters.

line 15 col 3: Avoid return types on setters.

Fix lib/src/core/bridge.dart. (-0.50 points)

Analysis of lib/src/core/bridge.dart reported 1 hint:

line 63 col 3: Avoid return types on setters.

Fix lib/src/group/group_api.dart. (-0.50 points)

Analysis of lib/src/group/group_api.dart reported 1 hint:

line 14 col 3: Avoid return types on setters.

Fix additional 7 files with analysis or formatting issues. (-3 points)

Additional issues in the following files:

  • lib/src/light/light_api.dart (1 hint)
  • lib/src/resource_link/resource_link_api.dart (1 hint)
  • lib/src/rule/rule_api.dart (1 hint)
  • lib/src/schedule/schedule_api.dart (1 hint)
  • lib/src/schedule/timer.dart (1 hint)
  • lib/src/sensor/sensor_api.dart (1 hint)
  • lib/src/resource_link/resource_links_bloc.dart (Run dartfmt to format lib/src/resource_link/resource_links_bloc.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (http, intl, json_serializable).

Package is getting outdated. (-12.88 points)

The package was last published 58 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.69.0 <3.0.0
http ^0.11.3+16 0.11.3+17 0.12.0+2
intl ^0.15.6 0.15.8 0.16.0
json_serializable ^0.5.8 0.5.8+1 3.2.3
Transitive dependencies
analyzer 0.32.6 0.39.0
args 1.5.2
async 2.4.0
build 0.12.8 1.2.0
build_config 0.3.1+2 0.4.1+1
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.1.3 1.3.2
front_end 0.1.4+2 0.1.28
glob 1.2.0
html 0.14.0+3
http_parser 3.1.3
js 0.6.1+1
json_annotation 0.2.9+1 3.0.0
kernel 0.3.4+2 0.3.28
logging 0.11.3+2
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
plugin 0.2.0+3
pub_semver 1.4.2
pubspec_parse 0.1.2+2 0.1.5
source_gen 0.8.3+1 0.9.4+5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner any
mockito ^3.0.0
test ^1.2.0