Skip to content

Commit

Permalink
feat: Schema-Prep This works with all lower case, still sends Get/Set…
Browse files Browse the repository at this point in the history
… upper case
  • Loading branch information
ztalbot2000 committed Sep 25, 2021
1 parent 03b232a commit d376458
Show file tree
Hide file tree
Showing 32 changed files with 1,848 additions and 648 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"CMD4_ACC_TYPE_ENUM" : "readonly",
"CMD4_DEVICE_TYPE_ENUM" : "readonly",
"cleanStatesDir" : "readonly",
"accEnumIndexToC" : "readonly",
"devEnumIndexToC" : "readonly",
"fs" : "writeable",
"HomebridgeAPI" : "writeable",
"Logger" : "writeable",
Expand Down
285 changes: 153 additions & 132 deletions Cmd4Accessory.js

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions Cmd4Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ class Cmd4Platform
let lcKey = lcFirst( key );
if ( key == "UUID" )
{
lcKey = "UUID";
lcKey = "uuid";
} else
{
// warn now
if ( key.charAt( 0 ) === key.charAt( 0 ).toUpperCase( ) )
{
this.log.warn( `The config.json Platform key: ${ key } is Capitalized. All definitions, except CONSTANTS, in the near future will start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
this.log.warn( `The config.json Platform key: ${ key } is Capitalized. All keys in the near future will ALWAYS start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
}
}

Expand Down Expand Up @@ -416,19 +416,24 @@ class Cmd4Platform
// generate a unique id for the accessory this should be generated from
// something globally unique, but constant, for example, the device serial
// number or MAC address.
let UUID = getAccessoryUUID( device, this.api.hap.uuid );
let uuid = getAccessoryUUID( device, this.api.hap.uuid );

// See if an accessory with the same UUID has already been registered and
// restored from the cached devices we stored in the `configureAccessory`
// method above
const existingAccessory = this.toBeRestoredPlatforms.find(accessory => accessory.UUID === UUID);

// NOTE: HOMEBRIDGE EXAMPLES HAVE THIS AS UPPERCASE UUID.
// lower case uuid will not be found.
const existingAccessory = this.toBeRestoredPlatforms.find(accessory => accessory.UUID === uuid);

if (existingAccessory)
{
// NOTE: HOMEBRIDGE EXAMPLES HAVE THIS AS UPPERCASE UUID.
// lower case uuid will not be found.
let duplicatePlatformAccessory = this.createdCmd4Platforms.find(accessory => accessory.UUID === existingAccessory.UUID);
if ( duplicatePlatformAccessory )
{
this.log( chalk.red( `Error duplicate platform accessory: ${ duplicatePlatformAccessory.name } UUID:${ duplicatePlatformAccessory.UUID }` ) );
this.log( chalk.red( `Error duplicate platform accessory: ${ duplicatePlatformAccessory.name } uuid:${ duplicatePlatformAccessory.UUID }` ) );
// Next in for.Each object iteration
return;
}
Expand Down Expand Up @@ -516,8 +521,8 @@ class Cmd4Platform
// Create the new PlatformAccessory
if ( device.category == undefined )
{
if ( cmd4Dbg ) this.log.debug( `Step 1. platformAccessory = new platformAccessory( ${ displayName }, ${ UUID } )` );
platform = new this.api.platformAccessory( displayName, UUID );
if ( cmd4Dbg ) this.log.debug( `Step 1. platformAccessory = new platformAccessory( ${ displayName }, ${ uuid } )` );
platform = new this.api.platformAccessory( displayName, uuid );

} else
{
Expand All @@ -528,9 +533,9 @@ class Cmd4Platform
if ( ! category )
throw new Error( `Category specified: ${ device.category } is not a valid homebridge category.` );

if ( cmd4Dbg ) this.log.debug( `Step 1. platformAccessory = new platformAccessory( ${ displayName }, ${ UUID }, ${ category } )` );
if ( cmd4Dbg ) this.log.debug( `Step 1. platformAccessory = new platformAccessory( ${ displayName }, ${ uuid }, ${ category } )` );

platform = new this.api.platformAccessory( displayName, UUID, category );
platform = new this.api.platformAccessory( displayName, uuid, category );
}

platform.Service = this.Service;
Expand Down
14 changes: 7 additions & 7 deletions Cmd4PriorityPollingQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Cmd4PriorityPollingQueue
let self = this;

// Save the value to cache. The set will come later
self.cmd4Storage.setStoredValueForCharacteristic( characteristicString, value );
self.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
callback( 0 );

let newEntry = { [ constants.IS_SET_lv ]: true, [ constants.ACCESSORY_lv ]: self, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.CALLBACK_lv ]: callback, [ constants.VALUE_lv ]: value };
Expand All @@ -90,7 +90,7 @@ class Cmd4PriorityPollingQueue
} else {

// Make sure that this is the latest "Set" of this entry
let index = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.UUID == self.UUID && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
let index = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.uuid == self.uuid && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );

if ( index == -1 )
{
Expand Down Expand Up @@ -121,7 +121,7 @@ class Cmd4PriorityPollingQueue
let self = this;

// return the cached value
let storedValue = self.cmd4Storage.getStoredValueForCharacteristic( characteristicString );
let storedValue = self.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
callback( 0, storedValue );

// When the value is returned, it will update homebridge
Expand Down Expand Up @@ -824,10 +824,10 @@ class Cmd4PriorityPollingQueue
if ( staggeredDelayIndex++ >= staggeredDelaysLength )
staggeredDelayIndex = 0;

if ( lastAccessoryUUID != entry.accessory.UUID )
if ( lastAccessoryUUID != entry.accessory.uuid )
staggeredDelayIndex = 0;

lastAccessoryUUID = entry.accessory.UUID;
lastAccessoryUUID = entry.accessory.uuid;

delay += staggeredDelays[ staggeredDelayIndex ];

Expand Down Expand Up @@ -877,7 +877,7 @@ class Cmd4PriorityPollingQueue
isCharacteristicPolled( accTypeEnumIndex, queue, accessory )
{
if ( queue.lowPriorityQueue.filter(
entry => entry.accessory.UUID == accessory.UUID &&
entry => entry.accessory.uuid == accessory.uuid &&
entry.accTypeEnumIndex == accTypeEnumIndex
).length == 0 )
{
Expand Down Expand Up @@ -927,7 +927,7 @@ var parseAddQueueTypes = function ( log, entrys )
// warn now
if ( key.charAt( 0 ) === key.charAt( 0 ).toUpperCase( ) )
{
log.warn( `The config.json queueTypes key: ${ key } is Capitalized. All definitions, except CONSTANTS, in the near future will start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
log.warn( `The config.json queueTypes key: ${ key } is Capitalized. All keys in the near future will ALWAYS start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
}

let value = entry[ key ];
Expand Down
8 changes: 4 additions & 4 deletions Extras/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@
"ozoneDensity": 50,
"nitrogenDioxideDensity": 50,
"sulphurDioxideDensity": 50,
"pM2_5Density": 50,
"pM10Density": 50,
"vOCDensity": 50,
"pm2_5Density": 50,
"pm10Density": 50,
"vocDensity": 50,
"statusActive": "TRUE",
"statusFault": "NO_FAULT",
"statusTampered": "NOT_TAMPERED",
Expand Down Expand Up @@ -784,7 +784,7 @@
{
"type": "WiFiSatellite",
"displayName": "My_WiFiSatellite",
"wiFiSatelliteStatus": "NOT_CONNECTED"
"wifiSatelliteStatus": "NOT_CONNECTED"
}
]
}
Expand Down
Loading

0 comments on commit d376458

Please sign in to comment.