maxinminax / node-mihome

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
MIT License
121 stars 34 forks source link

New Device yeelink.light.ceiling1 #27

Closed Pittini closed 3 years ago

Pittini commented 3 years ago

Hi, please insert this Device (trying the yeelink.light.ceiling3 as template) for testing. Its also a userrequest, he will test, then i report.

const Device = require('../device-miio');
const { withLightEffect } = require('../utils');

module.exports = class extends Device {

  static model = 'yeelink.light.ceiling1';
  static name = 'Yeelight LED Ceiling Light';
  static image = 'http://static.home.mi.com/app/image/get/file/developer_1500887836qfgbqwws.png';

  constructor(opts) {
    super(opts);

    this._propertiesToMonitor = ['power', 'night_mode', 'bright', 'ct', 'nl_br'];
  }

  getPower() {
    const { power } = this.properties;
    if (power === 'on') return true;
    if (power === 'off') return false;
    return undefined;
  }

  getBrightness() {
    const brightness = parseInt(this.properties.bright, 10);
    const nightLightBrightness = parseInt(this.properties.nl_br, 10);
    if (nightLightBrightness > 0) return nightLightBrightness;
    if (brightness > 0) return brightness;
    return undefined;
  }

  getColorTemperature() {
    const colorTemperature = parseInt(this.properties.ct, 10);
    if (colorTemperature > 0) return colorTemperature;
    return undefined;
  }

  getSleepMode() {
    const nightLightBrightness = parseInt(this.properties.nl_br, 10);
    if (nightLightBrightness > 0) return true;
    if (nightLightBrightness === 0) return false;
    return undefined;
  }

  setPower(v) {
    return this.miioCall('set_power', withLightEffect(v ? 'on' : 'off'));
  }

  setBrightness(v) {
    return this.miioCall('set_bright', withLightEffect(v));
  }

  setColorTemperature(v) {
    return this.miioCall('set_ct_abx', withLightEffect(v));
  }

  setSleepMode(v) {
    return this.miioCall('set_ps', ['nightlight', v ? 'on' : 'off']);
  }

};
maxinminax commented 3 years ago

added in new version 0.0.31, pls create pull request for new device in the future