Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
haywirecoder authored Sep 14, 2024
1 parent 4103f42 commit e8b02d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
23 changes: 15 additions & 8 deletions accessories/optionSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ const HealthTestRunTime = 240000;
const FLO_VALVE_OPEN = 'open';
const FLO_VALVE_CLOSE = 'closed';


class FloOptionSwitch {
constructor(flo, device, log, config, Service, Characteristic, UUIDGen) {
constructor(flo, device, log, config, Service, Characteristic, UUIDGen, deviceIndex) {
this.Characteristic = Characteristic;
this.Service = Service;
this.model = device.deviceModel;
this.name = device.name;
this.deviceIndex = deviceIndex;
this.serialNumber = device.serialNumber;
this.log = log;
this.switchType = config.switchType;
Expand All @@ -30,9 +32,10 @@ class FloOptionSwitch {
refreshState(eventData)
{
this.log.debug(`Switch updated requested: ` , eventData);
this.valveStatus = eventData.device.valveCurrentState;
this.valveStatus = eventData.device.valveGlobalState;
this.gallonsPerMin = eventData.device.gpm;
this.pressure = eventData.device.psi;

}

setAccessory(accessory) {
Expand Down Expand Up @@ -109,19 +112,23 @@ class FloOptionSwitch {
return callback(null, currentValve);
}

async setAuxSwitch(value,callback) {
async setAuxSwitch(value,callback) {
var switchService = this.accessory.getService(this.Service.Switch);
if (this.IsValveControlEnabled) {
if (this.value) {
this.flo.setValve(this.deviceid , FLO_VALVE_OPEN)
if (value) {
await this.flo.setValve(this.deviceid , FLO_VALVE_OPEN, this.deviceIndex)
this.valveStatus = FLO_VALVE_OPEN;
}
else {
this.flo.setValve(this.deviceid , FLO_VALVE_CLOSE)
await this.flo.setValve(this.deviceid , FLO_VALVE_CLOSE, this.deviceIndex)
this.valveStatus = FLO_VALVE_CLOSE;

}
// setTimeout(function () {this.flo.refreshDevice(this.deviceIndex)}.bind(this),30000);
}
else {
this.log.warn("Smart Water Shutoff: Valve control is disabled in Homebridge.");
this.log.warn("Smart Water Shutoff: Valve control is disabled in Homebridge.");
// Get the button service and updated switch soon after set function is complete
var switchService = this.accessory.getService(this.Service.Switch);
var currentValve = this.VALVE_INUSE_STATE[this.valveStatus];
setTimeout(function () {switchService.updateCharacteristic(this.Characteristic.On,currentValve)}.bind(this),2000);
}
Expand Down
11 changes: 6 additions & 5 deletions accessories/smartWater.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const FLO_VALVE_CLOSE = 'closed';

class FloSmartWater {

constructor(flo, device, log, config, Service, Characteristic, UUIDGen) {
constructor(flo, device, log, config, Service, Characteristic, UUIDGen, deviceIndex) {
this.Characteristic = Characteristic;
this.Service = Service;
this.log = log;
this.name = device.name;
this.deviceIndex = deviceIndex;
this.model = device.deviceModel;
this.serialNumber = device.serialNumber;
this.location = device.location;
Expand Down Expand Up @@ -71,7 +72,7 @@ class FloSmartWater {
refreshState(eventData)
{
this.log.debug(`Device updated requested: ` , eventData);
this.valveStatus = eventData.device.valveCurrentState;
this.valveStatus = eventData.device.valveGlobalState;
this.gallonsPerMin = eventData.device.gpm;
this.isInstalled = eventData.device.isInstalled;
this.pressure = eventData.device.psi;
Expand Down Expand Up @@ -213,15 +214,15 @@ async getValveActive(callback) {

// Handle requests to set the "Active" characteristic
async setValveActive(homekitState, callback) {
this.log.info("Trigger Set Valve Active");
this.log.debug("Trigger Set Valve Active");
if (this.IsValveControlEnabled) {
if (homekitState == this.Characteristic.Active.ACTIVE)
{
this.flo.setValve(this.deviceid , FLO_VALVE_OPEN)
this.flo.setValve(this.deviceid , FLO_VALVE_OPEN, this.deviceIndex)
this.valveStatus = FLO_VALVE_OPEN;
}
else {
this.flo.setValve(this.deviceid , FLO_VALVE_CLOSE)
this.flo.setValve(this.deviceid , FLO_VALVE_CLOSE, this.deviceIndex)
this.valveStatus = FLO_VALVE_CLOSE;
}
} else {
Expand Down
30 changes: 15 additions & 15 deletions accessories/waterSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class FloWaterSensor {
this.Service = Service;
this.serialNumber = device.serialNumber;
this.model = device.deviceModel;
this.suppressNoticationFlag = config.surpressWaterNotification || false;
this.clearOnNoLeak = config.clearOnNoLeak ?? false;
this.log = log;
this.name = device.name;
this.version = device.version;
this.currentTemperature = device.temperature || -180;
this.currentHumidity = device.humidity || 0.0;
this.leakDetected = false;
this.currentTemperature = device.temperature ?? -180;
this.currentHumidity = device.humidity ?? 0.0;
this.leakDected = false;
this.isConnected = device.isConnected;
this.batteryLevel = device.batterylevel || 0;
this.batteryLevel = device.batterylevel ?? 0;
this.IsTemperatureAndHumidity = config.showTemperatureAndHumidity ?? true;
this.flo = flo;
this.deviceid = device.deviceid.toString();
Expand All @@ -27,10 +27,10 @@ class FloWaterSensor {
refreshState(eventData)
{
this.log.debug(`Device updated requested: ` , eventData);
this.currentTemperature = eventData.device.temperature || -180;
this.currentHumidity = eventData.device.humidity || 0.0;
this.batteryLevel = eventData.device.batterylevel || 0;
var leakDetectedOnCritical = false;
this.currentTemperature = eventData.device.temperature ?? -180;
this.currentHumidity = eventData.device.humidity ?? 0.0;
this.batteryLevel = eventData.device.batterylevel ?? 0;
var leakdectedOnCritical = false;

// Is device offline?
if ((eventData.device.offline != 0 ) || (eventData.device.isConnected == false ))
Expand All @@ -39,19 +39,19 @@ class FloWaterSensor {
this.systemTampered = this.Characteristic.StatusTampered.NOT_TAMPERED;

// Should leak clear once water is not longer detect ?
if (this.suppressNoticationFlag == false)
if(eventData.device.notifications.criticalCount > 0) leakDetectedOnCritical = true;
if (this.clearOnNoLeak == false)
if(eventData.device.notifications.criticalCount > 0) leakdectedOnCritical = true;

// get the leak sensor service to update status
const leakService = this.accessory.getService(this.Service.LeakSensor);
if(leakDetectedOnCritical || eventData.device.waterdetect)
if((leakdectedOnCritical) || (eventData.device.waterdetect))
{
this.leakDetected = true;
this.leakDected = true;
leakService.updateCharacteristic(this.Characteristic.LeakDetected, this.Characteristic.LeakDetected.LEAK_DETECTED);
leakService.updateCharacteristic(this.Characteristic.StatusTampered, this.systemTampered);
}
else {
this.leakDetected = false;
this.leakDected = false;
leakService.updateCharacteristic(this.Characteristic.LeakDetected, this.Characteristic.LeakDetected.LEAK_NOT_DETECTED);
leakService.updateCharacteristic(this.Characteristic.StatusTampered, this.systemTampered);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ class FloWaterSensor {
}

async getLeakStatus(callback) {
if (this.leakDetected)
if (this.leakDected)
{
return callback(null, this.Characteristic.LeakDetected.LEAK_DETECTED);
} else {
Expand Down

0 comments on commit e8b02d9

Please sign in to comment.