mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-10-06 01:07:03 +08:00
Switch true/false conditionals to boolean
This commit is contained in:
@@ -31,7 +31,7 @@ export default class BaseStation extends RingSocketDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
|
||||
if (this.entity.hasOwnProperty('volume')) {
|
||||
const currentVolume = (this.device.data.volume && !isNaN(this.device.data.volume) ? Math.round(100 * this.device.data.volume) : 0)
|
||||
|
@@ -66,8 +66,7 @@ export default class BeamOutdoorPlug extends RingSocketDevice {
|
||||
case 'on':
|
||||
case 'off': {
|
||||
const duration = 32767
|
||||
const on = command === 'on' ? true : false
|
||||
const data = on ? { lightMode: 'on', duration } : { lightMode: 'default' }
|
||||
const data = Boolean(command === 'on') ? { lightMode: 'on', duration } : { lightMode: 'default' }
|
||||
this[outletId].sendCommand('light-mode.set', data)
|
||||
break;
|
||||
}
|
||||
|
@@ -123,11 +123,10 @@ export default class Beam extends RingSocketDevice {
|
||||
case 'on':
|
||||
case 'off': {
|
||||
const duration = this.data.beam_duration ? Math.min(this.data.beam_duration, 32767) : undefined
|
||||
const on = command === 'on' ? true : false
|
||||
if (this.isLightGroup && this.groupId) {
|
||||
this.device.location.setLightGroup(this.groupId, on, duration)
|
||||
this.device.location.setLightGroup(this.groupId, Boolean(command === 'on'), duration)
|
||||
} else {
|
||||
const data = on ? { lightMode: 'on', duration } : { lightMode: 'default' }
|
||||
const data = Boolean(command === 'on') ? { lightMode: 'on', duration } : { lightMode: 'default' }
|
||||
this.device.sendCommand('light-mode.set', data)
|
||||
}
|
||||
break;
|
||||
|
@@ -82,7 +82,7 @@ export default class BinarySensor extends RingSocketDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
const contactState = this.device.data.faulted ? 'ON' : 'OFF'
|
||||
this.mqttPublish(this.entity[this.entityName].state_topic, contactState)
|
||||
this.publishBypassModeState(isPublish)
|
||||
|
@@ -12,8 +12,8 @@ export default class Camera extends RingPolledDevice {
|
||||
|
||||
const savedState = this.getSavedState()
|
||||
|
||||
this.hasBattery1 = this.device.data.hasOwnProperty('battery_voltage') ? true : false
|
||||
this.hasBattery2 = this.device.data.hasOwnProperty('battery_voltage_2') ? true : false
|
||||
this.hasBattery1 = Boolean(this.device.data.hasOwnProperty('battery_voltage'))
|
||||
this.hasBattery2 = Boolean(this.device.data.hasOwnProperty('battery_voltage_2'))
|
||||
|
||||
this.hevcEnabled = this.device.data?.settings?.video_settings?.hevc_enabled
|
||||
? this.device.data.settings.video_settings.hevc_enabled
|
||||
@@ -135,15 +135,19 @@ export default class Camera extends RingPolledDevice {
|
||||
options: [
|
||||
...this.device.isDoorbot
|
||||
? [ 'Ding 1', 'Ding 2', 'Ding 3', 'Ding 4', 'Ding 5',
|
||||
'Ding 1 (Transcoded)', 'Ding 2 (Transcoded)', 'Ding 3 (Transcoded)', 'Ding 4 (Transcoded)', 'Ding 5 (Transcoded)'
|
||||
'Ding 1 (Transcoded)', 'Ding 2 (Transcoded)', 'Ding 3 (Transcoded)',
|
||||
'Ding 4 (Transcoded)', 'Ding 5 (Transcoded)'
|
||||
]
|
||||
: [],
|
||||
'Motion 1', 'Motion 2', 'Motion 3', 'Motion 4', 'Motion 5',
|
||||
'Motion 1 (Transcoded)', 'Motion 2 (Transcoded)', 'Motion 3 (Transcoded)', 'Motion 4 (Transcoded)', 'Motion 5 (Transcoded)',
|
||||
'Motion 1 (Transcoded)', 'Motion 2 (Transcoded)', 'Motion 3 (Transcoded)',
|
||||
'Motion 4 (Transcoded)', 'Motion 5 (Transcoded)',
|
||||
'Person 1', 'Person 2', 'Person 3', 'Person 4', 'Person 5',
|
||||
'Person 1 (Transcoded)', 'Person 2 (Transcoded)', 'Person 3 (Transcoded)', 'Person 4 (Transcoded)', 'Person 5 (Transcoded)',
|
||||
'Person 1 (Transcoded)', 'Person 2 (Transcoded)', 'Person 3 (Transcoded)',
|
||||
'Person 4 (Transcoded)', 'Person 5 (Transcoded)',
|
||||
'On-demand 1', 'On-demand 2', 'On-demand 3', 'On-demand 4', 'On-demand 5',
|
||||
'On-demand 1 (Transcoded)', 'On-demand 2 (Transcoded)', 'On-demand 3 (Transcoded)', 'On-demand 4 (Transcoded)', 'On-demand 5 (Transcoded)',
|
||||
'On-demand 1 (Transcoded)', 'On-demand 2 (Transcoded)', 'On-demand 3 (Transcoded)',
|
||||
'On-demand 4 (Transcoded)', 'On-demand 5 (Transcoded)',
|
||||
],
|
||||
attributes: true
|
||||
},
|
||||
@@ -324,7 +328,7 @@ export default class Camera extends RingPolledDevice {
|
||||
const lastMotionDate = lastMotionEvent?.start_time ? new Date(lastMotionEvent.start_time) : false
|
||||
this.data.motion.last_ding = lastMotionDate ? Math.floor(lastMotionDate/1000) : 0
|
||||
this.data.motion.last_ding_time = lastMotionDate ? utils.getISOTime(lastMotionDate) : ''
|
||||
this.data.motion.is_person = lastMotionEvent?.cv?.person_detected ? true : false
|
||||
this.data.motion.is_person = Boolean(lastMotionEvent?.cv?.person_detected)
|
||||
this.data.motion.latestEventId = lastMotionEvent.event_id
|
||||
|
||||
// Try to get URL for most recent motion event, if it fails, assume there's no subscription
|
||||
@@ -412,7 +416,7 @@ export default class Camera extends RingPolledDevice {
|
||||
|
||||
// Publish camera capabilities and state and subscribe to events
|
||||
async publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
this.publishPolledState(isPublish)
|
||||
|
||||
// Checks for new events or expired recording URL every 3 polling cycles (~1 minute)
|
||||
@@ -485,7 +489,7 @@ export default class Camera extends RingPolledDevice {
|
||||
this.debug(`Received ${dingKind} push notification, expires in ${this.data[dingKind].duration} seconds`)
|
||||
|
||||
// Is this a new Ding or refresh of active ding?
|
||||
const newDing = (!this.data[dingKind].active_ding) ? true : false
|
||||
const newDing = Boolean(!this.data[dingKind].active_ding)
|
||||
this.data[dingKind].active_ding = true
|
||||
|
||||
// Update last_ding and expire time
|
||||
@@ -495,7 +499,7 @@ export default class Camera extends RingPolledDevice {
|
||||
|
||||
// If motion ding and snapshots on motion are enabled, publish a new snapshot
|
||||
if (dingKind === 'motion') {
|
||||
this.data[dingKind].is_person = (ding.detection_type === 'human') ? true : false
|
||||
this.data[dingKind].is_person = Boolean(ding.detection_type === 'human')
|
||||
if (this.data.snapshot.motion) {
|
||||
this.refreshSnapshot('motion', ding.image_uuid)
|
||||
}
|
||||
@@ -927,7 +931,7 @@ export default class Camera extends RingPolledDevice {
|
||||
const eventSelect = this.data.event_select.state.split(' ')
|
||||
const eventType = eventSelect[0].toLowerCase().replace('-', '_')
|
||||
const eventNumber = eventSelect[1]
|
||||
const transcoded = eventSelect[2] === '(Transcoded)' ? true : false
|
||||
const transcoded = Boolean(eventSelect[2] === '(Transcoded)')
|
||||
const urlExpired = this.data.event_select.recordingUrlExpire < Date.now()
|
||||
let selectedEvent
|
||||
let recordingUrl = false
|
||||
@@ -1122,13 +1126,13 @@ export default class Camera extends RingPolledDevice {
|
||||
// Set switch target state on received MQTT command message
|
||||
async setLightState(message) {
|
||||
this.debug(`Received set light state ${message}`)
|
||||
const command = message.toUpperCase()
|
||||
const command = message.toLowerCase()
|
||||
|
||||
switch (command) {
|
||||
case 'ON':
|
||||
case 'OFF':
|
||||
case 'on':
|
||||
case 'off':
|
||||
this.data.light.setTime = Math.floor(Date.now()/1000)
|
||||
await this.device.setLight(command === 'ON' ? true : false)
|
||||
await this.device.setLight(Boolean(command === 'on'))
|
||||
this.data.light.state = command
|
||||
this.mqttPublish(this.entity.light.state_topic, this.data.light.state)
|
||||
break;
|
||||
@@ -1145,7 +1149,7 @@ export default class Camera extends RingPolledDevice {
|
||||
switch (command) {
|
||||
case 'on':
|
||||
case 'off':
|
||||
await this.device.setSiren(command === 'on' ? true : false)
|
||||
await this.device.setSiren(Boolean(command === 'on'))
|
||||
break;
|
||||
default:
|
||||
this.debug('Received unknown command for siren')
|
||||
@@ -1162,7 +1166,7 @@ export default class Camera extends RingPolledDevice {
|
||||
case 'off':
|
||||
await this.device.setDeviceSettings({
|
||||
"motion_settings": {
|
||||
"motion_detection_enabled": command === 'on' ? true : false
|
||||
"motion_detection_enabled": Boolean(command === 'on')
|
||||
}
|
||||
})
|
||||
break;
|
||||
@@ -1189,10 +1193,10 @@ export default class Camera extends RingPolledDevice {
|
||||
case 'off':
|
||||
await this.device.restClient.request({
|
||||
method: 'PUT',
|
||||
url: this.device.doorbotUrl(`motion_announcement?motion_announcement=${command === 'on' ? 'true' : 'false'}`)
|
||||
url: this.device.doorbotUrl(`motion_announcement?motion_announcement=${Boolean(command === 'on')}`)
|
||||
})
|
||||
this.mqttPublish(this.entity.motion_warning.state_topic, command === 'on' ? 'ON' : 'OFF')
|
||||
this.data.motion.warning_enabled = command === 'on' ? true : false
|
||||
this.data.motion.warning_enabled = Boolean(command === 'on')
|
||||
break;
|
||||
default:
|
||||
this.debug('Received unknown command for motion warning state')
|
||||
|
@@ -87,7 +87,7 @@ export default class Chime extends RingPolledDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
|
||||
// Polled states are published only if value changes or it's a device publish
|
||||
const volumeState = this.device.data.settings.volume
|
||||
@@ -248,14 +248,14 @@ export default class Chime extends RingPolledDevice {
|
||||
|
||||
async setNightlightState(message) {
|
||||
this.debug(`Received set nightlight enabled ${message}`)
|
||||
const command = message.toUpperCase()
|
||||
const command = message.toLowerCase()
|
||||
switch(command) {
|
||||
case 'ON':
|
||||
case 'OFF':
|
||||
case 'on':
|
||||
case 'off':
|
||||
this.data.nightlight.set_time = Math.floor(Date.now()/1000)
|
||||
await this.setDeviceSettings({
|
||||
"night_light_settings": {
|
||||
"light_sensor_enabled": command === 'ON' ? true : false
|
||||
"light_sensor_enabled": Boolean(command === 'on')
|
||||
}
|
||||
})
|
||||
this.data.nightlight.enabled = command
|
||||
|
@@ -69,8 +69,7 @@ export default class Fan extends RingSocketDevice {
|
||||
switch(command) {
|
||||
case 'on':
|
||||
case 'off':
|
||||
const on = (command === 'on') ? true : false
|
||||
this.device.setInfo({ device: { v1: { on } } })
|
||||
this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
|
||||
break;
|
||||
default:
|
||||
this.debug('Received invalid command for fan!')
|
||||
|
@@ -71,7 +71,7 @@ export default class Lock extends RingPolledDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
|
||||
this.publishDingState(isPublish)
|
||||
this.publishLockState(isPublish)
|
||||
|
@@ -43,7 +43,7 @@ export default class Keypad extends RingSocketDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
if (isPublish) {
|
||||
// Eventually remove this but for now this attempts to delete the old light component based volume control from Home Assistant
|
||||
this.mqttPublish(`homeassistant/light/${this.locationId}/${this.deviceId}_audio/config`, '', false)
|
||||
|
@@ -18,7 +18,7 @@ export default class ModesPanel extends RingPolledDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
const mode = (isPublish) ? this.device.location.getLocationMode() : data
|
||||
// Publish device state if it's changed from prior state
|
||||
if (this.data.currentMode !== mode || isPublish) {
|
||||
|
@@ -41,8 +41,7 @@ export default class MultiLevelSwitch extends RingSocketDevice {
|
||||
switch(command) {
|
||||
case 'on':
|
||||
case 'off': {
|
||||
const on = (command === 'on') ? true : false
|
||||
this.device.setInfo({ device: { v1: { on } } })
|
||||
this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@@ -185,7 +185,7 @@ export default class SecurityPanel extends RingSocketDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
|
||||
// Publish alarm states for events not handled by processAlarmMode() as well as
|
||||
// any explicit publish requests
|
||||
|
@@ -24,7 +24,7 @@ export default class Siren extends RingSocketDevice {
|
||||
}
|
||||
|
||||
publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
if (isPublish) {
|
||||
// Eventually remove this but for now this attempts to delete the old siren binary_sensor
|
||||
this.mqttPublish('homeassistant/binary_sensor/'+this.locationId+'/'+this.deviceId+'_siren/config', '', false)
|
||||
@@ -64,7 +64,7 @@ export default class Siren extends RingSocketDevice {
|
||||
if (this.device.data.deviceType === 'siren.outdoor-strobe') {
|
||||
this.device.sendCommand((command ==='on') ? 'siren-test.start' : 'siren-test.stop')
|
||||
} else {
|
||||
this.device.setInfo({ device: { v1: { on: (command === 'on') ? true : false } } })
|
||||
this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@@ -36,7 +36,7 @@ export default class Switch extends RingSocketDevice {
|
||||
case 'on':
|
||||
case 'off':
|
||||
this.debug(`Received set switch state ${message}`)
|
||||
this.device.setInfo({ device: { v1: { on: (command === 'on') ? true : false } } })
|
||||
this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
|
||||
break;
|
||||
default:
|
||||
this.debug(`Received invalid switch state command`)
|
||||
|
@@ -71,7 +71,7 @@ export default class Thermostat extends RingSocketDevice {
|
||||
}
|
||||
|
||||
async publishState(data) {
|
||||
const isPublish = data === undefined ? true : false
|
||||
const isPublish = Boolean(data === undefined)
|
||||
|
||||
this.publishModeAndSetpoints()
|
||||
this.mqttPublish(this.entity.thermostat.fan_mode_state_topic, this.data.fanMode())
|
||||
|
@@ -86,7 +86,7 @@ export default new class TokenApp {
|
||||
debug('Username/Password was accepted, waiting for 2FA code to be entered.')
|
||||
res.sendFile('code.html', {root: webdir})
|
||||
} else {
|
||||
const errmsg = error.message ? error.message : 'Unknown error, please check your credentials and try again.'
|
||||
const errmsg = error.message ? error.message : 'Null response, you may be temporarily throttled/blocked. Please shut down ring-mqtt and try again in a few hours.'
|
||||
debug(chalk.red(errmsg))
|
||||
res.cookie('error', errmsg, { maxAge: 1000, encode: String })
|
||||
res.sendFile('account.html', {root: webdir})
|
||||
|
Reference in New Issue
Block a user