@hernas/homebridge-panasonic-heat-pump
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -49,47 +49,37 @@ "use strict"; | ||
async discoverDevices() { | ||
if (!this.email || !this.password) { | ||
return; | ||
} | ||
const panasonicApi = new panasonicApi_1.PanasonicApi(this.email, this.password); | ||
const { selectedDeviceId, selectedDeviceName, deviceConf } = await panasonicApi.loadDevice(); | ||
const exampleDevices = [ | ||
{ | ||
uniqueId: selectedDeviceId, | ||
displayName: selectedDeviceName, | ||
isCoolModeEnabled: deviceConf.configration[0].zoneInfo[0].coolMode === 'enable', | ||
hasWaterTank: deviceConf.configration[0].tankInfo[0].tank === 'Yes', | ||
}, | ||
]; | ||
// loop over the discovered devices and register each one if it has not already been registered | ||
for (const device of exampleDevices) { | ||
// generate a unique id for the accessory this should be generated from | ||
// something globally unique, but constant, for example, the device serial | ||
// number or MAC address | ||
let devices = []; | ||
try { | ||
const { selectedDeviceId, selectedDeviceName, deviceConf } = await panasonicApi.loadDevice(); | ||
devices = [ | ||
{ | ||
uniqueId: selectedDeviceId, | ||
displayName: selectedDeviceName, | ||
isCoolModeEnabled: deviceConf.configration[0].zoneInfo[0].coolMode === 'enable', | ||
hasWaterTank: deviceConf.configration[0].tankInfo[0].tank === 'Yes', | ||
}, | ||
]; | ||
} | ||
catch (e) { | ||
this.log.error(`Could not load the device: ${e}`); | ||
} | ||
for (const device of devices) { | ||
const uuid = this.api.hap.uuid.generate(device.uniqueId); | ||
// see if an accessory with the same uuid has already been registered and restored from | ||
// the cached devices we stored in the `configureAccessory` method above | ||
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); | ||
if (existingAccessory) { | ||
// the accessory already exists | ||
this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); | ||
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.: | ||
existingAccessory.context.device = device; | ||
this.api.updatePlatformAccessories([existingAccessory]); | ||
// create the accessory handler for the restored accessory | ||
// this is imported from `platformAccessory.ts` | ||
if (existingAccessory.context.device.hasWaterTank === undefined) { | ||
existingAccessory.context.device = device; | ||
this.api.updatePlatformAccessories([existingAccessory]); | ||
} | ||
new platformAccessory_1.PanasonicHeatPumpPlatformAccessory(this, existingAccessory, panasonicApi); | ||
// it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.: | ||
// remove platform accessories when no longer present | ||
// this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]); | ||
// this.log.info('Removing existing accessory from cache:', existingAccessory.displayName); | ||
} | ||
else { | ||
// the accessory does not yet exist, so we need to create it | ||
this.log.info('Adding new accessory:', device.displayName); | ||
// create a new accessory | ||
const accessory = new this.api.platformAccessory(device.displayName, uuid); | ||
// store a copy of the device object in the `accessory.context` | ||
// the `context` property can be used to store any data about the accessory you may need | ||
accessory.context.device = device; | ||
// create the accessory handler for the newly create accessory | ||
// this is imported from `platformAccessory.ts` | ||
new platformAccessory_1.PanasonicHeatPumpPlatformAccessory(this, accessory, panasonicApi); | ||
// link the accessory to your platform | ||
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]); | ||
@@ -96,0 +86,0 @@ } |
import { PlatformAccessory } from 'homebridge'; | ||
import { PanasonicApi } from './panasonicApi'; | ||
import { PanasonicHeatPumpHomebridgePlatform } from './platform'; | ||
/** | ||
* Platform Accessory | ||
* An instance of this class is created for each accessory your platform registers | ||
* Each accessory may expose multiple services of different service types. | ||
*/ | ||
declare type Details = { | ||
temperatureNow: number; | ||
heatingCoolingState: number; | ||
targetHeatingCoolingState: number; | ||
outdoorTemperatureNow: number; | ||
tankTemperatureNow: number; | ||
tankTemperatureSet: number; | ||
tankHeatingCoolingState: number; | ||
tankTargetHeatingCoolingState: number; | ||
isActive: boolean; | ||
ecoModeIsActive: boolean; | ||
comfortModeIsActive: boolean; | ||
tankTemperatureMax: number; | ||
tankTemperatureMin: number; | ||
targetTempSet: number; | ||
targetTempMin: number; | ||
targetTempMax: number; | ||
tempType: 'heat' | 'cool' | 'eco' | 'comfort'; | ||
}; | ||
export declare class PanasonicHeatPumpPlatformAccessory { | ||
@@ -20,24 +34,7 @@ private readonly platform; | ||
private readonly hasWaterTank; | ||
private lastDetailsPromise; | ||
private lastDetails; | ||
private timeoutId; | ||
constructor(platform: PanasonicHeatPumpHomebridgePlatform, accessory: PlatformAccessory, panasonicApi: PanasonicApi); | ||
getReadings(force?: boolean, afterSet?: boolean): Promise<{ | ||
temperatureNow: any; | ||
heatingCoolingState: number; | ||
targetHeatingCoolingState: number; | ||
outdoorTemperatureNow: any; | ||
tankTemperatureNow: any; | ||
tankTemperatureSet: any; | ||
tankHeatingCoolingState: number; | ||
tankTargetHeatingCoolingState: number; | ||
isActive: boolean; | ||
ecoModeIsActive: boolean; | ||
comfortModeIsActive: boolean; | ||
tankTemperatureMax: any; | ||
tankTemperatureMin: any; | ||
targetTempSet: any; | ||
targetTempMin: any; | ||
targetTempMax: any; | ||
tempType: "cool" | "heat" | "eco" | "comfort"; | ||
}>; | ||
getReadings(force?: boolean, afterSet?: boolean): Promise<Details>; | ||
updateReadings(): Promise<void>; | ||
@@ -47,2 +44,3 @@ private refreshTimeout; | ||
} | ||
export {}; | ||
//# sourceMappingURL=platformAccessory.d.ts.map |
@@ -5,7 +5,2 @@ "use strict"; | ||
const panasonicApi_1 = require("./panasonicApi"); | ||
/** | ||
* Platform Accessory | ||
* An instance of this class is created for each accessory your platform registers | ||
* Each accessory may expose multiple services of different service types. | ||
*/ | ||
class PanasonicHeatPumpPlatformAccessory { | ||
@@ -57,3 +52,8 @@ constructor(platform, accessory, panasonicApi) { | ||
} | ||
this.panasonicApi.setOperationMode(this.accessory.context.device.uniqueId, operationMode); | ||
try { | ||
this.panasonicApi.setOperationMode(this.accessory.context.device.uniqueId, operationMode); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set operation mode[${this.accessory.context.device.uniqueId}][${operationMode}]: ${e}`); | ||
} | ||
await this.getReadings(true); | ||
@@ -65,3 +65,8 @@ }).onGet(async () => (await this.getReadings()).targetHeatingCoolingState); | ||
const adjustedTemp = (parseInt(temp)) - readings.temperatureNow; | ||
this.panasonicApi.setZoneTemp(this.accessory.context.device.uniqueId, adjustedTemp, readings.tempType); | ||
try { | ||
this.panasonicApi.setZoneTemp(this.accessory.context.device.uniqueId, adjustedTemp, readings.tempType); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set zone temp[${this.accessory.context.device.uniqueId}][${adjustedTemp}][${readings.tempType}]: ${e}`); | ||
} | ||
await this.getReadings(true); | ||
@@ -87,7 +92,17 @@ }).onGet(async () => { | ||
if (value) { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.Eco); | ||
try { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.Eco); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set special status[${this.accessory.context.device.uniqueId}][${panasonicApi_1.PanasonicSpecialStatus.Eco}]: ${e}`); | ||
} | ||
this.comfortModeService.getCharacteristic(this.platform.Characteristic.On).updateValue(false); | ||
} | ||
else { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.None); | ||
try { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.None); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set special status[${this.accessory.context.device.uniqueId}][${panasonicApi_1.PanasonicSpecialStatus.None}]: ${e}`); | ||
} | ||
} | ||
@@ -103,7 +118,17 @@ await this.getReadings(true, true); | ||
if (value) { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.Comfort); | ||
try { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.Comfort); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set special status[${this.accessory.context.device.uniqueId}][${panasonicApi_1.PanasonicSpecialStatus.Comfort}]: ${e}`); | ||
} | ||
this.ecoModeService.getCharacteristic(this.platform.Characteristic.On).updateValue(false); | ||
} | ||
else { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.None); | ||
try { | ||
panasonicApi.setSpecialStatus(this.accessory.context.device.uniqueId, panasonicApi_1.PanasonicSpecialStatus.None); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set special status[${this.accessory.context.device.uniqueId}][${panasonicApi_1.PanasonicSpecialStatus.None}]: ${e}`); | ||
} | ||
} | ||
@@ -117,3 +142,3 @@ await this.getReadings(true, true); | ||
if (force) { | ||
this.lastDetails = undefined; | ||
this.lastDetailsPromise = undefined; | ||
} | ||
@@ -228,8 +253,36 @@ const loadReadings = async () => { | ||
} | ||
if (this.lastDetailsPromise) { | ||
return this.lastDetailsPromise; | ||
} | ||
const readingsPromise = loadReadings().then(details => { | ||
this.lastDetails = details; | ||
return details; | ||
}); | ||
this.lastDetailsPromise = readingsPromise; | ||
return await readingsPromise; | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not fetch details of device[${this.accessory.context.device.uniqueId}] ${e}`); | ||
if (this.lastDetails) { | ||
return this.lastDetails; | ||
} | ||
const readingsPromise = loadReadings(); | ||
this.lastDetails = readingsPromise; | ||
return await readingsPromise; | ||
return { | ||
temperatureNow: 0, | ||
heatingCoolingState: 0, | ||
targetHeatingCoolingState: 0, | ||
outdoorTemperatureNow: 0, | ||
tankTemperatureNow: 0, | ||
tankTemperatureSet: 0, | ||
tankHeatingCoolingState: 0, | ||
tankTargetHeatingCoolingState: 0, | ||
isActive: false, | ||
ecoModeIsActive: false, | ||
comfortModeIsActive: false, | ||
tankTemperatureMax: 0, | ||
tankTemperatureMin: 0, | ||
targetTempSet: 0, | ||
targetTempMin: 0, | ||
targetTempMax: 0, | ||
tempType: 'heat', | ||
}; | ||
} | ||
@@ -293,3 +346,8 @@ finally { | ||
this.tankService.getCharacteristic(this.platform.Characteristic.TargetTemperature).onSet(async (temp) => { | ||
this.panasonicApi.setTankTargetHeat(this.accessory.context.device.uniqueId, temp); | ||
try { | ||
this.panasonicApi.setTankTargetHeat(this.accessory.context.device.uniqueId, temp); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set tank target heat[${this.accessory.context.device.uniqueId}][${temp}]: ${e}`); | ||
} | ||
await this.getReadings(true); | ||
@@ -308,3 +366,8 @@ }).onGet(async () => { | ||
.updateValue(this.platform.Characteristic.TargetHeatingCoolingState.OFF); | ||
this.panasonicApi.setTankStatus(this.accessory.context.device.uniqueId, false); | ||
try { | ||
this.panasonicApi.setTankStatus(this.accessory.context.device.uniqueId, false); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set tank status[${this.accessory.context.device.uniqueId}][${false}]: ${e}`); | ||
} | ||
await this.getReadings(true, true); | ||
@@ -316,3 +379,8 @@ return; | ||
.updateValue(this.platform.Characteristic.TargetHeatingCoolingState.HEAT); | ||
this.panasonicApi.setTankStatus(this.accessory.context.device.uniqueId, true); | ||
try { | ||
this.panasonicApi.setTankStatus(this.accessory.context.device.uniqueId, true); | ||
} | ||
catch (e) { | ||
this.platform.log.error(`Could not set tank status[${this.accessory.context.device.uniqueId}][${true}]: ${e}`); | ||
} | ||
await this.getReadings(true, true); | ||
@@ -319,0 +387,0 @@ }).onGet(async () => { |
{ | ||
"displayName": "Homebridge Panasonic Heat Pump", | ||
"name": "@hernas/homebridge-panasonic-heat-pump", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Allows basic control of Panasonic Heat Pump (AQUAREA)", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201944
3705