Skip to content

Commit

Permalink
1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
apatsufas committed Oct 8, 2024
1 parent 9abc67e commit 929af90
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 127 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Example:
"name": "Kitchen",
"host": "192.168.1.21",
"type": "Plug",
"updateInterval": 30,
"updateInterval": 10,
"timeout": 2
}
]
Expand Down Expand Up @@ -105,7 +105,7 @@ Example response from this endpoint:
"rssi":-61,
"region":"Europe/Athens",
"time_diff":120,
"lang":"en_US"}}
"lang":"en_US"}
```

## Information
Expand Down
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"updateInterval": {
"title": "Interval in which the state of the Accessory should be updated (in seconds)",
"type": "number",
"default": "30",
"default": "10",
"required": false
},
"timeout": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"displayName": "Tapo P100 Plugin",
"name": "homebridge-tapo",
"version": "1.5.1-beta1",
"version": "1.5.1",
"description": "Homebridge Plugin for TP-Link Tapo P100 Plugs",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/apatsufas/homebridge-tapo-p100"
"url": "git+https://github.com/apatsufas/homebridge-tapo-p100.git"
},
"bugs": {
"url": "https://github.com/apatsufas/homebridge-tapo-p100/issues"
Expand Down
6 changes: 3 additions & 3 deletions src/platformL510EAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class L510EAccessory extends TPLinkPlatformAccessory<L510E> {
}

protected init(platform: TapoPlatform, updateInterval?: number){
this.tpLinkAccessory.getDeviceInfo().then((sysInfo) => {
this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
// set accessory information
this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
Expand All @@ -54,7 +54,7 @@ export class L510EAccessory extends TPLinkPlatformAccessory<L510E> {
.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

const interval = updateInterval ? updateInterval*1000 : 30000;
const interval = updateInterval ? updateInterval*1000 : 10000;
setTimeout(()=>{
this.updateState(interval);
}, interval);
Expand Down Expand Up @@ -116,7 +116,7 @@ export class L510EAccessory extends TPLinkPlatformAccessory<L510E> {
}

protected updateState(interval:number){
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.tpLinkAccessory.getDeviceInfo(true).then((response) => {
if(response){
const isOn = response.device_on;
const brightness = response.brightness;
Expand Down
6 changes: 3 additions & 3 deletions src/platformL520EAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class L520EAccessory extends TPLinkPlatformAccessory<L520E> {
}

protected init(platform: TapoPlatform, updateInterval?: number){
this.tpLinkAccessory.getDeviceInfo().then((sysInfo) => {
this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
// set accessory information
this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
Expand Down Expand Up @@ -65,7 +65,7 @@ export class L520EAccessory extends TPLinkPlatformAccessory<L520E> {
}); // GET - bind to the `getColorTemp` method below


const interval = updateInterval ? updateInterval*1000 : 30000;
const interval = updateInterval ? updateInterval*1000 : 10000;
setTimeout(()=>{
this.updateState(interval);
}, interval);
Expand Down Expand Up @@ -127,7 +127,7 @@ export class L520EAccessory extends TPLinkPlatformAccessory<L520E> {
}

protected updateState(interval:number){
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.tpLinkAccessory.getDeviceInfo(true).then((response) => {
if(response){
const isOn = response.device_on;
const brightness = response.brightness;
Expand Down
58 changes: 42 additions & 16 deletions src/platformL530Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
}

protected init(platform: TapoPlatform, updateInterval?: number){
this.tpLinkAccessory.getDeviceInfo().then((sysInfo) => {
this.log.debug('init called');

this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
this.log.debug('SysInfo: ', sysInfo);

// set accessory information
Expand Down Expand Up @@ -84,18 +86,10 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
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));

this.service.getCharacteristic(this.platform.customCharacteristics.ResetConsumptionCharacteristic)
.on('set', this.resetConsumption.bind(this));

// Setup the adaptive lighting controller if available
if (this.platform.api.versionGreaterOrEqual && this.platform.api.versionGreaterOrEqual('1.3.0-beta.23')) {
this.log.debug('Enabling Adaptvie Lightning');
this.adaptiveLightingController = new platform.api.hap.AdaptiveLightingController(
this.service,
);
Expand All @@ -104,7 +98,7 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {

this.updateConsumption();

const interval = updateInterval ? updateInterval*1000 : 30000;
const interval = updateInterval ? updateInterval*1000 : 10000;
setTimeout(()=>{
this.updateState(interval);
}, interval);
Expand Down Expand Up @@ -145,6 +139,7 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
getBrightness(callback: CharacteristicGetCallback) {
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.log.debug('getBritness: ' + JSON.stringify(response));
if(response){
const brightness = response.brightness;
if(brightness !== undefined){
Expand All @@ -156,12 +151,15 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
// you must call the callback function
callback(null, brightness);
}else{
this.log.debug('getBritness: ' + 167);
callback(new Error('unreachable'), 0);
}
} else{
this.log.debug('getBritness: ' + 171);
callback(new Error('unreachable'), 0);
}
}).catch(() => {
this.log.debug('getBritness: ' + 175);
callback(new Error('unreachable'), 0);
});
}
Expand Down Expand Up @@ -197,6 +195,8 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
getColorTemp(callback: CharacteristicGetCallback) {
this.tpLinkAccessory.getColorTemp().then((response) => {
this.log.debug('getColorTemp: ' + JSON.stringify(response));

if(response !== undefined){
const color_temp = response;

Expand All @@ -208,9 +208,14 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
// you must call the callback function
callback(null, color_temp);
}else{
this.log.debug('getColorTemp: ' + 224);

callback(new Error('unreachable'), 0);
}
}).catch(() => {
}).catch((error) => {
this.log.debug('getColorTemp: ' + 229);
this.log.debug('error: ' + error);

callback(new Error('unreachable'), 0);
});
}
Expand All @@ -221,6 +226,7 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
setHue(value: CharacteristicValue, callback: CharacteristicSetCallback) {
if(this.tpLinkAccessory.getSysInfo().device_on){
this.log.debug('Homekit Hue: ' + value);
this.tpLinkAccessory.setColor(Math.round(value as number), this.tpLinkAccessory.getSysInfo().saturation).then((result) => {
if(result){
this.tpLinkAccessory.getSysInfo().hue = Math.round(value as number);
Expand All @@ -245,6 +251,8 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
getHue(callback: CharacteristicGetCallback) {
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.log.debug('getHue: ' + JSON.stringify(response));

if(response){
let hue = response.hue;
this.platform.log.debug('Get Characteristic Hue ->', hue);
Expand All @@ -259,9 +267,15 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
// you must call the callback function
callback(null, hue);
} else{
this.log.debug('getHue: ' + 282);

callback(new Error('unreachable'), 0);
}
}).catch(() => {
}).catch((error) => {
this.log.debug('Unreachable');
this.log.debug('getHue: ' + 288);
this.log.debug('error: ' + error);

callback(new Error('unreachable'), 0);
});
}
Expand All @@ -272,6 +286,7 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
setSaturation(value: CharacteristicValue, callback: CharacteristicSetCallback) {
if(this.tpLinkAccessory.getSysInfo().device_on){
this.log.debug('Homekit Saturation: ' + value);
this.tpLinkAccessory.setColor(this.tpLinkAccessory.getSysInfo().hue, Math.round(value as number)).then((result) => {
if(result){
this.tpLinkAccessory.getSysInfo().saturation = Math.round(value as number);
Expand All @@ -296,6 +311,8 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
*/
getSaturation(callback: CharacteristicGetCallback) {
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.log.debug('getSaturation: ' + JSON.stringify(response));

if(response){
let saturation = response.saturation;

Expand All @@ -310,18 +327,25 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
// you must call the callback function
callback(null, saturation);
} else{
this.log.debug('getSaturation: ' + 341);

callback(new Error('unreachable'), 0);
}
}).catch(() => {
}).catch((error) => {
this.log.debug('getSaturation: ' + 346);
this.log.debug('error: ' + error);

callback(new Error('unreachable'), 0);
});
}

private updateConsumption(){
this.log.debug('updateConsumption called');
this.tpLinkAccessory.getEnergyUsage().then((response) => {
this.log.debug('Get Characteristic Power consumption ->', JSON.stringify(response));
if (response && response.power_usage) {
if(this.lastMeasurement){
this.platform.log.debug('Get Characteristic Power consumption ->', JSON.stringify(response));
this.log.debug('Get Characteristic Power consumption ->', JSON.stringify(response));
if (this.fakeGatoHistoryService ) {
this.fakeGatoHistoryService.addEntry({
time: new Date().getTime() / 1000,
Expand Down Expand Up @@ -388,8 +412,10 @@ export class L530Accessory extends TPLinkPlatformAccessory<L530> {
}

protected updateState(interval:number){
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.log.debug('updateState called');
this.tpLinkAccessory.getDeviceInfo(true).then((response) => {
if(response){
this.log.info('Device Info: ' + JSON.stringify(response));
const isOn = response.device_on;
const saturation = response.saturation;
const hue = response.hue;
Expand Down
4 changes: 2 additions & 2 deletions src/platformP100Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class P100Accessory extends TPLinkPlatformAccessory<P100>{
}

protected init(platform: TapoPlatform, updateInterval?: number){
this.tpLinkAccessory.getDeviceInfo().then((sysInfo) => {
this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
// set accessory information
this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
Expand All @@ -53,7 +53,7 @@ export class P100Accessory extends TPLinkPlatformAccessory<P100>{
this.service.getCharacteristic(this.platform.Characteristic.OutletInUse)
.on('get', this.handleOutletInUseGet.bind(this));

const interval = updateInterval ? updateInterval*1000 : 30000;
const interval = updateInterval ? updateInterval*1000 : 10000;
this.log.debug('interval: ' + interval);

setTimeout(()=>{
Expand Down
13 changes: 2 additions & 11 deletions src/platformP110Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class P110Accessory extends TPLinkPlatformAccessory<P110>{
}

protected init(platform: TapoPlatform, updateInterval?: number){
this.tpLinkAccessory.getDeviceInfo().then((sysInfo) => {
this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
// set accessory information
this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
Expand All @@ -56,18 +56,9 @@ export class P110Accessory extends TPLinkPlatformAccessory<P110>{
.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

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));

this.service.getCharacteristic(this.platform.customCharacteristics.ResetConsumptionCharacteristic)
.on('set', this.resetConsumption.bind(this));

this.updateConsumption();

const interval = updateInterval ? updateInterval*1000 : 30000;
const interval = updateInterval ? updateInterval*1000 : 10000;
setTimeout(()=>{
this.updateState(interval);
}, interval);
Expand Down
17 changes: 5 additions & 12 deletions src/platformTPLinkAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ export abstract class TPLinkPlatformAccessory <T extends TpLinkAccessory>{
protected readonly updateInterval?: number,
) {
this.log.debug('Start adding accessory: ' + accessory.context.device.host);


this.cron.schedule('*/10 * * * *', () => {
this.initialise(platform, updateInterval);
});

/*this.cron.schedule('0 0 * * *', () => {
this.initialise(platform, updateInterval);
});*/
}

protected initialise(platform: TapoPlatform, updateInterval?: number):void{
Expand Down Expand Up @@ -98,14 +89,16 @@ export abstract class TPLinkPlatformAccessory <T extends TpLinkAccessory>{
} else{
callback(new Error('unreachable'), false);
}
}).catch(() => {
callback(new Error('unreachable'), false);
}).catch((error) => {
this.log.debug('error: ' + error);

callback(new Error('unreachable'), 0);
});
}

protected updateState(interval:number){
this.platform.log.debug('Updating state');
this.tpLinkAccessory.getDeviceInfo().then((response) => {
this.tpLinkAccessory.getDeviceInfo(true).then((response) => {
if(response){
const isOn = response.device_on;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/l510e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default class L510E extends P100 {
this.log.debug('Constructing L510E on host: ' + ipAddress);
}

async getDeviceInfo(): Promise<LightSysinfo>{
return super.getDeviceInfo().then(() => {
async getDeviceInfo(force?:boolean): Promise<LightSysinfo>{
return super.getDeviceInfo(force).then(() => {
return this.getSysInfo();
});
}
Expand Down
10 changes: 4 additions & 6 deletions src/utils/l520e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default class L520E extends L510E {
this.log.debug('Constructing L510E on host: ' + ipAddress);
}

async getDeviceInfo(): Promise<ColorTempLightSysinfo>{
return super.getDeviceInfo().then(() => {
async getDeviceInfo(force?:boolean): Promise<ColorTempLightSysinfo>{
return super.getDeviceInfo(force).then(() => {
return this.getSysInfo();
});
}

async setColorTemp(color_temp:number):Promise<true>{
async setColorTemp(color_temp:number):Promise<boolean>{
const transformedColorTemp = this.transformColorTemp(color_temp);
this.log.debug('Color Temp Tapo :' + transformedColorTemp);

Expand All @@ -40,9 +40,7 @@ export default class L520E extends L510E {
'"requestTimeMils": ' + Math.round(Date.now() * 1000) + ''+
'};';

return this.handleRequest(payload).then(()=>{
return true;
});
return this.sendRequest(payload);
}

private transformColorTemp(value: number){
Expand Down
Loading

0 comments on commit 929af90

Please sign in to comment.