Skip to content

Commit

Permalink
release v0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Mar 10, 2024
1 parent 0b7a6cd commit ea9b77a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 89 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Important changes v0.4.0 and above!!!
* Main control mode, buttons and presets need to be configured again!!!

## [0.20.0] - (10.03.2024)
## Changes
- dynamically update temp unit
- prevent set out of range temperature for Air Conditioner
- cleanup

## [0.19.0] - (02.03.2024)
## Changes
- added support to control devices over MQTT protocol
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,33 @@ class MelCloudPlatform {
const debug = enableDebugMode ? log(`Account: ${accountName}, did finish launching.`) : false;

//remove sensitive data
const config = {
const debugData = {
...account,
user: 'removed',
passwd: 'removed',
mqttUser: 'removed',
mqttPasswd: 'removed'
};
const debug1 = enableDebugMode ? log(`Account: ${accountName}, Config: ${JSON.stringify(config, null, 2)}`) : false;
const debug1 = enableDebugMode ? log(`Account: ${accountName}, Config: ${JSON.stringify(debugData, null, 2)}`) : false;

//set refresh interval
const accountInfoFile = `${prefDir}/${accountName}_Account`;
const buildingsFile = `${prefDir}/${accountName}_Buildings`;
const refreshInterval = account.refreshInterval * 1000 || 120000;

//melcloud account
const melCloud = new MelCloud(prefDir, accountName, user, passwd, language, enableDebugMode, refreshInterval);
const melCloud = new MelCloud(prefDir, accountName, user, passwd, language, enableDebugMode, accountInfoFile, buildingsFile, refreshInterval);
melCloud.on('checkDevicesListComplete', (accountInfo, contextKey, deviceInfo) => {
const deviceId = deviceInfo.DeviceID.toString();
const deviceType = deviceInfo.Type;
const deviceName = deviceInfo.DeviceName;
const deviceTypeText = CONSTANTS.DeviceType[deviceType];
const useFahrenheit = accountInfo.UseFahrenheit ? 1 : 0;
const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;

//melcloud devices
switch (deviceType) {
case 0: //Air Conditioner
const airConditioner = new DeviceAta(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, useFahrenheit, deviceInfoFile)
const airConditioner = new DeviceAta(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile)
airConditioner.on('publishAccessory', (accessory) => {

//publish device
Expand All @@ -87,7 +88,7 @@ class MelCloudPlatform {
});
break;
case 1: //Heat Pump
const heatPump = new DeviceAtw(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, useFahrenheit, deviceInfoFile)
const heatPump = new DeviceAtw(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile)
heatPump.on('publishAccessory', (accessory) => {

//publish device
Expand All @@ -108,7 +109,7 @@ class MelCloudPlatform {
});
break;
case 3: //Energy Recovery Ventilation
const energyRecoveryVentilation = new DeviceErv(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, useFahrenheit, deviceInfoFile)
const energyRecoveryVentilation = new DeviceErv(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile)
energyRecoveryVentilation.on('publishAccessory', (accessory) => {

//publish device
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "MELCloud Control",
"name": "homebridge-melcloud-control",
"version": "0.19.26",
"version": "0.20.0",
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
34 changes: 16 additions & 18 deletions src/deviceata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
let Accessory, Characteristic, Service, Categories, AccessoryUUID;

class MelCloudDevice extends EventEmitter {
constructor(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, useFahrenheit, deviceInfoFile) {
constructor(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile) {
super();

Accessory = api.platformAccessory;
Expand Down Expand Up @@ -37,12 +37,10 @@ class MelCloudDevice extends EventEmitter {
this.buttonsCount = this.buttons.length;
this.startPrepareAccessory = true;

//temp unit
this.useFahrenheit = useFahrenheit;

//melcloud device
this.melCloudAta = new MelCloudAta({
contextKey: contextKey,
accountInfoFile: accountInfoFile,
deviceInfoFile: deviceInfoFile,
debugLog: account.enableDebugMode
});
Expand All @@ -64,7 +62,7 @@ class MelCloudDevice extends EventEmitter {
this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${deviceTypeText} ${deviceId}`;
this.serialNumber = serialNumber;
this.firmwareRevision = firmwareAppVersion;
}).on('deviceState', async (deviceData, deviceState) => {
}).on('deviceState', async (deviceData, deviceState, useFahrenheit) => {
//device info
const displayMode = this.displayMode;
const hasAutomaticFanSpeed = deviceData.Device.HasAutomaticFanSpeed ?? false;
Expand All @@ -91,7 +89,8 @@ class MelCloudDevice extends EventEmitter {
this.modelSupportsHeat = modelSupportsHeat;
this.modelSupportsDry = modelSupportsDry;
this.temperatureIncrement = temperatureIncrement;
this.temperatureUnit = CONSTANTS.TemperatureDisplayUnits[this.useFahrenheit];
this.temperatureUnit = CONSTANTS.TemperatureDisplayUnits[useFahrenheit];
this.useFahrenheit = useFahrenheit;

//device state
const roomTemperature = deviceState.RoomTemperature;
Expand Down Expand Up @@ -179,7 +178,7 @@ class MelCloudDevice extends EventEmitter {
.updateCharacteristic(Characteristic.HeatingThresholdTemperature, setTemperature)
.updateCharacteristic(Characteristic.CoolingThresholdTemperature, setTemperature)
.updateCharacteristic(Characteristic.LockPhysicalControls, lockPhysicalControls)
.updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.useFahrenheit);
.updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
const updateRS = modelSupportsFanSpeed ? this.melCloudService.updateCharacteristic(Characteristic.RotationSpeed, fanSpeed) : false;
const updateSM = swingFunction ? this.melCloudService.updateCharacteristic(Characteristic.SwingMode, swingMode) : false;
};
Expand All @@ -200,7 +199,7 @@ class MelCloudDevice extends EventEmitter {
.updateCharacteristic(Characteristic.TargetHeatingCoolingState, targetOperationMode)
.updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
.updateCharacteristic(Characteristic.TargetTemperature, setTemperature)
.updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.useFahrenheit);
.updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
};
break;
};
Expand Down Expand Up @@ -629,7 +628,6 @@ class MelCloudDevice extends EventEmitter {
const autoDryFan = [modelSupportsDry ? 2 : 7, 7][this.autoHeatMode];
const heatFanDry = [7, modelSupportsDry ? 2 : 7][this.autoHeatMode];
const serviceName = `${deviceTypeText} ${accessoryName}`;
const temperatureUnit = this.temperatureUnit;

switch (displayMode) {
case 0: //Heater Cooler
Expand Down Expand Up @@ -771,8 +769,8 @@ class MelCloudDevice extends EventEmitter {
});
this.melCloudService.getCharacteristic(Characteristic.HeatingThresholdTemperature)
.setProps({
minValue: [0, 32][this.useFahrenheit],
maxValue: [31, 88][this.useFahrenheit],
minValue: 0,
maxValue: 31,
minStep: this.temperatureIncrement
})
.onGet(async () => {
Expand All @@ -784,15 +782,15 @@ class MelCloudDevice extends EventEmitter {
deviceState.SetTemperature = value;
deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.SetTemperature;
await this.melCloudAta.send(deviceState);
const info = this.disableLogInfo ? false : this.emit('message', `Set heating threshold temperature: ${value}${temperatureUnit}`);
const info = this.disableLogInfo ? false : this.emit('message', `Set heating threshold temperature: ${value}${this.temperatureUnit}`);
} catch (error) {
this.emit('error', `Set heating threshold temperature error: ${error}`);
};
});
this.melCloudService.getCharacteristic(Characteristic.CoolingThresholdTemperature)
.setProps({
minValue: [10, 50][this.useFahrenheit],
maxValue: [31, 88][this.useFahrenheit],
minValue: 10,
maxValue: 31,
minStep: this.temperatureIncrement
})
.onGet(async () => {
Expand All @@ -804,7 +802,7 @@ class MelCloudDevice extends EventEmitter {
deviceState.SetTemperature = value;
deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.SetTemperature;
await this.melCloudAta.send(deviceState);
const info = this.disableLogInfo ? false : this.emit('message', `Set cooling threshold temperature: ${value}${temperatureUnit}`);
const info = this.disableLogInfo ? false : this.emit('message', `Set cooling threshold temperature: ${value}${this.temperatureUnit}`);
} catch (error) {
this.emit('error', `Set cooling threshold temperature error: ${error}`);
};
Expand Down Expand Up @@ -905,8 +903,8 @@ class MelCloudDevice extends EventEmitter {
});
this.melCloudService.getCharacteristic(Characteristic.TargetTemperature)
.setProps({
minValue: [0, 32][this.useFahrenheit],
maxValue: [31, 88][this.useFahrenheit],
minValue: 0,
maxValue: 31,
minStep: this.temperatureIncrement
})
.onGet(async () => {
Expand All @@ -918,7 +916,7 @@ class MelCloudDevice extends EventEmitter {
deviceState.SetTemperature = value;
deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.SetTemperature;
await this.melCloudAta.send(deviceState);
const info = this.disableLogInfo ? false : this.emit('message', `Set temperature: ${value}${temperatureUnit}`);
const info = this.disableLogInfo ? false : this.emit('message', `Set temperature: ${value}${this.temperatureUnit}`);
} catch (error) {
this.emit('error', `Set temperature error: ${error}`);
};
Expand Down
Loading

0 comments on commit ea9b77a

Please sign in to comment.