8000 Esm 2.1.0 - Change tracking by NorthernMan54 · Pull Request #12 · homebridge/hap-client · GitHub
[go: up one dir, main page]

Skip to content

Esm 2.1.0 - Change tracking #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add destroy for testing purposes
  • Loading branch information
NorthernMan54 committed Oct 28, 2024
commit 81713fb6c832141abe9d3ca2224d4745e8911a03
99 changes: 54 additions & 45 deletions eslint.config.js
8000
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
import antfu from '@antfu/eslint-config'

export default antfu(
{
ignores: ['dist', 'docs'],
jsx: false,
typescript: true,
formatters: {
markdown: true,
},
rules: {
'curly': ['error', 'multi-line'],
'import/extensions': ['error', 'ignorePackages'],
'import/order': 0,
'jsdoc/check-alignment': 'error',
'jsdoc/check-line-alignment': 'error',
'no-undef': 'error',
'perfectionist/sort-exports': 'error',
'perfectionist/sort-imports': [
'error',
{
groups: [
'builtin-type',
'external-type',
'internal-type',
['parent-type', 'sibling-type', 'index-type'],
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'object',
'unknown',
],
order: 'asc',
type: 'natural',
},
],
'perfectionist/sort-named-exports': 'error',
'perfectionist/sort-named-imports': 'error',
'sort-imports': 0,
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'style/quote-props': ['error', 'consistent-as-needed'],
'test/no-only-tests': 'error',
'unicorn/no-useless-spread': 'error',
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
},
export default antfu({
ignores: ['dist', 'docs'],
jsx: false,
typescript: true,
formatters: {
markdown: true,
},
)
rules: {
'curly': ['error', 'multi-line'],
'import/extensions': ['error', 'ignorePackages'],
'import/order': 0,
'jsdoc/check-alignment': 'error',
'jsdoc/check-line-alignment': 'error',
'no-undef': 'off', // Turn off no-undef for TypeScript, handled by TS itself
'perfectionist/sort-exports': 'error',
'perfectionist/sort-imports': [
'error',
{
groups: [
'builtin-type',
'external-type',
'internal-type',
['parent-type', 'sibling-type', 'index-type'],
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'object',
'unknown',
],
order: 'asc',
type: 'natural',
},
],
'perfectionist/sort-named-exports': 'error',
'perfectionist/sort-named-imports': 'error',
'sort-imports': 0,
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'style/quote-props': ['error', 'consistent-as-needed'],
'test/no-only-tests': 'error',
'unicorn/no-useless-spread': 'error',
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
},
overrides: [
{
files: ['*.ts', '*.tsx'], // Apply to TypeScript files only
env: {
node: true, // Enables Node.js global variables and type definitions
},
parserOptions: {
project: './tsconfig.json', // Directs ESLint to use your TypeScript config
},
},
],
})
11 changes: 5 additions & 6 deletions package-lock.json
8000

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"gen": "node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/gen-hap-types.ts",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm run lint && npm run build"
"prepublishOnly": "npm run lint && npm run build",
"test": "echo \"Error: no test specified\" && exit 0"
},
"dependencies": {
"axios": "1.7.7",
Expand All @@ -50,7 +51,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "^3.0.0",
"@types/node": "^22.5.2",
"@types/node": "^22.8.2",
"@types/source-map-support": "^0.5.10",
"eslint": "^9.9.1",
"eslint-plugin-format": "^0.1.2",
Expand Down
22 changes: 20 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class HapClient extends EventEmitter {
Characteristics.Name,
]

private resetInstancePoolTimeout: NodeJS.Timeout | undefined = undefined
private startDiscoveryTimeout: NodeJS.Timeout | undefined = undefined

constructor(opts: {
pin: string
logger?: any
Expand Down Expand Up @@ -69,7 +72,7 @@ export class HapClient extends EventEmitter {

this.instances = []

setTimeout(() => {
this.resetInstancePoolTimeout = setTimeout(() => {
this.refreshInstances()
}, 6000)
}
Expand All @@ -85,6 +88,21 @@ export class HapClient extends EventEmitter {
}
}

/**
* Destroy the HapClient instance, used for testing
*/
public destroy() {
this.browser?.stop()

this.discoveryInProgress = false
if (this.resetInstancePoolTimeout) {
clearTimeout(this.resetInstancePoolTimeout)
}
if (this.startDiscoveryTimeout) {
clearTimeout(this.startDiscoveryTimeout)
}
}

private async startDiscovery() {
this.discoveryInProgress = true

Expand All @@ -97,7 +115,7 @@ export class HapClient extends EventEmitter {
this.debug(`[HapClient] Discovery :: Started`)

// stop discovery after 20 seconds
setTimeout(() => {
this.startDiscoveryTimeout = setTimeout(() => {
this.browser?.stop()
this.debug(`[HapClient] Discovery :: Ended`)
this.discoveryInProgress = false
Expand Down
Loading
0