Skip to content

Commit

Permalink
fix(ui): filter battery null values (#3131)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>
Co-authored-by: AlCalzone <d.griesel@gmx.net>
  • Loading branch information
3 people committed Jun 20, 2023
1 parent 1415037 commit 4721f91
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ const observedCCProps: {
} = {
[CommandClasses.Battery]: {
level(node, value) {
const levels: number[] = node.batteryLevels || []
const levels: { [key: number]: number } = node.batteryLevels || {}

levels[value.endpoint] = value.value
node.batteryLevels = levels
node.minBatteryLevel = Math.min(...levels)
node.minBatteryLevel = Math.min(...Object.values(levels))

this.emitNodeUpdate(node, {
batteryLevels: levels,
Expand Down Expand Up @@ -470,7 +470,7 @@ export type ZUINode = {
inited: boolean
healProgress?: HealNodeStatus | undefined
minBatteryLevel?: number
batteryLevels?: number[]
batteryLevels?: { [key: number]: number }
firmwareUpdate?: FirmwareUpdateProgress
firmwareCapabilities?: FirmwareUpdateCapabilities
eventsQueue: NodeEvent[]
Expand Down
7 changes: 2 additions & 5 deletions src/components/nodes-table/SmartView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ import {
} from '@mdi/js'
import { mapState } from 'pinia'
import useBaseStore from '../../stores/base.js'
import { jsonToList } from '../../lib/utils.js'
import { getBatteryDescription, jsonToList } from '../../lib/utils.js'
export default {
props: {
Expand Down Expand Up @@ -505,10 +505,7 @@ export default {
icon = mdiPowerPlug
description = 'Main power source'
} else {
description = Array.isArray(node.batteryLevels)
? 'All battery levels: ' +
node.batteryLevels.map((v) => `${v}%`).join(',')
: 'Unknown battery level'
description = getBatteryDescription(node)
if (level <= 10) {
icon = mdiBatteryAlertVariantOutline
iconStyle = `color: ${colors.red.base}`
Expand Down
6 changes: 2 additions & 4 deletions src/components/nodes-table/nodes-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
mdiSleep,
} from '@mdi/js'
import useBaseStore from '../../stores/base.js'
import { getBatteryDescription } from '../../lib/utils.js'

export default {
props: {
Expand Down Expand Up @@ -273,10 +274,7 @@ export default {
description = 'mains-powered'
} else {
label = `${level}%`
description = Array.isArray(node.batteryLevels)
? 'All battery levels: ' +
node.batteryLevels.map((v) => `${v}%`).join(',')
: 'Unknown battery level'
description = getBatteryDescription(node)
if (level <= 10) {
icon = mdiBatteryAlertVariantOutline
iconStyle = `color: ${colors.red.base}`
Expand Down
9 changes: 9 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,12 @@ export function arraysEqual(a, b) {

return true
}

export function getBatteryDescription(node) {
return typeof node.batteryLevels !== 'undefined'
? 'All battery levels: ' +
Object.values(node.batteryLevels)
.map((v) => `${v}%`)
.join(', ')
: 'Unknown battery level'
}

0 comments on commit 4721f91

Please sign in to comment.