Skip to content

Commit

Permalink
1.4.2 Resolve issue with customCharacteristics not loading from file (#…
Browse files Browse the repository at this point in the history
…442)

### Fixed

- Resolve issue with customCharacteristics not loading from file
- Fixed publish process
  • Loading branch information
Shaquu authored Oct 5, 2021
1 parent 4833319 commit 740c93d
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 89 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.2]

### Fixed

- Resolve issue with customCharacteristics not loading from file
- Fixed publish process

## [1.4.1]

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-homekit-bridged",
"version": "1.4.1",
"version": "1.4.2",
"description": "Node-RED nodes to simulate Apple HomeKit devices.",
"main": "build/nodes/nrchkb.js",
"scripts": {
Expand Down Expand Up @@ -61,8 +61,8 @@
"@types/node-red": "^1.1.1",
"@types/semver": "^7.3.8",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/HAPHostNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ module.exports = (RED: NodeAPI, hostType: HostType) => {
}
}

self.accessoryCategory = ((self.hostType == HostType.BRIDGE
self.accessoryCategory = (self.hostType == HostType.BRIDGE
? HapCategories.BRIDGE
: self.config.accessoryCategory) as unknown) as Categories
: self.config.accessoryCategory) as unknown as Categories

self.published = false

Expand Down
22 changes: 14 additions & 8 deletions src/lib/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export class Storage {

static save(
type: StorageType,
key: string,
key: string | undefined,
value: unknown
): Promise<storage.WriteFileResult> {
Storage.log.trace(`Saving ${type}, ${key}:${value}`)
return storage.set(`${type}-${key}`, value)
const itemName = key ? `${type}-${key}` : type
Storage.log.trace(`Saving ${itemName}:${value}`)
return storage.set(itemName, value)
}

static saveCallback(eventCallback: EventCallback, ttl = 10000) {
Expand All @@ -74,7 +75,11 @@ export class Storage {
static saveCustomCharacteristics(
value: unknown
): Promise<storage.WriteFileResult> {
return Storage.save(StorageType.CUSTOM_CHARACTERISTICS, '', value)
return Storage.save(
StorageType.CUSTOM_CHARACTERISTICS,
undefined,
value
)
}

static saveService(
Expand All @@ -98,9 +103,10 @@ export class Storage {
return Storage.save(StorageType.HOST, key, serializedHost)
}

static load(type: StorageType, key: string): Promise<any> {
Storage.log.trace(`Loading ${type}, ${key}`)
return storage.get(`${type}-${key}`)
static load(type: StorageType, key?: string): Promise<any> {
const itemName = key ? `${type}-${key}` : type
Storage.log.trace(`Loading ${itemName}`)
return storage.get(itemName)
}

static loadCallback(key: string): EventCallback | undefined {
Expand All @@ -115,7 +121,7 @@ export class Storage {
}

static loadCustomCharacteristics(): Promise<any> {
return Storage.load(StorageType.CUSTOM_CHARACTERISTICS, '')
return Storage.load(StorageType.CUSTOM_CHARACTERISTICS)
}

static loadService(key: string): Promise<SerializedService> {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ module.exports = function (RED: NodeAPI) {
const getCustomCharacteristics = () => {
return Storage.loadCustomCharacteristics()
.then((value) => {
log.trace(`loadCustomCharacteristics()`)
log.trace(value)

if (Array.isArray(value)) {
return value
} else {
Expand Down Expand Up @@ -342,7 +345,7 @@ module.exports = function (RED: NodeAPI) {
.sort()
.filter((x) => parseInt(x) >= 0)
.forEach((key) => {
const keyNumber = (key as unknown) as number
const keyNumber = key as unknown as number
accessoryCategoriesData[keyNumber] = HapCategories[keyNumber]
})

Expand Down
4 changes: 2 additions & 2 deletions src/test/lib/HAPBridgeNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ describe('HAPHostNode', function () {
})

it('null string macify should fail', function (done) {
const stringToMacify = (null as unknown) as string
const stringToMacify = null as unknown as string
should.throws(() => {
HAPHostNode.macify(stringToMacify)
}, 'nodeId cannot be empty in macify process')
done()
})

it('undefined string macify should fail', function (done) {
const stringToMacify = (undefined as unknown) as string
const stringToMacify = undefined as unknown as string
should.throws(() => {
HAPHostNode.macify(stringToMacify)
}, 'nodeId cannot be empty in macify process')
Expand Down
Loading

0 comments on commit 740c93d

Please sign in to comment.