ilcato / homebridge-Fibaro-HC2

Homebridge plugin for Fibaro Home Center 2 (and Home Center Lite ...)
Apache License 2.0
65 stars 27 forks source link

Missing hapService.BatteryService #137

Closed lboue closed 5 years ago

lboue commented 5 years ago

Hello,

Could you tell me how to add the hapService.BatteryService service to the accessory in the createShadowAccessory method? The goal is to expose Battery Level

homebridge-mi-aqara I found an implementation example here with the homebridge-mi-aqara plugin and the SmokeDetectorParser.js class

homebridge-hue example https://github.com/ebaauw/homebridge-hue/blob/314719ea2771381289b65c828471646e085a5663/lib/HueAccessory.js#L292

HueAccessory.prototype.getBatteryService = function (battery) {
  if (this.batteryService == null) {
    this.batteryService = new Service.BatteryService(this.name)
    this.batteryService.getCharacteristic(Characteristic.ChargingState)
      .setValue(Characteristic.ChargingState.NOT_CHARGEABLE)
    this.state.battery = battery
    this.checkBattery(battery)
  }
  return this.batteryService
}

Can you confirm it should be declared like this? new ShadowService(new hapService.BatteryService(device.name), [hapCharacteristic.StatusLowBattery, hapCharacteristic.BatteryLevel, hapCharacteristic.ChargingState]) Regards

ilcato commented 5 years ago

This is correct. You must also implement the corresponding functions in getFunctions.ts.

hovorkap commented 5 years ago

I have a working solution for this, expect a PR shortly https://github.com/hovorkap/homebridge-Fibaro-HC2/pull/2

lboue commented 5 years ago

Fixed by PR #150.