diff --git a/js/extension.js b/js/extension.js index e7c4282..c2bbffe 100644 --- a/js/extension.js +++ b/js/extension.js @@ -27,11 +27,11 @@ this.pin_code = ""; - + /* API.getThings().then((things) => { console.log('Homebridge:API: things: ', things); }); - /* + API.getThing('energyuse').then((thing) => { console.log('Homebridge:API: thing: ', thing); }); @@ -260,7 +260,7 @@ // re-create the interval that checks if Homebridge has started this.interval = setInterval( () => { - console.log("reset interval timer"); + //console.log("reset interval timer"); this.get_init_data(); },5000); @@ -1037,7 +1037,7 @@ // Scan for all potential Homekit accessory types this thing could be shared as let possible_accessories = {}; - //if(thing_id.indexOf("z2m-0x086bd7fffe59a948") != -1){ + //if(thing_id.indexOf("z2m-0x086") != -1){ possible_accessories = this.find_accessory(thing_id); if(Object.keys(possible_accessories).length == 0){ //console.warn("device had no potential homekit abilities. Skipping: ", thing_id); @@ -1188,16 +1188,6 @@ find_accessory(thing_id){ - // accessory mapping of minimally required properties/services - /* - const ac_map = {"light":{"required":"on_off","optional":"brightness"}, - "switch"{"required":"on_off"}, - } - */ - //const ac_map = {"light":{"required":"on_off","optional":"brightness"}, - // "switch"{"required":"on_off"}, - //} - const ac_map = [ // Temperature sensor @@ -1804,66 +1794,10 @@ let potentials = {}; let thing_title = this.all_things[i]['title'] - console.log("\n\n\n\n\n=\n==\n==="); - console.log("thing title: ", thing_title); - - - /* - - { - "homekit_type":"airQualitySensor", - "webthings_type":["AirQualitySensor"], - "preference_score":90, - "required": - [ - { - "property_name":"quality", - "config_names":["getAirQuality"], - "required_variable":"enum", - "extra_attributes":{"targetAirPurifierStateValues":["unknown","excellent","good","poor","moderate","unhealthy"]} - } - ], - "optional":[ - { - "property_at_type":"DensityProperty", - "property_name":"filter", - "config_names":["getPM2_5Density"], - }, - { - "property_at_type":"ConcentrationProperty", - "config_names":["getAirQualityPPM"], - "required_unit":"ppm", - }, - { - "property_name":"voc", - "config_names":["getVOCDensity"] - }, - { - "property_name":"co2", - "config_names":["getCarbonDioxideLevel"] - }, - { - "property_name":"nox", - "config_names":["getNitrogenDioxideDensity"] - }, - { - "property_at_type":"TemperatureProperty", - "property_name":"temperature", - "config_names":["getCurrentTemperature"] - }, - { - "property_at_type":"HumidityProperty", - "property_name":"humidity", - "config_names":["getCurrentRelativeHumidity"], - "required_unit":"percentage", - "required_variable":"integer", - } - - ] - }, - - */ - + if(this.debug){ + console.log("\n\n\n\n\n=\n==\n==="); + console.log("thing title: ", thing_title); + } for(let m=0;m -1){ - console.log('(partial) name match: ', prop['title'], schema[serv_type][r]['property_name']); + //console.log('(partial) name match: ', prop['title'], schema[serv_type][r]['property_name']); might_work++; might_work++; } @@ -1980,9 +1916,9 @@ // Look for UNIT. // Checking for unit string might be finicky, as even within the webthings standard there are multiple ways to decribe these string (e.g. "percentage" and "%") if(typeof schema[serv_type][r]['required_unit'] != 'undefined' && typeof prop['unit'] != 'undefined'){ - console.log("required unit is set: ", schema[serv_type][r]['required_unit']); + //console.log("required unit is set: ", schema[serv_type][r]['required_unit']); if( prop['unit'].toLowerCase() == schema[serv_type][r]['required_unit'].toLowerCase() ){ - console.log("perfect unit match: ", prop['unit']); + //console.log("perfect unit match: ", prop['unit']); might_work++; } else{ @@ -2008,7 +1944,9 @@ let enum_item = schema[serv_type][r]['extra_attributes'][enum_test_key][p]; //console.log("enum_item: ", enum_item); if(prop['enum'].indexOf(enum_item) == -1){ - console.log("not found in enum: ", enum_item, prop['enum']); + if(this.debug){ + console.log("not found in enum: ", enum_item, prop['enum']); + } all_in_enum = false; might_work = -3; break; @@ -2069,7 +2007,7 @@ if(!endpoint_already_taken){ if(serv_type == 'required'){ - console.log("increasing matched_required_properties"); + //console.log("increasing matched_required_properties"); matched_required_properties++; } //console.error(schema.homekit_type, " matched_required_properties: " + matched_required_properties + " of " + schema.required.length); @@ -2106,14 +2044,18 @@ } // isn't serv_type always "required" when we arrive here? - console.log("\n\n------------- WHAT DID WE GET? -------------"); + //console.log("\n\n------------- WHAT DID WE GET? -------------"); if(serv_type == 'required'){ if(matched_required_properties == schema[serv_type].length){ - console.warn(schema.homekit_type, " M A T C H count with required properties. Matched: ", matched_required_properties, potent); + if(this.debug){ + console.warn(schema.homekit_type, " M A T C H count with required properties. Matched: ", matched_required_properties, potent); + } potentials[schema.homekit_type] = potent; } else{ - console.warn(schema.homekit_type, " not a match, only got " + matched_required_properties + " of " + schema[serv_type].length, potent); + if(this.debug){ + console.warn(schema.homekit_type, " not a match, only got " + matched_required_properties + " of " + schema[serv_type].length, potent); + } //console.log("XXX filled_endpoints: ", filled_endpoints); if(missing_required_endpoints.length > 0 && filled_endpoints.length > 0){ // make sure we're on the last run of the for loop that goes over required properties/endpoints @@ -2129,21 +2071,23 @@ //for(let h=0;h -1){ - console.log("Hacking: could calculate air quality opinion on the fly from pm25"); + if(this.debug){ + console.log("Hacking: could calculate air quality opinion on the fly from pm25"); + } const hackname = 'generate-' + hacks_count; potent['services'].push( {'config_name':'getAirQuality',"thing_id":thing_id,"property_id":"homebridge-fake-" + hacks_count} ); potent['extras'].push( {hackname:{'from':'getPM2_5Density','to':'getAirQuality','nr':hacks_count,'thresholds':[null,0,10,20,40,100] }} ); @@ -2152,7 +2096,9 @@ } else if(missing == 'getAirQuality' && filled_endpoints.indexOf('getCarbonDioxideLevel') > -1){ - console.log("Hacking: could calculate air quality opinion on the fly from carbon dioxide level"); + if(this.debug){ + console.log("Hacking: could calculate air quality opinion on the fly from carbon dioxide level"); + } potent['services'].push( {'config_name':'getAirQuality',"thing_id":thing_id,"property_id":"homebridge-fake-" + hacks_count} ); const hackname = 'generate-' + hacks_count; potent['extras'].push( {hackname:{'from':'getPM2_5Density','to':'getAirQuality','nr':hacks_count,'thresholds':[null,0,600,800,1000,1500] }} ); @@ -2165,7 +2111,9 @@ else if(schema.homekit_type == 'carbonDioxideSensor'){ if(missing == 'getCarbonDioxideDetected' && filled_endpoints.indexOf('getCarbonDioxideLevel') > -1){ - console.log("Hacking: could calculate carbon dioxide quality opinion on the fly from carbon dioxide level"); + if(this.debug){ + console.log("Hacking: could calculate carbon dioxide quality opinion on the fly from carbon dioxide level"); + } potent['services'].push( {'config_name':'getCarbonDioxideDetected',"thing_id":thing_id,"property_id":"homebridge-fake-" + hacks_count} ); const hackname = 'generate-' + hacks_count; potent['extras'].push( {hackname:{'from':'getPM2_5Density','to':'getAirQuality','nr':hacks_count,'thresholds':[0,1000] }} ); @@ -2176,11 +2124,15 @@ } } if(hacks_count == missing_required_endpoints.length){ - console.log("Hurray found enough hacks to complete the device: ", hacks_count); + if(this.debug){ + console.log("Found enough hacks to complete the device: ", hacks_count); + } potentials[schema.homekit_type] = potent; }else{ - console.warn('not enough hacks found to complete the device: ', hacks_count, " of ", missing_required_endpoints.length, missing_required_endpoints); + if(this.debug){ + console.warn('not enough hacks found to complete the device: ', hacks_count, " of ", missing_required_endpoints.length, missing_required_endpoints); + } } }