Open Blackra1n5 opened 4 years ago
Could I see your AirPurifierAccessory.js fork? It would help a lot!
I've been using SimpleFanAccessory with a few modifications. I have tried to use AirPurifier Accessory but I seem to not be able to get correctly implement CurrentAirPurifierState and TargetAirPurifierState.
However, here is my Modified SimpleFanAccessory
`const BaseAccessory = require('./BaseAccessory');
class SimpleFanAccessory extends BaseAccessory { static getCategory(Categories) { return Categories.FAN; }
constructor(...props) {
super(...props);
}
_registerPlatformAccessory() {
const {Service} = this.hap;
this.accessory.addService(Service.Fan, this.device.context.name);
super._registerPlatformAccessory();
}
_registerCharacteristics(dps) {
const {Service, Characteristic} = this.hap;
const service = this.accessory.getService(Service.Fan);
this._checkServiceName(service, this.device.context.name);
this.dpActive = this._getCustomDP(this.device.context.dpActive) || '1';
this.dpRotationSpeed = this._getCustomDP(this.device.context.RotationSpeed) || '4';
const characteristicActive = service.getCharacteristic(Characteristic.On)
.updateValue(this._getActive(dps[this.dpActive]))
.on('get', this.getActive.bind(this))
.on('set', this.setActive.bind(this));
const characteristicRotationSpeed = service.getCharacteristic(Characteristic.RotationSpeed)
.setProps({
minValue: 0,
maxValue: 24,
minStep: 1
})
.updateValue(this._getSpeed(dps[this.dpRotationSpeed]))
.on('get', this.getSpeed.bind(this))
.on('set', this.setSpeed.bind(this));
}
// State getActive(callback) { this.getState(this.dpActive, (err, dp) => { if (err) return callback(err);
callback(null, this._getActive(dp));
});
}
_getActive(dp) {
const {Characteristic} = this.hap;
return dp;
}
setActive(value, callback) {
const {Characteristic} = this.hap;
return this.setState(this.dpActive, value, callback);
callback();
}
// Speed getSpeed(callback) { this.getState(this.dpRotationSpeed, (err, dp) => { if (err) return callback(err);
callback(null, this._getSpeed(dp));
});
}
_getSpeed(dp) {
const {Characteristic} = this.hap;
// console.log("_getSpeed = " + dp); return dp; }
setSpeed(value, callback) {
const {Characteristic} = this.hap;
if (value == 0) {
return this.setState(this.dpActive, false, callback);
} else {
return this.setState(this.dpRotationSpeed, value.toString(), callback);
}
callback();
}
}
module.exports = SimpleFanAccessory; `
I can't seem to get Air Purifier working that great either, I can try to base it off another plugin to see. But would you like to to make an accessory based off your code and see if I can make some tweaks to get it to show up officially in the plugin?
I haven't been able to spent substantial amount of time on it, however things are quite less hectic now and I will be able to work on this.
Would you mind explaining some of the code from some of the accessory.js files to me? Even just the data flow.
My JS is not great but it's something to do while I'm locked in ππ
I have a couple of Tuya Air Purifiers (branded as Homie) and would like to be able to control it as an air purifier accessory (in HomeKit) with the auto/manual modes, on/off, fan speed, filter status, and Particulate Matter sensor. These features should all be supported by HomeKit.
I have tried to write my own 'AirPurifierAccessory.js' file but my javascript is terrible :( I am currently running it as a fan with a modified simpleFan.js file
Here is the air purifier's schema:
{ name: 'Bedroom', id: '37600541dc4f225b3576', key: '865ba4398c24d1be', def: { schema: '[{"mode":"rw","code":"switch","name":"\\u5f00\\u5173","property":{"type":"bool"},"iconname":"icon-dp_power2","id":1,"type":"obj","desc":""},{"mode":"ro","code":"pm25","name":"PM2.5","property":{"unit":"","min":0,"max":999,"scale":0,"step":1,"type":"value"},"iconname":"icon-dp_dust","id":2,"type":"obj","desc":""},{"mode":"rw","code":"mode","name":"\\u6a21\\u5f0f","property":{"range":["Auto","Manual","Monitor"],"type":"enum"},"iconname":"icon-dp_mode","id":3,"type":"obj","desc":"\\u81ea\\u52a8\\u6a21\\u5f0f\\uff1b\\u624b\\u52a8\\u6a21\\u5f0f\\uff1b\\u76d1\\u6d4b\\u6a21\\u5f0f"},{"mode":"rw","code":"speed","name":"\\u98ce\\u901f","property":{"range":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"],"type":"enum"},"iconname":"icon-dp_wind","id":4,"type":"obj","desc":""},{"mode":"ro","code":"filter","name":"\\u6ee4\\u82af\\u4f7f\\u7528\\u7387","property":{"unit":"\\uff05","min":0,"max":100,"scale":0,"step":1,"type":"value"},"iconname":"icon-dp_wet2","id":5,"type":"obj","desc":""},{"mode":"rw","code":"lock","name":"\\u7ae5\\u9501","property":{"type":"bool"},"iconname":"icon-dp_lock","id":7,"type":"obj","desc":""},{"mode":"rw","code":"light","name":"\\u706f\\u5149","property":{"type":"bool"},"iconname":"icon-dp_light","id":8,"type":"obj","desc":""},{"mode":"ro","code":"fault","scope":"fault","name":"\\u6545\\u969c\\u544a\\u8b66","property":{"label":["1","2"],"type":"bitmap","maxlen":2},"iconname":"icon-dp_warming","id":21,"type":"obj","desc":""},{"mode":"ro","code":"air_quality","name":"\\u7a7a\\u6c14\\u8d28\\u91cf","property":{"range":["1","2","3","4"],"type":"enum"},"id":22,"type":"obj","desc":""},{"mode":"rw","code":"SmartSleepSwitch","name":"\\u667a\\u80fd\\u7761\\u7720\\u5f00\\u5173","property":{"type":"bool"},"id":101,"type":"obj","desc":""},{"mode":"rw","code":"ScreenDisplaySel","name":"\\u5c4f\\u663e\\u8bbe\\u7f6e","property":{"range":["1","2","3","4"],"type":"enum"},"id":102,"type":"obj","desc":"PM2.5;Wifi;Filter;AirVolume"},{"mode":"rw","code":"SoundSwitch","name":"\\u97f3\\u6548\\u5f00\\u5173","property":{"type":"bool"},"id":103,"type":"obj","desc":"\\u8702\\u9e23\\u5668\\u5f00\\u5173"},{"mode":"rw","code":"MonitorAutoPowerOnSw","name":"\\u76d1\\u6d4b\\u6a21\\u5f0f\\u81ea\\u52a8\\u5f00\\u673a\\u5f00\\u5173","property":{"type":"bool"},"id":104,"type":"obj","desc":"\\u76d1\\u6d4b\\u6a21\\u5f0f\\u81ea\\u52a8\\u5f00\\u673a\\u5f00\\u5173\\uff0c\\u8bbe\\u7f6e\\u4e3a\\u5f00\\u65f6PM2.5\\u6570\\u503c\\u624d\\u6709\\u6548"},{"mode":"rw","code":"AutoPowerOnPM25","name":"\\u81ea\\u52a8\\u5f00\\u673aPM2.5","property":{"unit":"","min":0,"max":999,"scale":1,"step":1,"type":"value"},"id":105,"type":"obj","desc":"\\u76d1\\u6d4b\\u6a21\\u5f0f\\u81ea\\u52a8\\u5f00\\u673aPM2.5\\u6570\\u503c\\uff0c\\u7531\\u7528\\u6237\\u8bbe\\u7f6e"}]', }, },
Signature:
Ready to handle Master Bedroom Air purifier (fan:3.3) with signature {"1":false,"2":10,"3":"Auto","4":"1","5":100,"7":false,"8":true,"21":0,"22":"1","101":true,"102":"1","103":true,"104":true,"105":100}
Key
1: Active (true, false) 2: PM2.5 Density (0-999) 3: Auto Mode (Auto, Manual, Monitor) 4: Fan Level (1-24) 5: Filter Status (0-100%) 7: Child Lock (true, false) 8: Light sensor (true, false) x 102: Screen Display Selection (1-4) x 103: Sound Switch (true, False) x 104: Auto On When PM2.5 reaches [105] (true, false) x 105: Auto On threshold (0-999)
I would really appreciate any help! Many Thanks :)