homebridge-veritable-potager
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -10,2 +10,3 @@ import { PlatformAccessory, CharacteristicValue } from 'homebridge'; | ||
private configCharacteristic?; | ||
private statusCharacteristic?; | ||
private serviceLight; | ||
@@ -12,0 +13,0 @@ private sensorService; |
@@ -21,3 +21,3 @@ "use strict"; | ||
this.peripheral.on('disconnect', async () => { | ||
this.platform.log.info('Disconnected:', this.peripheral.advertisement.localName); | ||
this.platform.log.info('Disconnected:', this.peripheral.advertisement.localName, 'device is now', this.peripheral.state); | ||
}); | ||
@@ -41,8 +41,8 @@ this.accessory.getService(this.platform.Service.AccessoryInformation) | ||
.onGet(this.getContactSensorState.bind(this)); | ||
this.limit(() => { | ||
this.reload(true); | ||
this.limit(async () => { | ||
await this.reload(true); | ||
}); | ||
setInterval(() => { | ||
this.limit(() => { | ||
this.reload(); | ||
setInterval(async () => { | ||
await this.limit(async () => { | ||
await this.reload(); | ||
}); | ||
@@ -56,8 +56,33 @@ }, 60000); | ||
} | ||
if (firstStart || !this.statusCharacteristic) { | ||
const services = await this.peripheral.discoverServicesAsync([]); | ||
const service = services.find((s) => s.uuid === 'fabca1ea9cc34640bb586d8be824421c'); | ||
const serviceCharacteristics = await service.discoverCharacteristicsAsync([]); | ||
this.statusCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'a0e46546c5154eb5987e61394f91b560'); | ||
this.configCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'f65d72680bef46dc85d0f64ffb2296af'); | ||
const validationKeyCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'f29e003d521e4388bc7c4de6741e8d04'); | ||
const currentTimeService = services.find((s) => s.uuid === '1805'); | ||
const currentTimeCharacteristics = await currentTimeService.discoverCharacteristicsAsync([]); | ||
const currentTimeCharacteristic = currentTimeCharacteristics.find((c) => c.uuid === '2a2b'); | ||
// write validation key to device (this is an hardcoded password without any challenge) | ||
await validationKeyCharacteristic.writeAsync(Buffer.from([100, 25, 4, 39]), false); | ||
// get current date | ||
const currentTimeData = await currentTimeCharacteristic.readAsync(); | ||
this.platform.log.debug(`Current time -> ${currentTimeData.toString('hex')}`); | ||
const peripheralDate = new Date(); | ||
peripheralDate.setFullYear(currentTimeData.readUInt16LE(0), currentTimeData.readUInt8(2) - 1, currentTimeData.readUInt8(3)); | ||
peripheralDate.setHours(currentTimeData.readUInt8(4), currentTimeData.readUInt8(5), currentTimeData.readUInt8(6)); | ||
const now = new Date(); | ||
const nowBuffer = Buffer.alloc(10); | ||
nowBuffer.writeUInt16LE(now.getFullYear(), 0); | ||
nowBuffer.writeUInt8(now.getMonth() + 1, 2); | ||
nowBuffer.writeUInt8(now.getDate(), 3); | ||
nowBuffer.writeUInt8(now.getHours(), 4); | ||
nowBuffer.writeUInt8(now.getMinutes(), 5); | ||
nowBuffer.writeUInt8(now.getSeconds(), 6); | ||
this.platform.log.debug(`New time -> ${nowBuffer.toString('hex')}`); | ||
await currentTimeCharacteristic.writeAsync(nowBuffer, false); | ||
} | ||
this.platform.log.debug('Current status ->', this.state); | ||
const services = await this.peripheral.discoverServicesAsync([]); | ||
const service = services.find((s) => s.uuid === 'fabca1ea9cc34640bb586d8be824421c'); | ||
const serviceCharacteristics = await service.discoverCharacteristicsAsync([]); | ||
const statusCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'a0e46546c5154eb5987e61394f91b560'); | ||
const statusData = await statusCharacteristic.readAsync(); | ||
const statusData = await this.statusCharacteristic.readAsync(); | ||
const statusInt = statusData.readUInt8(); | ||
@@ -79,3 +104,2 @@ const currentOn = (statusInt & 1) > 0; | ||
} | ||
this.configCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'f65d72680bef46dc85d0f64ffb2296af'); | ||
const configData = await this.configCharacteristic.readAsync(); | ||
@@ -95,29 +119,8 @@ const configInt = configData.readUInt8(); | ||
} | ||
if (firstStart) { | ||
// write validation key to device (this is an hardcoded password without any challenge) | ||
const validationKeyCharacteristic = serviceCharacteristics.find((c) => c.uuid === 'f29e003d521e4388bc7c4de6741e8d04'); | ||
await validationKeyCharacteristic.writeAsync(Buffer.from([100, 25, 4, 39]), false); | ||
// get current date | ||
const currentTimeService = services.find((s) => s.uuid === '1805'); | ||
const currentTimeCharacteristics = await currentTimeService.discoverCharacteristicsAsync([]); | ||
const currentTimeCharacteristic = currentTimeCharacteristics.find((c) => c.uuid === '2a2b'); | ||
const currentTimeData = await currentTimeCharacteristic.readAsync(); | ||
this.platform.log.debug(`Current time -> ${currentTimeData.toString('hex')}`); | ||
const peripheralDate = new Date(); | ||
peripheralDate.setFullYear(currentTimeData.readUInt16LE(0), currentTimeData.readUInt8(2) - 1, currentTimeData.readUInt8(3)); | ||
peripheralDate.setHours(currentTimeData.readUInt8(4), currentTimeData.readUInt8(5), currentTimeData.readUInt8(6)); | ||
const now = new Date(); | ||
const nowBuffer = Buffer.alloc(10); | ||
nowBuffer.writeUInt16LE(now.getFullYear(), 0); | ||
nowBuffer.writeUInt8(now.getMonth() + 1, 2); | ||
nowBuffer.writeUInt8(now.getDate(), 3); | ||
nowBuffer.writeUInt8(now.getHours(), 4); | ||
nowBuffer.writeUInt8(now.getMinutes(), 5); | ||
nowBuffer.writeUInt8(now.getSeconds(), 6); | ||
this.platform.log.debug(`New time -> ${nowBuffer.toString('hex')}`); | ||
await currentTimeCharacteristic.writeAsync(nowBuffer, false); | ||
} | ||
this.platform.log.debug('New status ->', this.state); | ||
} | ||
async setOn(value) { | ||
if (this.peripheral.state !== 'connected') { | ||
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */); | ||
} | ||
const isOn = value; | ||
@@ -143,2 +146,5 @@ this.platform.log.debug('Will Set Characteristic On ->', value); | ||
async setBrightness(value) { | ||
if (this.peripheral.state !== 'connected') { | ||
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */); | ||
} | ||
const v = value; | ||
@@ -145,0 +151,0 @@ let currentLightMode = this.state.LightMode; |
{ | ||
"displayName": "Homebridge Veritable Potager BLE", | ||
"name": "homebridge-veritable-potager", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A short description about what your plugin does.", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47470
335