Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
refactor WIP
  • Loading branch information
apatsufas committed Oct 5, 2024
1 parent 8d25f8a commit 4a5e872
Show file tree
Hide file tree
Showing 12 changed files with 551 additions and 44 deletions.
12 changes: 8 additions & 4 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@
"type": "string",
"default": "plug",
"oneOf": [{
"title": "Plug",
"title": "P100",
"enum": ["Plug"]
},
{
"title": "Plug (with Power monitoring)",
"title": "P110",
"enum": ["PowerPlug"]
},
{
"title": "Light",
"title": "L510",
"enum": ["Light"]
},
{
"title": "Colorlight",
"title": "L520",
"enum": ["WhiteLight"]
},
{
"title": "L530",
"enum": ["Colorlight"]
}
],
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"axios": "^0.21.1",
"fakegato-history": "^0.6.2",
"lodash.defaults": "^4.2.0",
"node-cron": "^3.0.3",
"uuid": "8.3.2"
},
"devDependencies": {
Expand Down
21 changes: 21 additions & 0 deletions src/custom-characteristics/resetConsumptionCharacteristic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Characteristic, Units, Formats, WithUUID, Perms} from 'homebridge';

export default function resetConsumption(
DefaultCharacteristic: typeof Characteristic,
): WithUUID<new () => Characteristic> {
return class ResetConsumptionCharacteristic extends DefaultCharacteristic {
static readonly UUID = 'E863F112-079E-48FF-8F27-9C2605A29F52';

constructor() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: unable to override class constructor parameters as its a type and not a value
super('Reset Total', ResetConsumptionCharacteristic.UUID, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: custom unit
format: Formats.UINT32,
unit: Units.SECONDS,
perms: [Perms.PAIRED_READ, Perms.NOTIFY, Perms.PAIRED_WRITE],
});
}
};
}
5 changes: 4 additions & 1 deletion src/homekit-device/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ export type LightSysinfo = PlugSysinfo &{
brightness: number;
};

export type ColorLightSysinfo = LightSysinfo &{
export type ColorTempLightSysinfo = LightSysinfo &{
color_temp: number;
};

export type ColorLightSysinfo = ColorTempLightSysinfo &{
hue: number;
saturation: number;
};
Expand Down
10 changes: 10 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { L530Accessory } from './platformL530Accessory';
import fakegato from 'fakegato-history';
import { P110Accessory } from './platformP110Accessory';
import Characteristics from './custom-characteristics';
import { L520EAccessory } from './platformL520EAccessory';

/**
* TapoPlatform
Expand Down Expand Up @@ -109,6 +110,8 @@ export default class TapoPlatform implements DynamicPlatformPlugin {
// this is imported from `platformAccessory.ts`
if(device.type && device.type.toLowerCase() === 'colorlight'){
new L530Accessory(this.log, this, existingAccessory, device.timeout ? device.timeout : 2, device.updateInterval);
} else if(device.type && device.type.toLowerCase() === 'whiteLight'){
new L520EAccessory(this.log, this, existingAccessory, device.timeout ? device.timeout : 2, device.updateInterval);
} else if(device.type && device.type.toLowerCase() === 'light'){
new L510EAccessory(this.log, this, existingAccessory, device.timeout ? device.timeout : 2, device.updateInterval);
} else if(device.type && device.type.toLowerCase() === 'powerplug'){
Expand Down Expand Up @@ -147,6 +150,13 @@ export default class TapoPlatform implements DynamicPlatformPlugin {
// the `context` property can be used to store any data about the accessory you may need
accessory.context.device = device;
new L510EAccessory(this.log, this, accessory, device.timeout ? device.timeout : 2, device.updateInterval);
} else if(device.type && device.type.toLowerCase() === 'whiteLight'){
// create a new accessory
accessory = new this.api.platformAccessory(device.name ? device.name : device.host, uuid, Categories.LIGHTBULB);
// store a copy of the device object in the `accessory.context`
// the `context` property can be used to store any data about the accessory you may need
accessory.context.device = device;
new L520EAccessory(this.log, this, accessory, device.timeout ? device.timeout : 2, device.updateInterval);
} else if(device.type && device.type.toLowerCase() === 'powerplug'){
// create a new accessory
accessory = new this.api.platformAccessory(device.name ? device.name : device.host, uuid, Categories.OUTLET);
Expand Down
Loading

0 comments on commit 4a5e872

Please sign in to comment.