Skip to content

Commit

Permalink
start of H5198
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Dec 30, 2023
1 parent 1993917 commit b9cdd8f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 9 deletions.
6 changes: 3 additions & 3 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@
"deviceId": {
"title": "Device ID",
"type": "string",
"description": "Enter the 23 digit Govee Device ID to begin (e.g. 12:AB:A1:C5:A8:99:D2:17).",
"description": "Enter the 23/26 digit Govee Device ID to begin (e.g. 12:AB:A1:C5:A8:99:D2:17).",
"minLength": 23,
"maxLength": 23
},
Expand All @@ -1094,7 +1094,7 @@
"title": "Hide From HomeKit",
"description": "If true, this accessory will be removed and ignored from HomeKit.",
"condition": {
"functionBody": "return (model.thermoDevices && model.thermoDevices[arrayIndices] && model.thermoDevices[arrayIndices].deviceId && model.thermoDevices[arrayIndices].deviceId.length === 23);"
"functionBody": "return (model.thermoDevices && model.thermoDevices[arrayIndices] && model.thermoDevices[arrayIndices].deviceId && [23,26].includes(model.thermoDevices[arrayIndices].deviceId.length));"
}
},
"lowBattThreshold": {
Expand All @@ -1104,7 +1104,7 @@
"placeholder": 20,
"minimum": 1,
"condition": {
"functionBody": "return (model.thermoDevices && model.thermoDevices[arrayIndices] && model.thermoDevices[arrayIndices].deviceId && model.thermoDevices[arrayIndices].deviceId.length === 23 && !model.thermoDevices[arrayIndices].ignoreDevice);"
"functionBody": "return (model.thermoDevices && model.thermoDevices[arrayIndices] && model.thermoDevices[arrayIndices].deviceId && [23,26].includes(model.thermoDevices[arrayIndices].deviceId.length) && !model.thermoDevices[arrayIndices].ignoreDevice);"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/device/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import deviceSensorContact from './sensor-contact.js';
import deviceSensorLeak from './sensor-leak.js';
import deviceSensorMonitor from './sensor-monitor.js';
import deviceSensorThermo from './sensor-thermo.js';
import deviceSensorThermo4 from './sensor-thermo4.js';
import deviceSwitchDouble from './switch-double.js';
import deviceSwitchSingle from './switch-single.js';
import deviceSwitchTriple from './switch-triple.js';
Expand Down Expand Up @@ -63,6 +64,7 @@ export default {
deviceSensorLeak,
deviceSensorMonitor,
deviceSensorThermo,
deviceSensorThermo4,
deviceSwitchDouble,
deviceSwitchSingle,
deviceSwitchTriple,
Expand Down
55 changes: 55 additions & 0 deletions lib/device/sensor-thermo4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { base64ToHex, getTwoItemPosition, hexToTwoItems } from '../utils/functions.js';
import platformLang from '../utils/lang-en.js';

export default class {
constructor(platform, accessory) {
// Set up variables from the platform
this.hapChar = platform.api.hap.Characteristic;
this.hapErr = platform.api.hap.HapStatusError;
this.hapServ = platform.api.hap.Service;
this.platform = platform;

// Set up variables from the accessory
this.accessory = accessory;

// remove temperature sensor, humidity sensor, battery service
if (this.accessory.getService(this.hapServ.TemperatureSensor)) {
this.accessory.removeService(this.accessory.getService(this.hapServ.TemperatureSensor));
}
if (this.accessory.getService(this.hapServ.HumiditySensor)) {
this.accessory.removeService(this.accessory.getService(this.hapServ.HumiditySensor));
}
if (this.accessory.getService(this.hapServ.Battery)) {
this.accessory.removeService(this.accessory.getService(this.hapServ.Battery));
}

// Output the customised options to the log
const opts = JSON.stringify({});
platform.log('[%s] %s %s.', accessory.displayName, platformLang.devInitOpts, opts);
}

externalUpdate(params) {
this.accessory.logWarn(JSON.stringify(params, null, 2));

// Check for some other scene/mode change
(params.commands || []).forEach((command) => {
const hexString = base64ToHex(command);
const hexParts = hexToTwoItems(hexString);

this.accessory.logWarn(`${platformLang.newScene}: [${command}] [${hexString}]`);

// Return now if not a device query update code
if (getTwoItemPosition(hexParts, 1) !== 'aa') {
return;
}

const deviceFunction = `${getTwoItemPosition(hexParts, 2)}${getTwoItemPosition(hexParts, 3)}`;

switch (deviceFunction) {
default:
this.accessory.logWarn(`${platformLang.newScene}: [${command}] [${hexString}]`);
break;
}
});
}
}
8 changes: 6 additions & 2 deletions lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ export default class {
if (httpDevices && httpDevices.length > 0) {
// We have some devices from HTTP client
httpDevices.forEach((httpDevice) => {
// It appears sometimes the device id isn't quite in the form I first expected
if (httpDevice.device.length === 16) {
// Format device id
if (!httpDevice.device.includes(':')) {
// Eg converts abcd1234abcd1234 to AB:CD:12:34:AB:CD:12:34
httpDevice.device = httpDevice.device.replace(/..\B/g, '$&:').toUpperCase();
}
Expand Down Expand Up @@ -957,6 +957,10 @@ export default class {
// Device is a thermo-hygrometer sensor
devInstance = deviceTypes.deviceSensorThermo;
accessory = devicesInHB.get(uuid) || this.addAccessory(device);
} else if (platformConsts.models.sensorThermo4.includes(device.model)) {
// Device is a thermo-hygrometer sensor with 4 prongs and AWS support
devInstance = deviceTypes.deviceSensorThermo4;
accessory = devicesInHB.get(uuid) || this.addAccessory(device);
} else if (platformConsts.models.sensorMonitor.includes(device.model)) {
devInstance = deviceTypes.deviceSensorMonitor;
doAWSPolling = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ export default {
'H5177',
'H5179',
'H5183',
'H5198',
],
sensorThermo4: ['H5198'],
sensorMonitor: ['H5106'],
fan: ['H7100', 'H7101', 'H7102', 'H7111'],
heater1: ['H7130', 'H713A', 'H713B', 'H713C'],
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

0 comments on commit b9cdd8f

Please sign in to comment.