Skip to content

Commit

Permalink
bump melcloud-api
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Nov 13, 2024
1 parent 12f1e50 commit b72c503
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
19 changes: 11 additions & 8 deletions app.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<T extends keyof typeof DeviceType>(
zoneType: 'devices',
id: number | string,
): IDeviceFacade<T>
public getFacade(
zoneType: 'areas' | 'buildings' | 'floors',
zoneType: Exclude<keyof typeof zoneModel, 'devices'>,
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(
Expand Down
14 changes: 5 additions & 9 deletions bases/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -55,7 +55,7 @@ export abstract class BaseMELCloudDevice<

#setCapabilityTagMapping: Partial<SetCapabilityTagMapping[T]> = {}

#device?: DeviceFacade[T]
#device?: IDeviceFacade<T>

protected abstract readonly fromDevice: Partial<
Record<keyof OpCapabilities[T], ConvertFromDevice<T>>
Expand Down Expand Up @@ -201,15 +201,11 @@ export abstract class BaseMELCloudDevice<
) as Partial<M>
}

public async fetchDevice(): Promise<DeviceFacade[T] | undefined> {
public async fetchDevice(): Promise<IDeviceFacade<T> | 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) {
Expand Down
4 changes: 2 additions & 2 deletions bases/report.mts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ export abstract class BaseEnergyReport<T extends keyof typeof DeviceType> {
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 {}
Expand Down
12 changes: 6 additions & 6 deletions lib/getBuildings.mts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
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 = (
{ name: name1 }: { name: string },
{ 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)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions types/common.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type DeviceType,
type EnergyData,
type FanSpeed,
type IBaseModel,
type IModel,
type ListDevice,
type ListDeviceDataAta,
type ListDeviceDataErv,
Expand Down Expand Up @@ -293,11 +293,11 @@ export interface DeviceDetails<T extends keyof typeof DeviceType> {
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[]
}
Expand Down

0 comments on commit b72c503

Please sign in to comment.