Skip to content
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

Beta 0.2.8 #108

Merged
merged 10 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
71 changes: 0 additions & 71 deletions .github/workflows/Build and Publish.yml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/Build_and_Publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: "Build and Publish"

on:
push:
branches: [beta-*.*.*, beta]
workflow_dispatch:

jobs:
get_tags:
runs-on: ubuntu-latest

steps:
# checkout repo
- uses: actions/checkout@v4

# get branch / tag name
- name: Get Branch / Tag Name
id: get_branch
run: |
export BRANCH_NAME=$(if [[ ${GITHUB_REF} =~ "refs/tags/" ]]; then echo ${GITHUB_REF/refs\/tags\//}; else echo ${GITHUB_REF/refs\/heads\//}; fi)
echo $BRANCH_NAME
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
# generate the image tag
- name: Get Image Tag
id: get_tag
run: |
export TARGET_IMAGE_TAG=$(if [ "${{ steps.get_branch.outputs.BRANCH_NAME }}" = "main" ]; then echo "main"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}" | awk -F- '{ print $1 }'; fi)
echo $TARGET_IMAGE_TAG
echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_OUTPUT
outputs:
BRANCH_NAME: ${{ steps.get_branch.outputs.BRANCH_NAME }}
TARGET_IMAGE_TAG: ${{ steps.get_tag.outputs.TARGET_IMAGE_TAG }}

publish_prod_release:
permissions:
id-token: write
needs: get_tags
name: Publish Release Version
if: ${{ needs.get_tags.outputs.BRANCH_NAME == 'main' }}
uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
with:
install_cmd: npm ci
secrets:
npm_auth_token: ${{ secrets.npm_token }}

publish_test:
permissions:
id-token: write
needs: get_tags
name: Publish Test Version - ${{ needs.get_tags.outputs.BRANCH_NAME }}
if: ${{ needs.get_tags.outputs.BRANCH_NAME != 'main' }}
uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
with:
tag: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
dynamically_adjust_version: true
npm_version_command: "pre"
pre_id: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
secrets:
npm_auth_token: ${{ secrets.npm_token }}

publish_github_release:
needs: [publish_prod_release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
name: Release ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
generate_release_notes: true
draft: false
prerelease: false
23 changes: 18 additions & 5 deletions HAPNodeJSClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ axiosRetry(axios, { retries: 3 });
var discovered = [];
var mdnsCache = {};
var populateCache = false;
var populateCacheTimeout;

var filter = false;
var pins = {};
var type = 'hap';

module.exports = {
HAPNodeJSClient: HAPNodeJSClient
Expand Down Expand Up @@ -47,6 +49,7 @@ function HAPNodeJSClient(options) {
this.timeout = options.timeout || 20;
this.reqTimeout = options.reqTimeout || 7000;
this.RegisterPin('default', options.pin || '031-45-154');
type = options.type || 'hap';
filter = options.filter || false;
if (this.debug) {
let debugEnable = require('debug');
Expand All @@ -65,7 +68,7 @@ function HAPNodeJSClient(options) {
this.eventRegistry = {};
_discovery.call(this);
this._eventBus = new EventEmitter();
setInterval(_discovery.bind(this), this.refresh * 1000);
this.discoveryTimer = setInterval(_discovery.bind(this), this.refresh * 1000);

/**
* HomeKit Accessory Characteristic event pass thru
Expand Down Expand Up @@ -154,7 +157,7 @@ function _populateCache(timeout, discovery, callback) {
populateCache = true;
// debug('_populateCache', new Error().stack);
var browser = bonjour.find({
type: 'hap'
type: (type ? type : 'hap')
}, function (result) {
if (result.txt) {
debug('HAP Device discovered', result.name, result.addresses);
Expand Down Expand Up @@ -192,7 +195,7 @@ function _populateCache(timeout, discovery, callback) {
debug('Unsupported device found, skipping', result.name);
}
});
setTimeout(function () {
populateCacheTimeout = setTimeout(function () {
// debug('Timeout:');
browser.stop();
populateCache = false;
Expand All @@ -212,6 +215,16 @@ function _findPinByKey(key) {
return pins[key] || pins['default'];
}

/**
* Destroy and shutdown HAPNodeJSClient - Used by testing
*/
HAPNodeJSClient.prototype.destroy = function() {
clearInterval(this.discoveryTimer);
clearInterval(populateCacheTimeout);
bonjour.destroy();
// this.monitorBridgeUpdates.destroy();
}

/**
* HAPNodeJSClient.prototype.RegisterPin - Register pin numbers ()
*
Expand Down Expand Up @@ -706,8 +719,8 @@ HAPNodeJSClient.prototype.HAPstatus = function (ipAddress, port, body, callback,
};

function _getAccessories(instance, callback) {
// debug('_getAccessories()', filter, instance.url + '/accessories');
if ((filter && filter === instance.host + ':' + instance.port) || !filter) {
// console.log('_getAccessories()', filter, instance.host + ':' + instance.port, filter.includes(instance.host + ':' + instance.port));
if ((filter && filter.includes(instance.host + ':' + instance.port)) || !filter) {
var host = instance.host + ':' + instance.port;

axios({
Expand Down
87 changes: 87 additions & 0 deletions HAPNodeJSClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,91 @@ describe("Incorrect PIN", () => {
});
});
});
});


describe.only("Filter", () => {

describe("Filter None", () => {

let homebridges;

beforeAll(() => {
var options = {
};
homebridges = new HAPNodeJSClient(options);
});

describe("Discover Accessories", () => {
test("Retrieve Accessories", done => {
console.log('This takes 20 seconds');
homebridges.on('Ready', function () {

homebridges.HAPaccessories(function (endPoints) {
// console.log("alexaDiscovery Single", endPoints, endPoints.length);
// console.log("Test Endpoint", JSON.stringify(endPoints.find(endpoint => endpoint.deviceID === testDeviceID).accessories, null, 2));
expect(endPoints.length).toBeGreaterThan(2);
done();
});
});
}, 21000);
});

});

describe("Filter Single", () => {

let homebridges;

beforeAll(() => {
var options = {
filter: "192.168.1.11:51551"
};
homebridges = new HAPNodeJSClient(options);
});

describe("Discover Accessories", () => {
test("Retrieve Accessories", done => {
console.log('This takes 20 seconds');
homebridges.on('Ready', function () {

homebridges.HAPaccessories(function (endPoints) {
// console.log("alexaDiscovery Single", endPoints, endPoints.length);
// console.log("Test Endpoint", JSON.stringify(endPoints.find(endpoint => endpoint.deviceID === testDeviceID).accessories, null, 2));
expect(endPoints.length).toEqual(1);
done();
});
});
}, 21000);
});

});

describe("Filter Dual", () => {

let homebridges;

beforeAll(() => {
var options = {
filter: "192.168.1.11:51551, 192.168.1.11:46047"
};
homebridges = new HAPNodeJSClient(options);
});

describe("Discover Accessories", () => {
test("Retrieve Accessories", done => {
console.log('This takes 20 seconds');
homebridges.on('Ready', function () {

homebridges.HAPaccessories(function (endPoints) {
// console.log("alexaDiscovery Dual", endPoints, endPoints.length);
// console.log("Test Endpoint", JSON.stringify(endPoints.find(endpoint => endpoint.deviceID === testDeviceID).accessories, null, 2));
expect(endPoints.length).toEqual(2);
done();
});
});
}, 21000);
});

});
});
Loading