homebridge#AdaptiveLightingController TypeScript Examples

The following examples show how to use homebridge#AdaptiveLightingController. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: platformL530Accessory.ts    From homebridge-tapo-p100 with Apache License 2.0 5 votes vote down vote up
private adaptiveLightingController!: AdaptiveLightingController;
Example #2
Source File: platformL530Accessory.ts    From homebridge-tapo-p100 with Apache License 2.0 4 votes vote down vote up
constructor(
    public readonly log: Logger,
    private readonly platform: TapoPlatform,
    private readonly accessory: PlatformAccessory,
    private readonly timeout: number,
    private readonly updateInterval?: number,
  ) {
    this.log.debug('Start adding accessory: ' + accessory.context.device.host);
    this.l530 = new L530(this.log, accessory.context.device.host, platform.config.username, platform.config.password, this.timeout);

    this.fakeGatoHistoryService = new this.platform.FakeGatoHistoryService('energy', accessory, {
      log: this.log,
      size:4096, 
      storage:'fs',     
    });

    this.l530.handshake().then(() => {
      this.l530.login().then(() => {
        this.l530.getDeviceInfo().then((sysInfo) => {
          this.log.debug('SysInfo: ', sysInfo);

          // set accessory information
          this.accessory.getService(this.platform.Service.AccessoryInformation)!
            .setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
            .setCharacteristic(this.platform.Characteristic.Model, 'Tapo L530')
            .setCharacteristic(this.platform.Characteristic.SerialNumber, sysInfo.hw_id);

          // each service must implement at-minimum the "required characteristics" for the given service type
          // see https://developers.homebridge.io/#/service/Outlet

          // register handlers for the On/Off Characteristic
          this.service.getCharacteristic(this.platform.Characteristic.On)
            .on('set', this.setOn.bind(this))                // SET - bind to the `setOn` method below
            .on('get', this.getOn.bind(this));               // GET - bind to the `getOn` method below

          // register handlers for the Brightness Characteristic
          this.service.getCharacteristic(this.platform.Characteristic.Brightness)
            .on('set', this.setBrightness.bind(this))                // SET - bind to the `setBrightness` method below
            .on('get', this.getBrightness.bind(this));               // GET - bind to the `getBrightness` method below

          // register handlers for the ColorTemperature Characteristic
          this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature)
            .on('set', this.setColorTemp.bind(this))                // SET - bind to the `setColorTemp` method below
            .on('get', this.getColorTemp.bind(this))
            .setProps({
              minValue: 154,
              maxValue: 400,
              minStep: 1,
            });              // GET - bind to the `getColorTemp` method below

          // register handlers for the Hue Characteristic
          this.service.getCharacteristic(this.platform.Characteristic.Hue)
            .on('set', this.setHue.bind(this))                // SET - bind to the `setHue` method below
            .on('get', this.getHue.bind(this));               // GET - bind to the `getHue` method below

          // register handlers for the Saturation Characteristic
          this.service.getCharacteristic(this.platform.Characteristic.Saturation)
            .on('set', this.setSaturation.bind(this))                // SET - bind to the `setSaturation` method below
            .on('get', this.getSaturation.bind(this));               // GET - bind to the `getSaturation` method below

          this.service.getCharacteristic(this.platform.customCharacteristics.CurrentConsumptionCharacteristic)
            .on('get', this.getCurrentConsumption.bind(this));

          this.service.getCharacteristic(this.platform.customCharacteristics.TotalConsumptionCharacteristic)
            .on('get', this.getTotalConsumption.bind(this));

          // Setup the adaptive lighting controller if available
          if (this.platform.api.versionGreaterOrEqual && this.platform.api.versionGreaterOrEqual('1.3.0-beta.23')) {
            this.adaptiveLightingController = new platform.api.hap.AdaptiveLightingController(
              this.service,
            );
            this.accessory.configureController(this.adaptiveLightingController);
          }

          this.updateConsumption();

          const interval = updateInterval ? updateInterval*1000 : 30000;
          setTimeout(()=>{
            this.updateState(interval);
          }, interval);
        }).catch(() => {
          this.setNoResponse();
          this.log.error('100 - Get Device Info failed');
        });
      }).catch(() => {
        this.setNoResponse();
        this.log.error('Login failed');
      });
    }).catch(() => {
      this.setNoResponse();
      this.log.error('Handshake failed');
    });
    
    // get the Outlet service if it exists, otherwise create a new Outlet service
    this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);

    // set the service name, this is what is displayed as the default name on the Home app
    // we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
    this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
  }