yeedart 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

Yeedart #

Pub Build Status

Dart library for controlling Yeelight products over LAN.

More info about Yeelight API:

Contents #

Installation #

  1. Depend on it

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

dependencies:
  yeedart: ^0.1.0+1
  1. Install it

You can install packages from the command line:

with pub:

$ pub get

or 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.

  1. Import it

Now in your Dart code, you can use:

import 'package:yeedart/yeedart.dart';

Usage #

Device discovery #

First of all, you need to know your device's IP address and port. You can use Yeelight.discover() method which returns list of DiscoveryResponse.

final responses = await Yeelight.discover();
final response = responses.first; // or filter..

Each response contains IP address and port for given device and other properties (name, firmware version, current state,...).

ℹ️ You can also specify timeout for discovery. Default is 2 seconds.

Connect to the device #

final device = Device(
  address: InternetAddress("192.168.1.183"),
  port: 55443,
);

await device.turnOn(); // turn the device on

// set red color with smooth transition
await device.setRGB(
  color: Colors.red,
  effect: const Effect.smooth(),
  duration: const Duration(milliseconds: 500),
);

await device.setBrightness(brightness: 70); // set brightness to 70 %

device.disconnect(); // always disconnect when you are done!

⚠️ When you instantiate Device, new TCP connection is created automatically. This single TCP connection is then used for every command. So when you are done, you should close the connection.

ℹ️ Note that when call device.disconnect() and then call for example device.turnOff(), new TCP connection will be created automatically.

ℹ️ Also note that Yeelight connections are rate-limited to 60 per minute.

Main and background light #

Some devices can be equiped with two lights: main and background. Methods in Device class control main light by default (for example device.setRGB(color: Colors.red) sets RGB color for main light. If you want to set RGB color for background light, you have to specify lightType parameter: device.setRGB(color: Colors.red, lightType: LightType.backgroud);.

You can also use LightType.both but ONLY for toggling: device.toggle(lightType: LightType.both).

Flow #

Flow (color flow) is basically a list of transitions. To start a flow use startFlow() method and provide Flow. Flow has 3 required parameters:

  • count - number of transitions to run, 0 for infinite loop. If you have 10 transitions and count is 5, it will run only first 5 transitions!
  • action - specifies action to take after the flow ends.
    • FlowAction.stay to stay at the last state when the flow is stopped.
    • FlowAction.recover to recover the state before the flow.
    • FlowAction.turnOff to turn off.
  • transitions - list of FlowTransition, FlowTransition.rgb(), FlowTransition.colorTemperature() or FlowTransition.sleep().

Following example will loop red, green and blue colors at full brightness.

await device.startFlow(
  flow: const Flow(
    count: 0,
    action: FlowAction.recover(),
    transitions: [
      FlowTransition.rgb(color: 0xff0000, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
      FlowTransition.rgb(color: 0x00ff00, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
      FlowTransition.rgb(color: 0x0000ff, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
    ],
  ),
);

To manually stop flow, use device.stopFlow().

This library also includes some predefined flows:

  • Flow.rgb() - changes color from red, to green to blue
  • Flow.police - changes red and blue color like police lights.
  • Flow.pulse() - creates pulse with given color

Scene #

Scene allows you to set light to specific state. To use scene, use setScene() method and provide Scene.

You can use:

  • Scene.color() or Scene.hsv() to set color and brightness
  • Scene.colorTemperature to set color temperature and brightness
  • Scene.colorFlow() to start a color Flow
  • Scene.autoDelayOff() to turn on the device to specified brightness and start a timer to turn off the light after specified number of minutes.

Example:

device.setScene(scene: Scene.color(color: 0xff0000, brightness: 100));

Features and bugs #

Please file feature requests and bugs at the issue tracker.

[0.1.1] - 2019-12-22

  • lint fixes
  • updated dependencies

[0.1.0] - 2019-10-26

  • initial version
  • added device discovery & controls
  • added color flow and scene support

example/yeedart_example.dart

import 'dart:io';

import 'package:yeedart/yeedart.dart';

Future<void> main() async {
  // Discover devices
//  final responses = await Yeelight.discover();
//  final response = responses.first;
//  final device = Device(address: response.address, port: response.port);
//  device.turnOn();
//  await Future<void>.delayed(const Duration(seconds: 3));
//  device.turnOff();
//  device.disconnect();

  // Connect directly to device
  final device = Device(
    address: InternetAddress('192.168.1.183'),
    port: 55443,
  );

  // ignore: avoid_print
  print(await device.getProps(id: 1, parameters: [
    'name',
    'model',
    'fw_ver',
    'power',
    'color_mode',
    'bright',
    'ct',
    'rgb',
    'hue',
    'sat',
  ]));

  await device.turnOn();
  await Future<void>.delayed(const Duration(seconds: 3));
  await device.turnOff();
  device.disconnect();
}

Use this package as a library

1. Depend on it

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


dependencies:
  yeedart: ^0.1.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:yeedart/yeedart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
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]
62
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
collection ^1.14.11 1.14.12
meta ^1.1.8 1.1.8
path ^1.6.4 1.6.4
Dev dependencies
lint ^1.1.0
test ^1.9.4