Skip to content

Commit

Permalink
ver. 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NikDevx committed Apr 7, 2021
1 parent 81b7156 commit 128b6e1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 93 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ Author: David Maher | Nik_Dev

This plugin is now using [py-air-control](https://github.com/rgerganov/py-air-control) directly to enable support for newer Philips connected air purifier models.

## Installation
## 🔴 Foreword 🔴

**If you are using http protocol you need to install version 2.3.2!**<br>
**Or if you only have a purifier without a humidifier function you need to install version 2.3.2 as well!**<br>
**The version above 2.3.2 has improvements only for humidifier.**



## 🟡 Installation 🟡

1. Install Homebridge using the [official instructions](https://github.com/homebridge/homebridge/wiki).
2. Install this plugin using `sudo npm install -g homebridge-philips-air --unsafe-perm`.
Expand All @@ -28,7 +36,7 @@ Plain CoAP users only will also need to do:

If you're only using HTTP, no additional steps are required.

### Configuration
### 🟢 Configuration 🟢

Edit your `config.json` accordingly. Configuration sample:

Expand All @@ -55,7 +63,6 @@ Edit your `config.json` accordingly. Configuration sample:
|- sleep\_speed | Does this device support 'sleep' speed? | No |
|- light\_control | Expose device lights as lightbulbs. | No |
|- allergic\_func | Does this device support 'allergic' function? | No |
|- water\_level | Expose device water level as water leak sensor. | No |
|- temperature\_sensor | Expose device temperature as temperature sensor. | No |
|- humidity\_sensor | Expose device humidity as humidity sensor. | No |
|- polling | Adding a refresh time for the all sensors in seconds. | No |
Expand Down
5 changes: 0 additions & 5 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@
"type": "boolean",
"description": "Does this device support 'allergic' function?"
},
"water_level": {
"title": "Water level",
"type": "boolean",
"description": "Expose device water level as water leak sensor."
},
"temperature_sensor": {
"title": "Temperature sensor",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Philips Air",
"name": "homebridge-philips-air",
"version": "3.2.0",
"version": "3.2.1",
"description": "Homebridge Plugin for Philips Air Purifiers",
"main": "dist/index.js",
"repository": {
Expand Down
1 change: 0 additions & 1 deletion src/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type DeviceConfig = {
sleep_speed: boolean;
light_control: boolean;
allergic_func: boolean;
water_level: boolean;
temperature_sensor: boolean;
polling: number;
humidity_sensor: boolean;
Expand Down
130 changes: 48 additions & 82 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'homebridge';
import {AirClient, HttpClient, CoapClient, PlainCoapClient, HttpClientLegacy} from 'philips-air';
import {promisify} from 'util';
import {exec} from 'child_process';
import * as fs from 'fs';
import {PhilipsAirPlatformConfig, DeviceConfig} from './configTypes';
import {PurifierStatus, PurifierFilters, PurifierFirmware} from './deviceTypes';
Expand All @@ -28,7 +29,6 @@ enum CommandType {
GetFirmware,
GetFilters,
GetStatus,
GetWaterLevel,
GetTemperature,
GetHumidity,
SetData
Expand Down Expand Up @@ -103,7 +103,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
this.enqueueCommand(CommandType.GetFirmware, purifier);
this.enqueueCommand(CommandType.GetStatus, purifier);
this.enqueueCommand(CommandType.GetFilters, purifier);
this.enqueueCommand(CommandType.GetWaterLevel, purifier);
this.enqueueCommand(CommandType.GetTemperature, purifier);
this.enqueueCommand(CommandType.GetHumidity, purifier);
});
Expand Down Expand Up @@ -145,12 +144,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
.updateCharacteristic(hap.Characteristic.AirQuality, iaql)
.updateCharacteristic(hap.Characteristic.PM2_5Density, status.pm25);
}
if (purifier.config.water_level) {
const WaterLevel = purifier.accessory.getService('Water level');
if (WaterLevel) {
WaterLevel.updateCharacteristic(hap.Characteristic.WaterLevel, status.wl);
}
}
if (purifier.config.humidity_sensor) {
const humidity_sensor = purifier.accessory.getService('Humidity');
if (humidity_sensor) {
Expand All @@ -166,7 +159,24 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
if (purifier.config.humidifier) {
const Humidifier = purifier.accessory.getService('Humidifier');
if (Humidifier) {
Humidifier.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, status.rh);
Humidifier.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, status.rh)
.updateCharacteristic(hap.Characteristic.WaterLevel, status.wl);
if (status.wl == 0) {
Humidifier
.updateCharacteristic(hap.Characteristic.Active, 0)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.RotationSpeed, 0)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, 0);

if (status.func != 'P') {
exec('airctrl --ipaddr ' + purifier.config.ip + ' --protocol coap --func P', (err, stdout, stderr) => {
if (err) {
return;
}
});
}
}
}
}
if (purifier.config.logger) {
Expand Down Expand Up @@ -262,29 +272,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
}
}

async updateWaterLevel(purifier: Purifier): Promise<void> {
try {
const status: PurifierStatus = await purifier.client?.getStatus();
purifier.laststatus = Date.now();
await this.storeKey(purifier);
if (purifier.config.water_level) {
const WatereLevel = purifier.accessory.getService('Water level');
if (WatereLevel) {
if (status.wl == 0) {
WatereLevel.updateCharacteristic(hap.Characteristic.LeakDetected, 1);
WatereLevel.updateCharacteristic(hap.Characteristic.WaterLevel, 0);
} else {
WatereLevel.updateCharacteristic(hap.Characteristic.LeakDetected, 0);
WatereLevel.updateCharacteristic(hap.Characteristic.WaterLevel, status.wl);
}
}
}

} catch (err) {
this.log.error('[' + purifier.config.name + '] Unable to load water level info: ' + err);
}
}

async updateTemperature(purifier: Purifier): Promise<void> {
try {
const status: PurifierStatus = await purifier.client?.getStatus();
Expand Down Expand Up @@ -383,7 +370,7 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
let speed_humidity = 0;
let state_ph = 0;
if (status.pwr == '1') {
if (status.func == 'PH') {
if (status.func == 'PH' && status.wl != 0) {
state_ph = 1;
if (status.rhset == 40) {
speed_humidity = 25;
Expand All @@ -397,15 +384,25 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
}
}
Humidifier
.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, status.rh);
if (state_ph == 1 && status.rhset >= 40) {
.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, status.rh)
.updateCharacteristic(hap.Characteristic.WaterLevel, status.wl);
if (state_ph && status.rhset >= 40) {
Humidifier
.updateCharacteristic(hap.Characteristic.Active, status.pwr)
.updateCharacteristic(hap.Characteristic.Active, state_ph)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, state_ph * 2)
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, state_ph)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, speed_humidity)
.updateCharacteristic(hap.Characteristic.RotationSpeed, speed_humidity);
}
if (status.wl == 0) {
if (status.func != 'P') {
exec('airctrl --ipaddr ' + purifier.config.ip + ' --protocol coap --func P', (err, stdout, stderr) => {
if (err) {
return;
}
});
}
}
}
}
} catch (err) {
Expand All @@ -429,6 +426,13 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
const values = {
pwr: (state as boolean).toString()
};
if (purifier.config.humidifier) {
if (status.wl == 0) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
values['func'] = 'P';
}
}
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -456,7 +460,7 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
const Humidifier = accessory.getService('Humidifier');
let speed_humidity = 0;
let state_ph = 0;
if (status.func == 'PH') {
if (status.func == 'PH' && status.wl != 0) {
state_ph = 1;
if (status.rhset == 40) {
speed_humidity = 25;
Expand All @@ -477,13 +481,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, state_ph)
.updateCharacteristic(hap.Characteristic.RotationSpeed, speed_humidity)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, speed_humidity);
} else {
Humidifier
.updateCharacteristic(hap.Characteristic.Active, 0)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.RotationSpeed, 0)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, 0);
}
}
}
Expand Down Expand Up @@ -713,9 +710,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
accessory.addService(hap.Service.FilterMaintenance, 'Pre-filter', 'Pre-filter');
accessory.addService(hap.Service.FilterMaintenance, 'Active carbon filter', 'Active carbon filter');
accessory.addService(hap.Service.FilterMaintenance, 'HEPA filter', 'HEPA filter');
if (config.water_level) {
accessory.addService(hap.Service.LeakSensor, 'Water level', 'Water level');
}
if (config.temperature_sensor) {
accessory.addService(hap.Service.TemperatureSensor, 'Temperature', 'Temperature');
}
Expand All @@ -738,14 +732,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
} else if (lightsService != undefined) {
accessory.removeService(lightsService);
}
const WaterLevel = accessory.getService('Water level');
if (config.water_level) {
if (WaterLevel == undefined) {
accessory.addService(hap.Service.LeakSensor, 'Water level', 'Water level');
}
} else if (WaterLevel != undefined) {
accessory.removeService(WaterLevel);
}
const temperature_sensor = accessory.getService('Temperature');
if (config.temperature_sensor) {
if (temperature_sensor == undefined) {
Expand Down Expand Up @@ -795,8 +781,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
}

this.purifiers.set(accessory.displayName, {
rhset: 0,
rh: 0,
accessory: accessory,
client: client,
config: config
Expand Down Expand Up @@ -829,7 +813,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
.updateCharacteristic(hap.Characteristic.Active, 0)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, Humidifier.rh)
.updateCharacteristic(hap.Characteristic.RotationSpeed, 0)
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, 0)
Expand Down Expand Up @@ -998,23 +981,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
callback();
});
}
if (config.water_level) {
const WaterLevel = accessory.getService('Water level');
if (WaterLevel) {
WaterLevel
.getCharacteristic(hap.Characteristic.LeakDetected)
.on('get', (callback: CharacteristicGetCallback) => {
this.enqueueAccessory(CommandType.GetWaterLevel, accessory);
callback();
});
WaterLevel
.getCharacteristic(hap.Characteristic.WaterLevel)
.on('get', (callback: CharacteristicGetCallback) => {
this.enqueueAccessory(CommandType.GetWaterLevel, accessory);
callback();
});
}
}
if (config.temperature_sensor) {
const temperature_sensor = accessory.getService('Temperature');
if (temperature_sensor) {
Expand Down Expand Up @@ -1050,10 +1016,7 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
.updateCharacteristic(hap.Characteristic.RotationSpeed, 0)
.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, 0)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.updateCharacteristic(hap.Characteristic.CurrentRelativeHumidity, Humidifier.rh);
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, 0);
callback();
} catch (err) {
callback(err);
Expand All @@ -1062,6 +1025,12 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
this.enqueueAccessory(CommandType.GetStatus, accessory);
callback();
});
Humidifier
.getCharacteristic(hap.Characteristic.WaterLevel)
.on('get', (callback: CharacteristicGetCallback) => {
this.enqueueAccessory(CommandType.GetStatus, accessory);
callback();
});
Humidifier
.getCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState)
.on('set', async(state: CharacteristicValue, callback: CharacteristicSetCallback) => {
Expand Down Expand Up @@ -1166,9 +1135,6 @@ class PhilipsAirPlatform implements DynamicPlatformPlugin {
case CommandType.GetStatus:
command = this.updateStatus(todoItem.purifier);
break;
case CommandType.GetWaterLevel:
command = this.updateWaterLevel(todoItem.purifier);
break;
case CommandType.GetTemperature:
command = this.updateTemperature(todoItem.purifier);
break;
Expand Down

0 comments on commit 128b6e1

Please sign in to comment.