| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'
- import { accessory } from './accessory'
- import { device } from './device'
- import { httpRequest, response } from './httpPromise'
- import { domoticaPlatform } from './platform'
- export class activityAccessory extends accessory {
- private service: Service
- static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
- return new Promise((resolve, reject) => {
- let activityDevices: device[] = []
- httpRequest("http://" + platform.config.hostname + ':' + platform.config.port + '/API/inventory/activity')
- .then((response) => {
- let devices = JSON.parse(response.body)
- for (const device of devices) {
- if (device.enabled == "true") {
- let object: device = {
- type: "Activity",
- typeId: device.id,
- uniqueId: "Activity." + device.id,
- deviceName: device.name,
- switchable: "false",
- dimmable: "false",
- detailedType: ""
- }
- activityDevices.push(object)
- }
- }
- resolve(activityDevices)
- })
- .catch((error) => {
- reject('activityAccessory::discoverDevices Error ->' + error)
- })
- })
- }
- constructor(
- private readonly platform: domoticaPlatform,
- private readonly accessory: PlatformAccessory,
- ) {
- super("Activity", accessory.context.device.typeId)
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Activity')
- .setCharacteristic(this.platform.Characteristic.Model, 'Domotica-Activity')
- .setCharacteristic(this.platform.Characteristic.SerialNumber, '08000' + accessory.context.device.typeId)
- this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch)
- this.service.getCharacteristic(this.platform.Characteristic.On)
- .onGet(this.getOn.bind(this))
- .onSet(this.setOn.bind(this));
- this.setName(accessory.context.device.deviceName)
- }
- setName(name) {
- this.service.setCharacteristic(this.platform.Characteristic.Name, name)
- }
- setValue(key, value) {
- this.service.updateCharacteristic(this.platform.Characteristic.On, false)
- }
- update() {
- }
- getOn(): CharacteristicValue {
- return false;
- }
- async setOn(value: CharacteristicValue) {
- // http://$domoticaIP/external/WebUpdate.php?data=Activity/$id/
- httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=Activity/' + this.accessory.context.device.typeId + '/')
- .catch((error) => {
- this.platform.log.debug('activityAccessory::setOn Error ->' + error)
- })
-
- }
- }
|