Switch true/false conditionals to boolean

This commit is contained in:
tsightler
2023-08-28 21:39:42 -04:00
parent 7e2ab22797
commit 19e3dcc1a3
16 changed files with 44 additions and 44 deletions

View File

@@ -31,7 +31,7 @@ export default class BaseStation extends RingSocketDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
if (this.entity.hasOwnProperty('volume')) { if (this.entity.hasOwnProperty('volume')) {
const currentVolume = (this.device.data.volume && !isNaN(this.device.data.volume) ? Math.round(100 * this.device.data.volume) : 0) const currentVolume = (this.device.data.volume && !isNaN(this.device.data.volume) ? Math.round(100 * this.device.data.volume) : 0)

View File

@@ -66,8 +66,7 @@ export default class BeamOutdoorPlug extends RingSocketDevice {
case 'on': case 'on':
case 'off': { case 'off': {
const duration = 32767 const duration = 32767
const on = command === 'on' ? true : false const data = Boolean(command === 'on') ? { lightMode: 'on', duration } : { lightMode: 'default' }
const data = on ? { lightMode: 'on', duration } : { lightMode: 'default' }
this[outletId].sendCommand('light-mode.set', data) this[outletId].sendCommand('light-mode.set', data)
break; break;
} }

View File

@@ -123,11 +123,10 @@ export default class Beam extends RingSocketDevice {
case 'on': case 'on':
case 'off': { case 'off': {
const duration = this.data.beam_duration ? Math.min(this.data.beam_duration, 32767) : undefined 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) { if (this.isLightGroup && this.groupId) {
this.device.location.setLightGroup(this.groupId, on, duration) this.device.location.setLightGroup(this.groupId, Boolean(command === 'on'), duration)
} else { } 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) this.device.sendCommand('light-mode.set', data)
} }
break; break;

View File

@@ -82,7 +82,7 @@ export default class BinarySensor extends RingSocketDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
const contactState = this.device.data.faulted ? 'ON' : 'OFF' const contactState = this.device.data.faulted ? 'ON' : 'OFF'
this.mqttPublish(this.entity[this.entityName].state_topic, contactState) this.mqttPublish(this.entity[this.entityName].state_topic, contactState)
this.publishBypassModeState(isPublish) this.publishBypassModeState(isPublish)

View File

@@ -12,8 +12,8 @@ export default class Camera extends RingPolledDevice {
const savedState = this.getSavedState() const savedState = this.getSavedState()
this.hasBattery1 = this.device.data.hasOwnProperty('battery_voltage') ? true : false this.hasBattery1 = Boolean(this.device.data.hasOwnProperty('battery_voltage'))
this.hasBattery2 = this.device.data.hasOwnProperty('battery_voltage_2') ? true : false this.hasBattery2 = Boolean(this.device.data.hasOwnProperty('battery_voltage_2'))
this.hevcEnabled = this.device.data?.settings?.video_settings?.hevc_enabled this.hevcEnabled = this.device.data?.settings?.video_settings?.hevc_enabled
? 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: [ options: [
...this.device.isDoorbot ...this.device.isDoorbot
? [ 'Ding 1', 'Ding 2', 'Ding 3', 'Ding 4', 'Ding 5', ? [ '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', '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', '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', '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 attributes: true
}, },
@@ -324,7 +328,7 @@ export default class Camera extends RingPolledDevice {
const lastMotionDate = lastMotionEvent?.start_time ? new Date(lastMotionEvent.start_time) : false 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 = lastMotionDate ? Math.floor(lastMotionDate/1000) : 0
this.data.motion.last_ding_time = lastMotionDate ? utils.getISOTime(lastMotionDate) : '' 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 this.data.motion.latestEventId = lastMotionEvent.event_id
// Try to get URL for most recent motion event, if it fails, assume there's no subscription // 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 // Publish camera capabilities and state and subscribe to events
async publishState(data) { async publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
this.publishPolledState(isPublish) this.publishPolledState(isPublish)
// Checks for new events or expired recording URL every 3 polling cycles (~1 minute) // 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`) this.debug(`Received ${dingKind} push notification, expires in ${this.data[dingKind].duration} seconds`)
// Is this a new Ding or refresh of active ding? // 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 this.data[dingKind].active_ding = true
// Update last_ding and expire time // 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 motion ding and snapshots on motion are enabled, publish a new snapshot
if (dingKind === 'motion') { 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) { if (this.data.snapshot.motion) {
this.refreshSnapshot('motion', ding.image_uuid) 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 eventSelect = this.data.event_select.state.split(' ')
const eventType = eventSelect[0].toLowerCase().replace('-', '_') const eventType = eventSelect[0].toLowerCase().replace('-', '_')
const eventNumber = eventSelect[1] 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() const urlExpired = this.data.event_select.recordingUrlExpire < Date.now()
let selectedEvent let selectedEvent
let recordingUrl = false let recordingUrl = false
@@ -1122,13 +1126,13 @@ export default class Camera extends RingPolledDevice {
// Set switch target state on received MQTT command message // Set switch target state on received MQTT command message
async setLightState(message) { async setLightState(message) {
this.debug(`Received set light state ${message}`) this.debug(`Received set light state ${message}`)
const command = message.toUpperCase() const command = message.toLowerCase()
switch (command) { switch (command) {
case 'ON': case 'on':
case 'OFF': case 'off':
this.data.light.setTime = Math.floor(Date.now()/1000) 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.data.light.state = command
this.mqttPublish(this.entity.light.state_topic, this.data.light.state) this.mqttPublish(this.entity.light.state_topic, this.data.light.state)
break; break;
@@ -1145,7 +1149,7 @@ export default class Camera extends RingPolledDevice {
switch (command) { switch (command) {
case 'on': case 'on':
case 'off': case 'off':
await this.device.setSiren(command === 'on' ? true : false) await this.device.setSiren(Boolean(command === 'on'))
break; break;
default: default:
this.debug('Received unknown command for siren') this.debug('Received unknown command for siren')
@@ -1162,7 +1166,7 @@ export default class Camera extends RingPolledDevice {
case 'off': case 'off':
await this.device.setDeviceSettings({ await this.device.setDeviceSettings({
"motion_settings": { "motion_settings": {
"motion_detection_enabled": command === 'on' ? true : false "motion_detection_enabled": Boolean(command === 'on')
} }
}) })
break; break;
@@ -1189,10 +1193,10 @@ export default class Camera extends RingPolledDevice {
case 'off': case 'off':
await this.device.restClient.request({ await this.device.restClient.request({
method: 'PUT', 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.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; break;
default: default:
this.debug('Received unknown command for motion warning state') this.debug('Received unknown command for motion warning state')

View File

@@ -87,7 +87,7 @@ export default class Chime extends RingPolledDevice {
} }
publishState(data) { 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 // Polled states are published only if value changes or it's a device publish
const volumeState = this.device.data.settings.volume const volumeState = this.device.data.settings.volume
@@ -248,14 +248,14 @@ export default class Chime extends RingPolledDevice {
async setNightlightState(message) { async setNightlightState(message) {
this.debug(`Received set nightlight enabled ${message}`) this.debug(`Received set nightlight enabled ${message}`)
const command = message.toUpperCase() const command = message.toLowerCase()
switch(command) { switch(command) {
case 'ON': case 'on':
case 'OFF': case 'off':
this.data.nightlight.set_time = Math.floor(Date.now()/1000) this.data.nightlight.set_time = Math.floor(Date.now()/1000)
await this.setDeviceSettings({ await this.setDeviceSettings({
"night_light_settings": { "night_light_settings": {
"light_sensor_enabled": command === 'ON' ? true : false "light_sensor_enabled": Boolean(command === 'on')
} }
}) })
this.data.nightlight.enabled = command this.data.nightlight.enabled = command

View File

@@ -69,8 +69,7 @@ export default class Fan extends RingSocketDevice {
switch(command) { switch(command) {
case 'on': case 'on':
case 'off': case 'off':
const on = (command === 'on') ? true : false this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
this.device.setInfo({ device: { v1: { on } } })
break; break;
default: default:
this.debug('Received invalid command for fan!') this.debug('Received invalid command for fan!')

View File

@@ -71,7 +71,7 @@ export default class Lock extends RingPolledDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
this.publishDingState(isPublish) this.publishDingState(isPublish)
this.publishLockState(isPublish) this.publishLockState(isPublish)

View File

@@ -43,7 +43,7 @@ export default class Keypad extends RingSocketDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
if (isPublish) { if (isPublish) {
// Eventually remove this but for now this attempts to delete the old light component based volume control from Home Assistant // 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) this.mqttPublish(`homeassistant/light/${this.locationId}/${this.deviceId}_audio/config`, '', false)

View File

@@ -18,7 +18,7 @@ export default class ModesPanel extends RingPolledDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
const mode = (isPublish) ? this.device.location.getLocationMode() : data const mode = (isPublish) ? this.device.location.getLocationMode() : data
// Publish device state if it's changed from prior state // Publish device state if it's changed from prior state
if (this.data.currentMode !== mode || isPublish) { if (this.data.currentMode !== mode || isPublish) {

View File

@@ -41,8 +41,7 @@ export default class MultiLevelSwitch extends RingSocketDevice {
switch(command) { switch(command) {
case 'on': case 'on':
case 'off': { case 'off': {
const on = (command === 'on') ? true : false this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
this.device.setInfo({ device: { v1: { on } } })
break; break;
} }
default: default:

View File

@@ -185,7 +185,7 @@ export default class SecurityPanel extends RingSocketDevice {
} }
publishState(data) { 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 // Publish alarm states for events not handled by processAlarmMode() as well as
// any explicit publish requests // any explicit publish requests

View File

@@ -24,7 +24,7 @@ export default class Siren extends RingSocketDevice {
} }
publishState(data) { publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
if (isPublish) { if (isPublish) {
// Eventually remove this but for now this attempts to delete the old siren binary_sensor // 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) 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') { if (this.device.data.deviceType === 'siren.outdoor-strobe') {
this.device.sendCommand((command ==='on') ? 'siren-test.start' : 'siren-test.stop') this.device.sendCommand((command ==='on') ? 'siren-test.start' : 'siren-test.stop')
} else { } else {
this.device.setInfo({ device: { v1: { on: (command === 'on') ? true : false } } }) this.device.setInfo({ device: { v1: { on: Boolean(command === 'on') } } })
} }
break; break;
default: default:

View File

@@ -36,7 +36,7 @@ export default class Switch extends RingSocketDevice {
case 'on': case 'on':
case 'off': case 'off':
this.debug(`Received set switch state ${message}`) 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; break;
default: default:
this.debug(`Received invalid switch state command`) this.debug(`Received invalid switch state command`)

View File

@@ -71,7 +71,7 @@ export default class Thermostat extends RingSocketDevice {
} }
async publishState(data) { async publishState(data) {
const isPublish = data === undefined ? true : false const isPublish = Boolean(data === undefined)
this.publishModeAndSetpoints() this.publishModeAndSetpoints()
this.mqttPublish(this.entity.thermostat.fan_mode_state_topic, this.data.fanMode()) this.mqttPublish(this.entity.thermostat.fan_mode_state_topic, this.data.fanMode())

View File

@@ -86,7 +86,7 @@ export default new class TokenApp {
debug('Username/Password was accepted, waiting for 2FA code to be entered.') debug('Username/Password was accepted, waiting for 2FA code to be entered.')
res.sendFile('code.html', {root: webdir}) res.sendFile('code.html', {root: webdir})
} else { } 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)) debug(chalk.red(errmsg))
res.cookie('error', errmsg, { maxAge: 1000, encode: String }) res.cookie('error', errmsg, { maxAge: 1000, encode: String })
res.sendFile('account.html', {root: webdir}) res.sendFile('account.html', {root: webdir})