diff --git a/package.json b/package.json index 7869ea8b..ba672083 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "main": "dist/index.js", "scripts": { - "lint": "eslint src/**/**.ts --max-warnings=0", + "lint": "eslint src/**/*.ts --max-warnings=0", "test": "jest", "watch": "npm run build && npm link && nodemon", "build": "rimraf ./dist && tsc", diff --git a/src/accessory/AccessoryFactory.ts b/src/accessory/AccessoryFactory.ts index 040a5661..0ed47a02 100644 --- a/src/accessory/AccessoryFactory.ts +++ b/src/accessory/AccessoryFactory.ts @@ -26,6 +26,7 @@ import AirQualitySensorAccessory from './AirQualitySensorAccessory'; import HumanPresenceSensorAccessory from './HumanPresenceSensorAccessory'; import HumidifierAccessory from './HumidifierAccessory'; import AirPurifierAccessory from './AirPurifierAccessory'; +import TemperatureHumidityIRSensorAccessory from './TemperatureHumidityIRSensorAccessory'; export default class AccessoryFactory { @@ -104,6 +105,9 @@ export default class AccessoryFactory { case 'co2bj': handler = new CarbonDioxideSensorAccessory(platform, accessory); break; + case 'wnykq': + handler = new TemperatureHumidityIRSensorAccessory(platform, accessory); + break; case 'wsdcg': handler = new TemperatureHumiditySensorAccessory(platform, accessory); break; diff --git a/src/accessory/SwitchAccessory.ts b/src/accessory/SwitchAccessory.ts index 6ec6c47a..d0793f9b 100644 --- a/src/accessory/SwitchAccessory.ts +++ b/src/accessory/SwitchAccessory.ts @@ -21,7 +21,7 @@ export default class SwitchAccessory extends BaseAccessory { this.accessory.removeService(oldService); } - const schema = this.device.schema.filter((schema) => schema.code.startsWith('switch') && schema.type !== TuyaDeviceSchemaType.Boolean); + const schema = this.device.schema.filter((schema) => schema.code.startsWith('switch') && schema.type === TuyaDeviceSchemaType.Boolean); for (const _schema of schema) { const name = (schema.length === 1) ? this.device.name : _schema.code; this.configureSwitch(_schema, name); diff --git a/src/accessory/TemperatureHumidityIRSensorAccessory.ts b/src/accessory/TemperatureHumidityIRSensorAccessory.ts new file mode 100644 index 00000000..eaa6b1e5 --- /dev/null +++ b/src/accessory/TemperatureHumidityIRSensorAccessory.ts @@ -0,0 +1,23 @@ +import { PlatformAccessory } from 'homebridge'; +import { TuyaPlatform } from '../platform'; +import BaseAccessory from './BaseAccessory'; +import { configureHumiditySensor } from './TemperatureHumiditySensorAccessory/configureHumiditySensor'; +import { configureTemperatureSensor } from './TemperatureHumiditySensorAccessory/configureTemperatureSensor'; + + +export default class TemperatureHumidityIRSensorAccessory extends BaseAccessory { + + constructor(platform: TuyaPlatform, accessory: PlatformAccessory) { + super(platform, accessory); + + configureTemperatureSensor(this); + configureHumiditySensor(this); + } + + requiredSchema() { + return []; + } + + + +} diff --git a/src/accessory/TemperatureHumiditySensorAccessory.ts b/src/accessory/TemperatureHumiditySensorAccessory.ts index d034df48..24efd395 100644 --- a/src/accessory/TemperatureHumiditySensorAccessory.ts +++ b/src/accessory/TemperatureHumiditySensorAccessory.ts @@ -1,8 +1,8 @@ import { PlatformAccessory } from 'homebridge'; -import { TuyaDeviceSchemaIntegerProperty } from '../device/TuyaDevice'; import { TuyaPlatform } from '../platform'; -import { limit } from '../util/util'; import BaseAccessory from './BaseAccessory'; +import { configureHumiditySensor } from './TemperatureHumiditySensorAccessory/configureHumiditySensor'; +import { configureTemperatureSensor } from './TemperatureHumiditySensorAccessory/configureTemperatureSensor'; const SCHEMA_CODE = { SENSOR_STATUS: ['va_temperature', 'va_humidity', 'humidity_value'], @@ -13,54 +13,14 @@ export default class TemperatureHumiditySensorAccessory extends BaseAccessory { constructor(platform: TuyaPlatform, accessory: PlatformAccessory) { super(platform, accessory); - this.configureTemperatureSensor(); - this.configureHumiditySensor(); + configureTemperatureSensor(this); + configureHumiditySensor(this); } requiredSchema() { return [SCHEMA_CODE.SENSOR_STATUS]; } - configureTemperatureSensor() { - const schema = this.getSchema('va_temperature'); - if (!schema) { - this.log.warn('TemperatureSensor not supported.'); - return; - } - const service = this.accessory.getService(this.Service.TemperatureSensor) - || this.accessory.addService(this.Service.TemperatureSensor); - - const property = schema.property as TuyaDeviceSchemaIntegerProperty; - const multiple = Math.pow(10, property ? property.scale : 0); - service.getCharacteristic(this.Characteristic.CurrentTemperature) - .onGet(() => { - const status = this.getStatus(schema.code)!; - // this.log.debug('CurrentTemperature:', 'property =', property, 'multiple =', multiple, 'status =', status); - return limit(status.value as number / multiple, -270, 100); - }); - - } - - configureHumiditySensor() { - const schema = this.getSchema('va_humidity', 'humidity_value'); - if (!schema) { - this.log.warn('HumiditySensor not supported.'); - return; - } - - const service = this.accessory.getService(this.Service.HumiditySensor) - || this.accessory.addService(this.Service.HumiditySensor); - - const property = schema.property as TuyaDeviceSchemaIntegerProperty; - const multiple = Math.pow(10, property ? property.scale : 0); - service.getCharacteristic(this.Characteristic.CurrentRelativeHumidity) - .onGet(() => { - const status = this.getStatus(schema.code)!; - // this.log.debug('CurrentRelativeHumidity:', 'property =', property, 'multiple =', multiple, 'status =', status); - return limit(status.value as number / multiple, 0, 100); - }); - - } } diff --git a/src/accessory/TemperatureHumiditySensorAccessory/configureHumiditySensor.ts b/src/accessory/TemperatureHumiditySensorAccessory/configureHumiditySensor.ts new file mode 100644 index 00000000..22e68fdc --- /dev/null +++ b/src/accessory/TemperatureHumiditySensorAccessory/configureHumiditySensor.ts @@ -0,0 +1,24 @@ +import { TuyaDeviceSchemaIntegerProperty } from '../../device/TuyaDevice'; +import { limit } from '../../util/util'; +import BaseAccessory from '../BaseAccessory'; + +export function configureHumiditySensor(accessory: BaseAccessory) { + const schema = accessory.getSchema('va_humidity', 'humidity_value'); + if (!schema) { + accessory.log.warn('HumiditySensor not supported.'); + return; + } + + const service = accessory.accessory.getService(accessory.Service.HumiditySensor) + || accessory.accessory.addService(accessory.Service.HumiditySensor); + + const property = schema.property as TuyaDeviceSchemaIntegerProperty; + const multiple = Math.pow(10, property ? property.scale : 0); + service.getCharacteristic(accessory.Characteristic.CurrentRelativeHumidity) + .onGet(() => { + const status = accessory.getStatus(schema.code)!; + // this.log.debug('CurrentRelativeHumidity:', 'property =', property, 'multiple =', multiple, 'status =', status); + return limit(status.value as number / multiple, 0, 100); + }); + +} \ No newline at end of file diff --git a/src/accessory/TemperatureHumiditySensorAccessory/configureTemperatureSensor.ts b/src/accessory/TemperatureHumiditySensorAccessory/configureTemperatureSensor.ts new file mode 100644 index 00000000..8df8a8b8 --- /dev/null +++ b/src/accessory/TemperatureHumiditySensorAccessory/configureTemperatureSensor.ts @@ -0,0 +1,24 @@ +import { TuyaDeviceSchemaIntegerProperty } from '../../device/TuyaDevice'; +import { limit } from '../../util/util'; +import BaseAccessory from '../BaseAccessory'; + +export function configureTemperatureSensor(accessory: BaseAccessory) { + const schema = accessory.getSchema('va_temperature'); + if (!schema) { + accessory.log.warn('TemperatureSensor not supported.'); + return; + } + + const service = accessory.accessory.getService(accessory.Service.TemperatureSensor) + || accessory.accessory.addService(accessory.Service.TemperatureSensor); + + const property = schema.property as TuyaDeviceSchemaIntegerProperty; + const multiple = Math.pow(10, property ? property.scale : 0); + service.getCharacteristic(accessory.Characteristic.CurrentTemperature) + .onGet(() => { + const status = accessory.getStatus(schema.code)!; + // accessory.log.debug('CurrentTemperature:', 'property =', property, 'multiple =', multiple, 'status =', status); + return limit(status.value as number / multiple, -270, 100); + }); + +} \ No newline at end of file diff --git a/src/platform.ts b/src/platform.ts index e02c81e7..38155ba2 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -256,10 +256,10 @@ export class TuyaPlatform implements DynamicPlatformPlugin { this.log.info(`Got home_id=${home_id}, name=${name}`); if (this.options.homeWhitelist) { if (this.options.homeWhitelist.includes(home_id)) { - this.log.info(`Found home_id=${home_id} in whitelist; including devices from this home.`); - homeIDList.push(home_id); + this.log.info(`Found home_id=${home_id} in whitelist; including devices from this home.`); + homeIDList.push(home_id); } else { - this.log.info(`Did not find home_id=${home_id} in whitelist; excluding devices from this home.`); + this.log.info(`Did not find home_id=${home_id} in whitelist; excluding devices from this home.`); } } else { homeIDList.push(home_id);