mirror of
https://github.com/dtwardow/homebridge-multi-tap-switch.git
synced 2026-11-02 05:18:30 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62465b1deb | ||
|
|
e74bfeb4e2 | ||
|
|
b31fbe03fa | ||
|
|
7f97b81f77 | ||
|
|
79045cfaa0 | ||
|
|
68988d5098 | ||
|
|
cdc370a69a | ||
|
|
bccc0fa4cd | ||
|
|
2b840ec462 | ||
|
|
a8bdeddabd | ||
|
|
904ad68f6d | ||
|
|
08cbdc46b9 | ||
|
|
0134932ba3 | ||
|
|
ac935d9cf5 | ||
|
|
6640dc3d07 | ||
|
|
92c9de5c31 |
No files matched your search
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended" // uses the recommended rules from the @typescript-eslint/eslint-plugin
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"dist"
|
||||
],
|
||||
"rules": {
|
||||
"quotes": ["warn", "single"],
|
||||
"indent": ["warn", 2, { "SwitchCase": 1 }],
|
||||
"semi": ["off"],
|
||||
"comma-dangle": ["warn", "always-multiline"],
|
||||
"dot-notation": "off",
|
||||
"eqeqeq": "warn",
|
||||
"curly": ["warn", "all"],
|
||||
"brace-style": ["warn"],
|
||||
"prefer-arrow-callback": ["warn"],
|
||||
"max-len": ["warn", 140],
|
||||
"no-console": ["warn"], // use the provided Homebridge log method instead
|
||||
"no-non-null-assertion": ["off"],
|
||||
"comma-spacing": ["error"],
|
||||
"no-multi-spaces": ["warn", { "ignoreEOLComments": true }],
|
||||
"no-trailing-spaces": ["warn"],
|
||||
"lines-between-class-members": ["warn", "always", {"exceptAfterSingleLine": true}],
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/semi": ["warn"],
|
||||
"@typescript-eslint/member-delimiter-style": ["warn"]
|
||||
}
|
||||
}
|
||||
@@ -19,5 +19,4 @@ assignees: ''
|
||||
**Additional context:**
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
||||
|
||||
|
||||
<!-- Click the "Preview" tab before you submit to ensure the formatting is correct. -->
|
||||
@@ -7,15 +7,15 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# the Node.js versions to build on
|
||||
node-version: [12.x, 13.x, 14.x, 15.x, 16.x]
|
||||
node-version: [20.x, 22.x, 24.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
@@ -27,5 +27,11 @@ jobs:
|
||||
|
||||
- name: Build the project
|
||||
run: npm run build
|
||||
env:
|
||||
CI: true
|
||||
|
||||
- name: List, audit, fix outdated dependencies and build again
|
||||
run: |
|
||||
npm list --outdated
|
||||
npm audit || true # ignore failures
|
||||
npm audit fix || true
|
||||
npm list --outdated
|
||||
npm run build
|
||||
@@ -1,18 +1,24 @@
|
||||
name: Publish Package to npmjs
|
||||
name: Publish Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
id-token: write # Required for OIDC
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
# Setup .npmrc file to publish to npm
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '16.x'
|
||||
node-version: '24'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- run: npm ci
|
||||
- run: npm run build --if-present
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
+3
-1
@@ -10,7 +10,7 @@ src
|
||||
.github
|
||||
|
||||
# eslint
|
||||
.eslintrc
|
||||
eslint.config.js
|
||||
|
||||
# typescript
|
||||
tsconfig.json
|
||||
@@ -135,3 +135,5 @@ web_modules/
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.pnp.*
|
||||
|
||||
test/
|
||||
Vendored
+4
-2
@@ -1,8 +1,10 @@
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"editor.rulers": [ 140 ],
|
||||
"editor.rulers": [
|
||||
140
|
||||
],
|
||||
"eslint.enable": true
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<p align="center">
|
||||
<img src="https://github.com/homebridge/branding/raw/master/logos/homebridge-wordmark-logo-vertical.png" width="150" alt="Homebridge">
|
||||
<p>
|
||||
<img src="https://github.com/homebridge/branding/blob/latest/logos/homebridge-color-round-stylized.png" width="150" alt="Homebridge">
|
||||
</p>
|
||||
|
||||
# Homebridge Multi-Tap-Switch
|
||||
@@ -32,24 +32,21 @@ or manually by following these instructions:
|
||||
The configuration allows the user to add multiple **Multi-Tap-Switches**. The following parameters are available:
|
||||
|
||||
| Option | Default Value | Characteristic (runtime configuration) | Description |
|
||||
|------------------------------------|----------------|----------------------------------------|-------------------------------------------------------------------------------------------|
|
||||
|-------------------------------------|----------------|----------------------------------------|-------------------------------------------------------------------------------------------|
|
||||
| `name` | MultiTapSwitch | | Name of the Platform Accessory (primarily shown in logs) |
|
||||
| `devices[]` | | | Array of configured devices |
|
||||
| `devices[].name` | | | Name of the switch |
|
||||
| `devices[].numberConfiguredScenes` | 5 | `Configured Scenes` | Number of **stateless** switches (cannot be changed during runtime) |
|
||||
| `devices[].triggerTimeout` | 10 | `Trigger Timeout` | Seconds, after which the switch is reset (starting from the first **programmable** switch |
|
||||
| `devices[].resetAfterSwitchOff` | false | | Reset the switch (like after timeout), when it is turned ```OFF```. |
|
||||
| `devices[].logging` | false | | Logging of switch/trigger actions. |
|
||||
| `devices[] .numberConfiguredScenes` | 5 | `Configured Scenes` | Number of **stateless** switches (cannot be changed during runtime) |
|
||||
| `devices[] .triggerTimeout` | 10 | `Trigger Timeout` | Seconds, after which the switch is reset (starting from the first **programmable** switch |
|
||||
| `devices[] .resetAfterSwitchOff` | false | | Reset the switch (like after timeout), when it is turned ```OFF```. |
|
||||
| `devices[] .logging` | false | | Logging of switch/trigger actions. |
|
||||
|
||||
The parameter ```triggerTimeout``` can be changed in the configuration during runtime. So, this is just the initial value.<br>
|
||||
> **NOTE:** If the value is out of sync from the configured value (i.e. updated via Home-App), it will not be updated on later configuration changes.
|
||||
> It must be set back to the configured value first!
|
||||
The parameter ```triggerTimeout``` can be changed in the configuration during runtime. So, this is just the initial value.
|
||||
|
||||
The parameter ```numberConfiguredScenes``` just defines how many **programmable** switches are available. The number of
|
||||
The parameter ```numberConfiguredScenes``` just defines how many **programmable** switches are available (currently, there is no limit). The number of
|
||||
really **used** switches can configured during runtime, between 0 and the configured number.
|
||||
|
||||
> **NOTE:** Additional parameters (also called **Characteristics**) can only be configured via 3rd-party HomeKit apps (i.e.
|
||||
> Home+, Controller for HomeKit, etc.), but in the basic Home App!
|
||||
> **NOTE:** Additional parameters (also called **Characteristics**) can only be configured via 3rd-party HomeKit apps, but not in the basic Home App!
|
||||
|
||||
So, an example **platform** plugin config will look as follows:
|
||||
|
||||
@@ -68,3 +65,9 @@ So, an example **platform** plugin config will look as follows:
|
||||
]
|
||||
}
|
||||
````
|
||||
|
||||
## Contribution
|
||||
|
||||
Contributions are always welcome. You can also use the code for own projects and adapt it to your specific needs.
|
||||
|
||||
If you find any bugs or have ideas for optimizations or new features, feel free.
|
||||
@@ -0,0 +1,35 @@
|
||||
import eslint from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['dist/**'],
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'quotes': ['error', 'single'],
|
||||
'indent': ['error', 2, { 'SwitchCase': 0 }],
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'semi': ['error', 'always'],
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'dot-notation': 'error',
|
||||
'eqeqeq': ['error', 'smart'],
|
||||
'curly': ['error', 'all'],
|
||||
'brace-style': ['error'],
|
||||
'prefer-arrow-callback': 'warn',
|
||||
'max-len': ['warn', 160],
|
||||
'object-curly-spacing': ['error', 'always'],
|
||||
'no-use-before-define': 'off',
|
||||
'@typescript-eslint/no-use-before-define': ['error', { 'classes': false, 'enums': false }],
|
||||
'@typescript-eslint/no-unused-vars': ['error', { 'caughtErrors': 'none' }],
|
||||
},
|
||||
},
|
||||
{
|
||||
languageOptions: {
|
||||
ecmaVersion: 2022,
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
);
|
||||
Generated
+3599
-3656
File diff suppressed because it is too large.
Load diff
+15
-12
@@ -2,7 +2,7 @@
|
||||
"private": false,
|
||||
"displayName": "Homebridge Multi-Tap-Switch",
|
||||
"name": "homebridge-multi-tap-switch",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "A configurable multi-tap switch for i.e. switching scenes",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
@@ -13,8 +13,8 @@
|
||||
"url": "https://github.com/dtwardow/homebridge-multi-tap-switch/issues"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.1",
|
||||
"homebridge": ">=1.3.5"
|
||||
"node": "^20.18.0 || ^22.10.0 || ^24.0.0",
|
||||
"homebridge": "^1.8.0 || ^2.0.0-beta.0"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
@@ -26,16 +26,19 @@
|
||||
"keywords": [
|
||||
"homebridge-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"homebridge-lib": "^7.1.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.10.9",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"eslint": "^8.0.1",
|
||||
"homebridge": "^1.3.5",
|
||||
"nodemon": "^2.0.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-node": "^10.3.0",
|
||||
"typescript": "^4.4.4"
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/node": "^24.10.1",
|
||||
"eslint": "^9.39.1",
|
||||
"homebridge": "^2.0.0-beta.55",
|
||||
"nodemon": "^3.1.11",
|
||||
"rimraf": "^6.1.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.46.4"
|
||||
},
|
||||
"homepage": "https://github.com/dtwardow/homebridge-multi-tap-switch#readme",
|
||||
"author": "Dennis Twardowsky <twardowsky@gmail.com>"
|
||||
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
import {PlatformConfig} from 'homebridge';
|
||||
import { PlatformConfig } from 'homebridge';
|
||||
|
||||
const DEFAULT_NUM_OF_CONFIGURED_SCENES = 5;
|
||||
const DEFAULT_TRIGGER_TIMEOUT = 10;
|
||||
@@ -59,7 +59,6 @@ export class DeviceConfig {
|
||||
export interface AccessoryState {
|
||||
numberConfiguredScenes: number;
|
||||
triggerTimeout: number;
|
||||
//nextSceneToTrigger: number;
|
||||
triggerTimeoutManuallyChanged: boolean;
|
||||
}
|
||||
|
||||
@@ -67,7 +66,6 @@ export function initializeAccessoryState(initConfig: PluginDeviceConfig | Access
|
||||
return {
|
||||
numberConfiguredScenes: initConfig.numberConfiguredScenes || DEFAULT_NUM_OF_CONFIGURED_SCENES,
|
||||
triggerTimeout: initConfig.triggerTimeout || DEFAULT_TRIGGER_TIMEOUT,
|
||||
//nextSceneToTrigger: 0,
|
||||
triggerTimeoutManuallyChanged: false,
|
||||
};
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { API } from 'homebridge';
|
||||
|
||||
import { PLATFORM_NAME } from './settings';
|
||||
import { MultiTapSwitchPlatform } from './platform';
|
||||
import MultiTapSwitchPlatform from './platform';
|
||||
|
||||
/**
|
||||
* This method registers the platform with Homebridge
|
||||
|
||||
+10
-28
@@ -4,24 +4,14 @@ import { PLATFORM_NAME, PLUGIN_NAME } from './settings';
|
||||
import { DeviceAccessory } from './platformAccessory';
|
||||
|
||||
// Necessary definitions for custom characteristics!
|
||||
import ConfiguredScenes from './types/characteristicConfiguredScenes';
|
||||
let IConfiguredScenes;
|
||||
import {initializeAccessoryState, PluginConfig} from './config';
|
||||
let ITriggerTimeout;
|
||||
import TriggerTimeout from './types/characteristicTimeout';
|
||||
import { initializeAccessoryState, PluginConfig } from './config';
|
||||
|
||||
/**
|
||||
* HomebridgePlatform
|
||||
*/
|
||||
export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
public readonly Service: typeof Service = this.api.hap.Service;
|
||||
public readonly Characteristic:
|
||||
typeof Characteristic &
|
||||
typeof IConfiguredScenes &
|
||||
typeof ITriggerTimeout;
|
||||
|
||||
private readonly CharacteristicConfiguredScenes;
|
||||
private readonly CharacteristicTriggerTimeout;
|
||||
class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
public readonly Service: typeof Service;
|
||||
public readonly Characteristic: typeof Characteristic;
|
||||
|
||||
// Track restored cached accessories
|
||||
public readonly accessories: PlatformAccessory[] = [];
|
||||
@@ -40,25 +30,15 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
public readonly api: API,
|
||||
) {
|
||||
this.Config = new PluginConfig(this.config);
|
||||
this.Service = api.hap.Service;
|
||||
this.Characteristic = api.hap.Characteristic;
|
||||
|
||||
this.log.debug('Finished initializing platform:', this.Config.Name);
|
||||
|
||||
this.CharacteristicConfiguredScenes = ConfiguredScenes(this.api);
|
||||
IConfiguredScenes = this.CharacteristicConfiguredScenes;
|
||||
this.CharacteristicTriggerTimeout = TriggerTimeout(this.api);
|
||||
ITriggerTimeout = this.CharacteristicTriggerTimeout;
|
||||
|
||||
this.api.on('didFinishLaunching', () => {
|
||||
log.debug('Discover/Register Devices ...');
|
||||
this.discoverDevices();
|
||||
});
|
||||
|
||||
this.Characteristic = Object.defineProperty(this.api.hap.Characteristic,
|
||||
'ConfiguredScenes',
|
||||
{value: this.CharacteristicConfiguredScenes});
|
||||
this.Characteristic = Object.defineProperty(this.api.hap.Characteristic,
|
||||
'TriggerTimeout',
|
||||
{value: this.CharacteristicTriggerTimeout});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +90,7 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
|
||||
// Create the accessory handler for the restored accessory
|
||||
// This is imported from `platformAccessory.ts`
|
||||
new DeviceAccessory(this, existingAccessory);
|
||||
new DeviceAccessory(this, this.api, existingAccessory);
|
||||
|
||||
knownUuids.push(uuid);
|
||||
} else {
|
||||
@@ -128,7 +108,7 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
|
||||
// Create the accessory handler for the new accessory
|
||||
// This is imported from `platformAccessory.ts`
|
||||
new DeviceAccessory(this, accessory);
|
||||
new DeviceAccessory(this, this.api, accessory);
|
||||
|
||||
// link the accessory to your platform
|
||||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
||||
@@ -144,3 +124,5 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default MultiTapSwitchPlatform;
|
||||
+78
-29
@@ -1,8 +1,11 @@
|
||||
import {CharacteristicValue, PlatformAccessory, Service} from 'homebridge';
|
||||
import {MultiTapSwitchPlatform} from './platform';
|
||||
import {AccessoryState, DeviceConfig} from './config';
|
||||
import {Logging} from './helper/logger';
|
||||
import {VERSION} from './settings';
|
||||
import { CharacteristicValue, PlatformAccessory, Service, API } from 'homebridge';
|
||||
import MultiTapSwitchPlatform from './platform';
|
||||
import { AccessoryState, DeviceConfig } from './config';
|
||||
import { Logging } from './helper/logger';
|
||||
import { VERSION } from './settings';
|
||||
import { attachCharacteristic_ConfiguredScenes } from './types/characteristicConfiguredScenes';
|
||||
import { attachCharacteristic_TriggerTimeout } from './types/characteristicTimeout';
|
||||
import { attachCharacteristic_CurrentScene } from './types/characteristicCurrentScene';
|
||||
|
||||
/**
|
||||
* Platform Accessory
|
||||
@@ -11,7 +14,30 @@ export class DeviceAccessory {
|
||||
private serviceIn: Service;
|
||||
private serviceOut: Service;
|
||||
|
||||
private readonly singleButtonEvents = {
|
||||
private readonly singleButtonEvents;
|
||||
|
||||
private readonly State: AccessoryState;
|
||||
private readonly Config: DeviceConfig;
|
||||
|
||||
private readonly TriggerButtons: Service[] = [];
|
||||
private SwitchResetTimer: NodeJS.Timeout | undefined;
|
||||
private SwitchOn: boolean = false;
|
||||
private NextItemToTrigger: number = 0;
|
||||
|
||||
private Log: Logging;
|
||||
|
||||
/**
|
||||
* Construct the accessory services
|
||||
* @param platform Parent Homebridge platform
|
||||
* @param api Parent platform API
|
||||
* @param accessory Accessory to which these services will be attached
|
||||
*/
|
||||
constructor(
|
||||
private readonly platform: MultiTapSwitchPlatform,
|
||||
private readonly api: API,
|
||||
private readonly accessory: PlatformAccessory,
|
||||
) {
|
||||
this.singleButtonEvents = {
|
||||
minValue: this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
||||
maxValue: this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
||||
validValues: [
|
||||
@@ -19,25 +45,6 @@ export class DeviceAccessory {
|
||||
],
|
||||
};
|
||||
|
||||
private readonly State: AccessoryState;
|
||||
private readonly Config: DeviceConfig;
|
||||
|
||||
private readonly TriggerButtons: Service[] = [];
|
||||
private SwitchResetTimer: NodeJS.Timeout | undefined;
|
||||
private SwitchOn = false;
|
||||
private NextItemToTrigger = 0;
|
||||
|
||||
private Log: Logging;
|
||||
|
||||
/**
|
||||
* Construct the accessory services
|
||||
* @param platform Parent Homebridge platform
|
||||
* @param accessory Accessory to which these services will be attached
|
||||
*/
|
||||
constructor(
|
||||
private readonly platform: MultiTapSwitchPlatform,
|
||||
private readonly accessory: PlatformAccessory,
|
||||
) {
|
||||
this.Config = new DeviceConfig(accessory.context.config);
|
||||
this.State = this.accessory.context.persistent;
|
||||
|
||||
@@ -69,8 +76,7 @@ export class DeviceAccessory {
|
||||
if (this.State.numberConfiguredScenes > this.Config.NumOfScenes()) {
|
||||
this.State.numberConfiguredScenes = this.Config.NumOfScenes();
|
||||
}
|
||||
(this.serviceIn.getCharacteristic(this.platform.Characteristic.ConfiguredScenes)
|
||||
|| this.serviceIn.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredScenes))
|
||||
attachCharacteristic_ConfiguredScenes(this.serviceIn, this.api)
|
||||
.setProps({
|
||||
'minValue': 1,
|
||||
'maxValue': this.Config.NumOfScenes(),
|
||||
@@ -87,8 +93,7 @@ export class DeviceAccessory {
|
||||
this.Log.debug('Current Trigger Timeout [' + this.State.triggerTimeout + '] differs from configured value [' +
|
||||
this.Config.TriggerTimeout() + ']. It won\'t be updated until it\'s equal again.');
|
||||
}
|
||||
(this.serviceIn.getCharacteristic(this.platform.Characteristic.TriggerTimeout)
|
||||
|| this.serviceIn.addOptionalCharacteristic(this.platform.Characteristic.TriggerTimeout))
|
||||
attachCharacteristic_TriggerTimeout(this.serviceIn, this.api)
|
||||
.setProps({
|
||||
'minValue': 0,
|
||||
'maxValue': 30,
|
||||
@@ -98,6 +103,17 @@ export class DeviceAccessory {
|
||||
.onGet(this.getTriggerTimeout.bind(this))
|
||||
.updateValue(this.State.triggerTimeout);
|
||||
|
||||
// Register handlers for the CurrentScene characteristic & restore previous value
|
||||
attachCharacteristic_CurrentScene(this.serviceIn, this.api)
|
||||
.setProps({
|
||||
'minValue': 1,
|
||||
'maxValue': this.Config.NumOfScenes(),
|
||||
'minStep': 1,
|
||||
})
|
||||
.onSet(this.setCurrentScene.bind(this))
|
||||
.onGet(this.getCurrentScene.bind(this))
|
||||
.updateValue(this.NextItemToTrigger);
|
||||
|
||||
// Set the service name, this is what is displayed as the default name on the Home app
|
||||
this.serviceIn.setCharacteristic(this.platform.Characteristic.Name, this.Config.Name());
|
||||
|
||||
@@ -277,4 +293,37 @@ export class DeviceAccessory {
|
||||
this.Log.debug('Get Trigger Timeout ->', triggerTimeout);
|
||||
return triggerTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of active switches.
|
||||
* The final value is limited to the maximum configured number of programmable switches.
|
||||
* @param value Number of active switches
|
||||
*/
|
||||
async setCurrentScene(value: CharacteristicValue) {
|
||||
let currentScene = value as number;
|
||||
|
||||
if ((currentScene > 0) && (currentScene <= this.Config.NumOfScenes())) {
|
||||
this.Log.log('Set current active scene ->', currentScene);
|
||||
} else {
|
||||
this.Log.warn(
|
||||
'Set current scene ->', currentScene, '-> Out-of-Range / Value must be between 1 and', this.Config.NumOfScenes());
|
||||
if (currentScene > this.Config.NumOfScenes()) {
|
||||
currentScene = this.Config.NumOfScenes();
|
||||
} else {
|
||||
currentScene = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// value must be corrected by one, because it's used as array index
|
||||
this.NextItemToTrigger = currentScene - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report number of active switches back to HomeKit (for visualization)
|
||||
*/
|
||||
async getCurrentScene(): Promise<CharacteristicValue> {
|
||||
const currentScene = this.NextItemToTrigger + 1;
|
||||
this.Log.debug('Get Number of current scene ->', currentScene);
|
||||
return currentScene;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const package_config = require('../package.json');
|
||||
import package_config from '../package.json';
|
||||
|
||||
/**
|
||||
* This is the name of the platform that users will use to register the plugin in the Homebridge config.json
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import { Formats, Perms } from 'homebridge';
|
||||
import { API, Characteristic, Formats, Perms, Service } from 'homebridge';
|
||||
|
||||
export = (homebridge) => {
|
||||
const CustomCharacteristic = homebridge.hap.Characteristic;
|
||||
const characteristicUUID = 'A8E3F4DF-5E5D-6A7F-8FA7-A22FA5AE9F53';
|
||||
const DISPLAY_NAME = 'Configured Scenes';
|
||||
const UUID = 'A8E3F4DF-5E5D-6A7F-8FA7-A22FA5AE9F53';
|
||||
|
||||
return class ConfiguredScenes extends CustomCharacteristic {
|
||||
public static readonly UUID: string = characteristicUUID;
|
||||
export function attachCharacteristic_ConfiguredScenes(target: Service, api: API): Characteristic {
|
||||
let result: Characteristic;
|
||||
|
||||
constructor() {
|
||||
super('Configured Scenes', ConfiguredScenes.UUID, {
|
||||
if (target.testCharacteristic(DISPLAY_NAME)) {
|
||||
result = target.getCharacteristic(DISPLAY_NAME)!; // Already tested it exists
|
||||
} else {
|
||||
result = target.addCharacteristic(new api.hap.Characteristic(DISPLAY_NAME, UUID, {
|
||||
format: Formats.UINT8,
|
||||
//unit: '',
|
||||
minValue: 0,
|
||||
maxValue: 0,
|
||||
minStep: 1,
|
||||
perms: [Perms.PAIRED_WRITE, Perms.PAIRED_READ, Perms.NOTIFY],
|
||||
});
|
||||
this.value = this.getDefaultValue();
|
||||
}));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { API, Characteristic, Formats, Perms, Service } from 'homebridge';
|
||||
|
||||
const DISPLAY_NAME = 'Current Scene';
|
||||
const UUID = '290E9D33-0EFC-4640-891E-CC25AAD740EA';
|
||||
|
||||
export function attachCharacteristic_CurrentScene(target: Service, api: API): Characteristic {
|
||||
let result: Characteristic;
|
||||
|
||||
if (target.testCharacteristic(DISPLAY_NAME)) {
|
||||
result = target.getCharacteristic(DISPLAY_NAME)!; // Already tested it exists
|
||||
} else {
|
||||
result = target.addCharacteristic(new api.hap.Characteristic(DISPLAY_NAME, UUID, {
|
||||
format: Formats.UINT8,
|
||||
//unit: '',
|
||||
minValue: 0,
|
||||
maxValue: 0,
|
||||
minStep: 1,
|
||||
perms: [Perms.PAIRED_WRITE, Perms.PAIRED_READ, Perms.NOTIFY],
|
||||
}));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
import { Formats, Perms } from 'homebridge';
|
||||
import { API, Characteristic, Formats, Perms, Service } from 'homebridge';
|
||||
|
||||
export = (homebridge) => {
|
||||
const CustomCharacteristic = homebridge.hap.Characteristic;
|
||||
const characteristicUUID = 'E2C19A02-1D2F-F592-A2BF-BF920014FB18';
|
||||
const DISPLAY_NAME = 'Trigger Timeout';
|
||||
const UUID = 'E2C19A02-1D2F-F592-A2BF-BF920014FB18';
|
||||
|
||||
return class TriggerTimeout extends CustomCharacteristic {
|
||||
public static readonly UUID: string = characteristicUUID;
|
||||
export function attachCharacteristic_TriggerTimeout(target: Service, api: API): Characteristic {
|
||||
let result: Characteristic;
|
||||
|
||||
constructor() {
|
||||
super('Trigger Timeout', TriggerTimeout.UUID, {
|
||||
if (target.testCharacteristic(DISPLAY_NAME)) {
|
||||
result = target.getCharacteristic(DISPLAY_NAME)!; // Already tested it exists
|
||||
} else {
|
||||
result = target.addCharacteristic(new api.hap.Characteristic(DISPLAY_NAME, UUID, {
|
||||
format: Formats.UINT16,
|
||||
//unit: '',
|
||||
minValue: 0,
|
||||
maxValue: 60,
|
||||
minStep: 1,
|
||||
perms: [Perms.PAIRED_WRITE, Perms.PAIRED_READ, Perms.NOTIFY],
|
||||
});
|
||||
this.value = this.getDefaultValue();
|
||||
}));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"username": "test",
|
||||
"name": "test",
|
||||
"hashedPassword": "df121e72b850a058bd68f3d05b1f94dc985821a3885b5da38e263654f29843f98bb6d8e594f6042ff871a424602a9bff50dffa97f258bdc1dca4c79e87bac20c",
|
||||
"salt": "64085e70da64670349f042d4c3d3cac75b20233ffeb71db68399973f60da077d",
|
||||
"admin": true
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"bridge": {
|
||||
"name": "HomebridgeTest",
|
||||
"username": "CC:22:3D:E3:CE:30",
|
||||
"manufacturer": "homebridge.io",
|
||||
"model": "homebridge",
|
||||
"port": 51826,
|
||||
"pin": "031-45-154"
|
||||
},
|
||||
|
||||
"description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",
|
||||
"ports": {
|
||||
"start": 52100,
|
||||
"end": 52150,
|
||||
"comment": "This section is used to control the range of ports that separate accessory (like camera or television) should be bind to."
|
||||
},
|
||||
"accessories": [
|
||||
],
|
||||
|
||||
"platforms": [
|
||||
{
|
||||
"platform" : "MultiTapSwitch",
|
||||
"name" : "MTS",
|
||||
"devices": [
|
||||
{
|
||||
"name": "MTS1",
|
||||
"numberConfiguredScenes": 5,
|
||||
"triggerTimeout": 10,
|
||||
"resetAfterSwitchOff": false,
|
||||
"logging": true
|
||||
},
|
||||
{
|
||||
"name": "MTS2",
|
||||
"numberConfiguredScenes": 5,
|
||||
"triggerTimeout": 10,
|
||||
"resetAfterSwitchOff": false,
|
||||
"logging": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+13
-12
@@ -1,23 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2018", // ~node10
|
||||
"module": "commonjs",
|
||||
"target": "ES2022",
|
||||
"lib": [
|
||||
"es2015",
|
||||
"es2016",
|
||||
"es2017",
|
||||
"es2018"
|
||||
"DOM",
|
||||
"ES2022"
|
||||
],
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"rootDir": "src",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": false
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": [
|
||||
"eslint.config.js",
|
||||
"homebridge-ui",
|
||||
"src/"
|
||||
],
|
||||
"exclude": [
|
||||
|
||||
Reference in new issue
Block a user