Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Zalmanski committed Apr 25, 2024
1 parent 18b4732 commit 22b5eaa
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/nuos/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
OperationMode,
type PostData,
type PostSettings,
type ReportData,
} from '../../ariston/types'
import type AristonApp from '../../app'
import { Device } from 'homey'
Expand Down Expand Up @@ -64,15 +63,15 @@ const convertToDate = (days: number): string | null =>
: null

const getEnergyData = (
data: ReportData,
histogramData: readonly HistogramData[],
seriesName: HistogramData['series'],
): HistogramData | undefined => {
const histogramData = data.data.asKwhRaw.histogramData.filter(
({ tab, period }) =>
tab === 'ConsumedElectricity' && period === 'CurrentDay',
)
return histogramData.find(({ series }) => series === seriesName)
}
): HistogramData | undefined =>
histogramData
.filter(
({ tab, period }) =>
tab === 'ConsumedElectricity' && period === 'CurrentDay',
)
.find(({ series }) => series === seriesName)

const getEnergy = (energyData: HistogramData | undefined): number =>
energyData ?
Expand Down Expand Up @@ -417,9 +416,10 @@ class NuosDevice extends Device {

async #plantMetering(): Promise<void> {
try {
const { data } = await this.#aristonAPI.plantMetering(this.#id)
const energyHpData = getEnergyData(data, 'DhwHp')
const energyResistorData = getEnergyData(data, 'DhwResistor')
const { histogramData } = (await this.#aristonAPI.plantMetering(this.#id))
.data.data.asKwhRaw
const energyHpData = getEnergyData(histogramData, 'DhwHp')
const energyResistorData = getEnergyData(histogramData, 'DhwResistor')
await this.#setPowerValues(
getPower(energyHpData),
getPower(energyResistorData),
Expand Down

0 comments on commit 22b5eaa

Please sign in to comment.