From b72c5031bcb1c9644cacaf81d5ce5d2008bae6f6 Mon Sep 17 00:00:00 2001 From: Olivier Zalmanski <88216225+OlivierZal@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:49:59 +0100 Subject: [PATCH] bump melcloud-api --- app.mts | 19 +++++++++++-------- bases/device.mts | 14 +++++--------- bases/report.mts | 4 ++-- lib/getBuildings.mts | 12 ++++++------ package-lock.json | 8 ++++---- package.json | 2 +- types/common.mts | 8 ++++---- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/app.mts b/app.mts index adf3fdd5..b062e10b 100644 --- a/app.mts +++ b/app.mts @@ -9,18 +9,18 @@ import { MELCloudAPI, OperationMode, Vertical, - type AreaFacade, - type BuildingFacade, - type DeviceFacadeAny, type DeviceType, type ErrorLog, type ErrorLogQuery, - type FloorFacade, type FrostProtectionData, type FrostProtectionQuery, type GroupAtaState, type HolidayModeData, type HolidayModeQuery, + type IBuildingFacade, + type IDeviceFacade, + type IFacade, + type ISuperDeviceFacade, type ListDeviceDataAta, type LoginCredentials, } from '@olivierzal/melcloud-api' @@ -284,15 +284,18 @@ export default class MELCloudApp extends Homey.App { return this.#facadeManager.getErrors(query) } - public getFacade(zoneType: 'devices', id: number | string): DeviceFacadeAny + public getFacade( + zoneType: 'devices', + id: number | string, + ): IDeviceFacade public getFacade( - zoneType: 'areas' | 'buildings' | 'floors', + zoneType: Exclude, id: number | string, - ): AreaFacade | BuildingFacade | FloorFacade + ): IBuildingFacade | ISuperDeviceFacade public getFacade( zoneType: keyof typeof zoneModel, id: number | string, - ): AreaFacade | BuildingFacade | DeviceFacadeAny | FloorFacade { + ): IFacade { const instance = zoneModel[zoneType].getById(Number(id)) if (!instance) { throw new Error( diff --git a/bases/device.mts b/bases/device.mts index 352358f5..dcfa19c8 100644 --- a/bases/device.mts +++ b/bases/device.mts @@ -5,8 +5,8 @@ import { isTotalEnergyKey } from '../lib/isTotalEnergyKey.mjs' import { withTimers } from '../lib/withTimers.mjs' import type { - DeviceFacade, DeviceType, + IDeviceFacade, ListDevice, UpdateDeviceData, } from '@olivierzal/melcloud-api' @@ -55,7 +55,7 @@ export abstract class BaseMELCloudDevice< #setCapabilityTagMapping: Partial = {} - #device?: DeviceFacade[T] + #device?: IDeviceFacade protected abstract readonly fromDevice: Partial< Record> @@ -201,15 +201,11 @@ export abstract class BaseMELCloudDevice< ) as Partial } - public async fetchDevice(): Promise { + public async fetchDevice(): Promise | undefined> { try { if (!this.#device) { - this.#device = this.#app.getFacade('devices', this.id) as - | DeviceFacade[T] - | undefined - if (this.#device) { - await this.#init(this.#device.data) - } + this.#device = this.#app.getFacade('devices', this.id) + await this.#init(this.#device.data) } return this.#device } catch (error) { diff --git a/bases/report.mts b/bases/report.mts index fbd61d36..7a920e4d 100644 --- a/bases/report.mts +++ b/bases/report.mts @@ -132,10 +132,10 @@ export abstract class BaseEnergyReport { const toDateTime = DateTime.now().minus(this.minus) const to = toDateTime.toISODate() await this.#set( - (await device.getEnergyReport({ + await device.getEnergyReport({ from: this.mode === 'total' ? undefined : to, to, - })) as EnergyData[T], + }), toDateTime.hour, ) } catch {} diff --git a/lib/getBuildings.mts b/lib/getBuildings.mts index beedafd1..bda894b3 100644 --- a/lib/getBuildings.mts +++ b/lib/getBuildings.mts @@ -1,13 +1,13 @@ import { BuildingModel, - type AreaModelAny, - type DeviceModelAny, - type FloorModel, + type IAreaModel, + type IDeviceModelAny, + type IFloorModel, } from '@olivierzal/melcloud-api' import type { AreaZone, BuildingZone, FloorZone } from '../types/index.mjs' -const hasDevices = (zone: { devices: DeviceModelAny[] }): boolean => +const hasDevices = (zone: { devices: IDeviceModelAny[] }): boolean => Boolean(zone.devices.length) const compareNames = ( @@ -15,13 +15,13 @@ const compareNames = ( { name: name2 }: { name: string }, ): number => name1.localeCompare(name2) -const filterAndMapAreas = (areas: AreaModelAny[]): AreaZone[] => +const filterAndMapAreas = (areas: IAreaModel[]): AreaZone[] => areas .filter(hasDevices) .toSorted(compareNames) .map(({ id, name }) => ({ id, name })) -const filterAndMapFloors = (floors: FloorModel[]): FloorZone[] => +const filterAndMapFloors = (floors: IFloorModel[]): FloorZone[] => floors .filter(hasDevices) .toSorted(compareNames) diff --git a/package-lock.json b/package-lock.json index 278d9c22..bf15398b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "com.melcloud", "version": "40.0.0", "dependencies": { - "@olivierzal/melcloud-api": "^14.2.1", + "@olivierzal/melcloud-api": "^15.0.0", "core-js": "^3.39.0", "homey-lib": "^2.32.8", "luxon": "^3.5.0", @@ -559,9 +559,9 @@ } }, "node_modules/@olivierzal/melcloud-api": { - "version": "14.2.1", - "resolved": "https://npm.pkg.github.com/download/@olivierzal/melcloud-api/14.2.1/a451a530bca2bbdab986af50b818644638e498da", - "integrity": "sha512-fEiwlpV2lOpYTJrhEN+OGwIG8UuXKzZjukklxvYm77QbhK9ERzUwXUsmL6uRFVNxRCozoNP7VjWWsdP1n5rwtw==", + "version": "15.0.0", + "resolved": "https://npm.pkg.github.com/download/@olivierzal/melcloud-api/15.0.0/c122b652ed87f44aa01bd0b7bf40bbea6efc0979", + "integrity": "sha512-pGxX0BseQfB96Q3ifBIiCdssqIiFzy00EBDt/pDM1FmwsHVnFqSRgamE+GbtGHBtzCv7QBwiqmB+MDYuGhWKpg==", "license": "ISC", "dependencies": { "axios": "^1.7.7", diff --git a/package.json b/package.json index c53fdcd7..0e4f07fd 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "publish": "homey app publish" }, "dependencies": { - "@olivierzal/melcloud-api": "^14.2.1", + "@olivierzal/melcloud-api": "^15.0.0", "core-js": "^3.39.0", "homey-lib": "^2.32.8", "luxon": "^3.5.0", diff --git a/types/common.mts b/types/common.mts index 69be9fed..527a4c92 100644 --- a/types/common.mts +++ b/types/common.mts @@ -6,7 +6,7 @@ import { type DeviceType, type EnergyData, type FanSpeed, - type IBaseModel, + type IModel, type ListDevice, type ListDeviceDataAta, type ListDeviceDataErv, @@ -293,11 +293,11 @@ export interface DeviceDetails { readonly name: string } -export type AreaZone = IBaseModel -export interface FloorZone extends IBaseModel { +export type AreaZone = IModel +export interface FloorZone extends IModel { areas?: AreaZone[] } -export interface BuildingZone extends IBaseModel { +export interface BuildingZone extends IModel { areas?: AreaZone[] floors?: FloorZone[] }