-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #889 from tsightler/dev
Release v5.7.1
- Loading branch information
Showing
8 changed files
with
218 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import RingSocketDevice from './base-socket-device.js' | ||
|
||
export default class Valve extends RingSocketDevice { | ||
constructor(deviceInfo) { | ||
super(deviceInfo, 'alarm') | ||
this.deviceData.mdl = 'Water Valve' | ||
|
||
this.entity.valve = { | ||
component: 'valve' | ||
} | ||
} | ||
|
||
publishState() { | ||
let valveState | ||
switch(this.device.data.valveState) { | ||
case 'open': | ||
case 'closed': | ||
valveState = this.device.data.valveState | ||
break; | ||
default: | ||
// HA doesn't support broken state so setting unknown state is the best we can do | ||
valveState = 'None' | ||
} | ||
this.mqttPublish(this.entity.valve.state_topic, valveState) | ||
this.publishAttributes() | ||
} | ||
|
||
// Process messages from MQTT command topic | ||
processCommand(command, message) { | ||
switch (command) { | ||
case 'valve/command': | ||
this.setValveState(message) | ||
break; | ||
default: | ||
this.debug(`Received message to unknown command topic: ${command}`) | ||
} | ||
} | ||
|
||
// Set valve target state on received MQTT command message | ||
setValveState(message) { | ||
this.debug(`Received set valve state ${message}`) | ||
const command = message.toLowerCase() | ||
switch(command) { | ||
case 'open': | ||
case 'close': { | ||
let valveState = command === 'open' ? 'opening' : 'closing' | ||
this.mqttPublish(this.entity.valve.state_topic, valveState) | ||
this.device.sendCommand(`valve.${command}`) | ||
break; | ||
} | ||
default: | ||
this.debug('Received invalid command for valve') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.