mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-09-26 21:01:12 +08:00

* Use MQTT for start-stream debug messages * Fix ANSI colors * Refactor event URL management * Fix subscription detection * Improve event URL expiry handling by parsing Amazon S3 expire time * Convert to ESM/replace colors with chalk * Force colors for chalk * Migrate to ESM * Fix stop of keepalive stream * Add transcoded event selections * Update event URL on raw/trancoded toggle * Switch to per-camera livecall threads * Customized WebRTC functions Mostly copied from ring-client-api with port to pure Javascript, removal of unneeded features and additional debugging modified for use as worker thread with ring-mqtt. Allows easier testing with updated Werift versions. * Add nightlight enable/disable * Include nightlight state as attribute * Only pro versions have nightlight * Tweak battery level reporting for dual battery cameras * Release 5.1.0
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import RingSocketDevice from './base-socket-device.js'
|
|
|
|
export default class Switch extends RingSocketDevice {
|
|
constructor(deviceInfo) {
|
|
super(deviceInfo, 'alarm')
|
|
this.deviceData.mdl = (this.device.data.categoryId === 2) ? 'Light' : 'Switch'
|
|
this.component = (this.device.data.categoryId === 2) ? 'light' : 'switch'
|
|
|
|
this.entity[this.component] = {
|
|
component: this.component,
|
|
isLegacyEntity: true // Legacy compatibility
|
|
}
|
|
}
|
|
|
|
publishState() {
|
|
this.mqttPublish(this.entity[this.component].state_topic, this.device.data.on ? "ON" : "OFF")
|
|
this.publishAttributes()
|
|
}
|
|
|
|
// Process messages from MQTT command topic
|
|
processCommand(command, message) {
|
|
switch (command) {
|
|
case 'switch/command':
|
|
case 'light/command':
|
|
this.setSwitchState(message)
|
|
break;
|
|
default:
|
|
this.debug(`Received message to unknown command topic: ${command}`)
|
|
}
|
|
}
|
|
|
|
// Set switch target state on received MQTT command message
|
|
setSwitchState(message) {
|
|
const command = message.toLowerCase()
|
|
switch(command) {
|
|
case 'on':
|
|
case 'off':
|
|
this.debug(`Received set switch state ${message}`)
|
|
this.device.setInfo({ device: { v1: { on: (command === 'on') ? true : false } } })
|
|
break;
|
|
default:
|
|
this.debug(`Received invalid switch state command`)
|
|
}
|
|
}
|
|
}
|