Skip to content

Commit

Permalink
Migrate to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Oct 21, 2024
1 parent 22ac4dc commit c3b99f3
Show file tree
Hide file tree
Showing 45 changed files with 157 additions and 139 deletions.
13 changes: 7 additions & 6 deletions api.ts → api.mts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { getBuildings } from './lib'
import { getBuildings } from './lib/index.mjs'

import type {
FrostProtectionData,
GroupAtaState,
HolidayModeData,
LoginCredentials,
} from '@olivierzal/melcloud-api'
import type Homey from 'homey/lib/Homey'
import type Homey from 'homey/lib/Homey.js'

import type MELCloudApp from './app.mjs'
import type {
BuildingZone,
DeviceSettings,
Expand All @@ -19,13 +20,11 @@ import type {
HolidayModeSettings,
Settings,
ZoneData,
} from './types'

import type MELCloudApp from '.'
} from './types/index.mjs'

const getApp = (homey: Homey): MELCloudApp => homey.app as MELCloudApp

export = {
const api = {
getAtaCapabilities({
homey,
}: {
Expand Down Expand Up @@ -139,3 +138,5 @@ export = {
return getApp(homey).setHolidayModeSettings(body, params)
},
}

export default api
26 changes: 14 additions & 12 deletions app.ts → app.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'core-js/actual/object/group-by'
import 'source-map-support/register'
import 'core-js/actual/object/group-by.js'
import 'source-map-support/register.js'

import {
FacadeManager,
Expand All @@ -18,16 +18,16 @@ import {
type ListDeviceDataAta,
type LoginCredentials,
} from '@olivierzal/melcloud-api'
import { App } from 'homey'
import fanSpeed from 'homey-lib/assets/capability/capabilities/fan_speed.json'
import power from 'homey-lib/assets/capability/capabilities/onoff.json'
import setTemperature from 'homey-lib/assets/capability/capabilities/target_temperature.json'
import thermostatMode from 'homey-lib/assets/capability/capabilities/thermostat_mode.json'
import Homey from 'homey'

Check failure on line 21 in app.mts

View workflow job for this annotation

GitHub Actions / Validate app

No default export found in imported module "homey"
import fanSpeed from 'homey-lib/assets/capability/capabilities/fan_speed.json' assert { type: 'json' }
import power from 'homey-lib/assets/capability/capabilities/onoff.json' assert { type: 'json' }
import setTemperature from 'homey-lib/assets/capability/capabilities/target_temperature.json' assert { type: 'json' }
import thermostatMode from 'homey-lib/assets/capability/capabilities/thermostat_mode.json' assert { type: 'json' }
import { Settings as LuxonSettings } from 'luxon'

import changelog from './.homeychangelog.json'
import horizontal from './.homeycompose/capabilities/horizontal.json'
import vertical from './.homeycompose/capabilities/vertical.json'
import changelog from './.homeychangelog.json' assert { type: 'json' }
import horizontal from './.homeycompose/capabilities/horizontal.json' assert { type: 'json' }
import vertical from './.homeycompose/capabilities/vertical.json' assert { type: 'json' }
import {
fanSpeedValues,
zoneModel,
Expand All @@ -46,7 +46,7 @@ import {
type ManifestDriverCapabilitiesOptions,
type Settings,
type ZoneData,
} from './types'
} from './types/index.mjs'

const NOTIFICATION_DELAY = 10000

Expand Down Expand Up @@ -131,7 +131,7 @@ const getLocalizedCapabilitiesOptions = (
})),
})

export = class extends App {
class MELCloudApp extends Homey.App {

Check failure on line 134 in app.mts

View workflow job for this annotation

GitHub Actions / Validate app

Caution: `Homey` also has a named export `App`. Check if you meant to write `import {App} from 'homey'` instead
readonly #language = this.homey.i18n.getLanguage()

#api!: MELCloudAPI
Expand Down Expand Up @@ -404,3 +404,5 @@ export = class extends App {
)
}
}

export default MELCloudApp
10 changes: 5 additions & 5 deletions bases/device.ts → bases/device.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Device } from 'homey'
import homey from 'homey'

Check failure on line 1 in bases/device.mts

View workflow job for this annotation

GitHub Actions / Validate app

No default export found in imported module "homey"

import { addToLogs, withTimers } from '../lib'
import { addToLogs, withTimers } from '../lib/index.mjs'

import type {
DeviceFacade,
Expand All @@ -9,7 +9,7 @@ import type {
UpdateDeviceData,
} from '@olivierzal/melcloud-api'

import type MELCloudApp from '../app'
import type MELCloudApp from '../app.mjs'
import type {
Capabilities,
CapabilitiesOptions,
Expand All @@ -28,7 +28,7 @@ import type {
SetCapabilities,
SetCapabilityTagMapping,
Settings,
} from '../types'
} from '../types/index.mjs'

const SYNC_DELAY = 1000

Expand All @@ -47,7 +47,7 @@ const isTotalEnergyKey = (key: string): boolean =>
@addToLogs('getName()')
export abstract class BaseMELCloudDevice<
T extends keyof typeof DeviceType,
> extends withTimers(Device) {
> extends withTimers(homey.Device) {

Check failure on line 50 in bases/device.mts

View workflow job for this annotation

GitHub Actions / Validate app

Caution: `homey` also has a named export `Device`. Check if you meant to write `import {Device} from 'homey'` instead
public declare readonly driver: MELCloudDriver[T]

readonly #app = this.homey.app as MELCloudApp
Expand Down
10 changes: 5 additions & 5 deletions bases/driver.ts → bases/driver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
type ListDevice,
type LoginCredentials,
} from '@olivierzal/melcloud-api'
import { Driver } from 'homey'
import Homey from 'homey'

Check failure on line 8 in bases/driver.mts

View workflow job for this annotation

GitHub Actions / Validate app

No default export found in imported module "homey"

import type PairSession from 'homey/lib/PairSession'
import type PairSession from 'homey/lib/PairSession.js'

import type MELCloudApp from '..'
import type MELCloudApp from '../app.mjs'
import type {
Capabilities,
CapabilitiesOptions,
Expand All @@ -22,7 +22,7 @@ import type {
OpCapabilities,
SetCapabilities,
SetCapabilityTagMapping,
} from '../types'
} from '../types/index.mjs'

const getArg = <T extends keyof typeof DeviceType>(
capability: Extract<keyof OpCapabilities[T], string>,
Expand All @@ -33,7 +33,7 @@ const getArg = <T extends keyof typeof DeviceType>(

export abstract class BaseMELCloudDriver<
T extends keyof typeof DeviceType,
> extends Driver {
> extends Homey.Driver {

Check failure on line 36 in bases/driver.mts

View workflow job for this annotation

GitHub Actions / Validate app

Caution: `Homey` also has a named export `Driver`. Check if you meant to write `import {Driver} from 'homey'` instead
public readonly capabilities = (this.manifest as ManifestDriver).capabilities

public readonly consumedTagMapping: Partial<EnergyCapabilityTagMapping[T]> =
Expand Down
3 changes: 3 additions & 0 deletions bases/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { BaseMELCloudDevice } from './device.mjs'
export { BaseMELCloudDriver } from './driver.mjs'
export { BaseEnergyReport } from './report.mjs'
3 changes: 0 additions & 3 deletions bases/index.ts

This file was deleted.

8 changes: 4 additions & 4 deletions bases/report.ts → bases/report.mts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DateTime, type DateObjectUnits, type DurationLike } from 'luxon'

import { K_MULTIPLIER, isTotalEnergyKey } from '../lib'
import { K_MULTIPLIER, isTotalEnergyKey } from '../lib/index.mjs'

import type {
DeviceFacade,
DeviceType,
EnergyData,
} from '@olivierzal/melcloud-api'
import type { Homey } from 'homey/lib/Device'
import type { Homey } from 'homey/lib/Device.js'

import type {
Capabilities,
Expand All @@ -16,9 +16,9 @@ import type {
EnergyCapabilityTagMapping,
EnergyReportMode,
MELCloudDriver,
} from '../types'
} from '../types/index.mjs'

import type { BaseMELCloudDevice } from './device'
import type { BaseMELCloudDevice } from './device.mjs'

const INITIAL_SUM = 0
const DEFAULT_DEVICE_COUNT = 1
Expand Down
13 changes: 9 additions & 4 deletions drivers/melcloud/device.ts → drivers/melcloud/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import {
type ListDeviceDataAta,
} from '@olivierzal/melcloud-api'

import { BaseMELCloudDevice } from '../../bases'
import { EnergyReportRegularAta, EnergyReportTotalAta } from '../../reports'
import { BaseMELCloudDevice } from '../../bases/index.mjs'
import {
EnergyReportRegularAta,
EnergyReportTotalAta,
} from '../../reports/index.mjs'
import {
ThermostatModeAta,
type ConvertFromDevice,
type ConvertToDevice,
type OpCapabilitiesAta,
type SetCapabilitiesAta,
} from '../../types'
} from '../../types/index.mjs'

export = class extends BaseMELCloudDevice<'Ata'> {
class MELCloudDeviceAta extends BaseMELCloudDevice<'Ata'> {
protected readonly fromDevice: Partial<
Record<keyof OpCapabilitiesAta, ConvertFromDevice<'Ata'>>
> = {
Expand Down Expand Up @@ -51,3 +54,5 @@ export = class extends BaseMELCloudDevice<'Ata'> {

protected EnergyReportTotal = EnergyReportTotalAta
}

export default MELCloudDeviceAta
8 changes: 5 additions & 3 deletions drivers/melcloud/driver.ts → drivers/melcloud/driver.mts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseMELCloudDriver } from '../../bases'
import { BaseMELCloudDriver } from '../../bases/index.mjs'
import {
energyCapabilityTagMappingAta,
getCapabilitiesOptionsAtaErv,
getCapabilityTagMappingAta,
listCapabilityTagMappingAta,
setCapabilityTagMappingAta,
} from '../../types'
} from '../../types/index.mjs'

export = class extends BaseMELCloudDriver<'Ata'> {
class MELCloudDriverAta extends BaseMELCloudDriver<'Ata'> {
public readonly energyCapabilityTagMapping = energyCapabilityTagMappingAta

public readonly getCapabilitiesOptions = getCapabilitiesOptionsAtaErv
Expand All @@ -30,3 +30,5 @@ export = class extends BaseMELCloudDriver<'Ata'> {
]
}
}

export default MELCloudDriverAta
15 changes: 10 additions & 5 deletions drivers/melcloud_atw/device.ts → drivers/melcloud_atw/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import {
} from '@olivierzal/melcloud-api'
import { DateTime } from 'luxon'

import { BaseMELCloudDevice } from '../../bases'
import { K_MULTIPLIER } from '../../lib'
import { EnergyReportRegularAtw, EnergyReportTotalAtw } from '../../reports'
import { BaseMELCloudDevice } from '../../bases/index.mjs'
import { K_MULTIPLIER } from '../../lib/index.mjs'
import {
EnergyReportRegularAtw,
EnergyReportTotalAtw,
} from '../../reports/index.mjs'
import {
HotWaterMode,
OperationModeStateHotWaterCapability,
Expand All @@ -18,7 +21,7 @@ import {
type OpCapabilitiesAtw,
type SetCapabilitiesAtw,
type TargetTemperatureFlowCapabilities,
} from '../../types'
} from '../../types/index.mjs'

const convertFromDeviceMeasurePower = ((value: number) =>
value * K_MULTIPLIER) as ConvertFromDevice<'Atw'>
Expand Down Expand Up @@ -63,7 +66,7 @@ const getOperationModeStateZoneValue = (
return OperationModeStateZoneCapability.idle
}

export = class extends BaseMELCloudDevice<'Atw'> {
class MELCloudDeviceAtw extends BaseMELCloudDevice<'Atw'> {
protected readonly fromDevice: Partial<
Record<keyof OpCapabilitiesAtw, ConvertFromDevice<'Atw'>>
> = {
Expand Down Expand Up @@ -168,3 +171,5 @@ export = class extends BaseMELCloudDevice<'Atw'> {
await this.#setOperationModeStateZones(data, operationModeState)
}
}

export default MELCloudDeviceAtw
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { BaseMELCloudDriver } from '../../bases'
import { BaseMELCloudDriver } from '../../bases/index.mjs'
import {
energyCapabilityTagMappingAtw,
getCapabilitiesOptionsAtw,
getCapabilityTagMappingAtw,
listCapabilityTagMappingAtw,
setCapabilityTagMappingAtw,
type CapabilitiesAtw,
} from '../../types'
} from '../../types/index.mjs'

import type { ListDeviceDataAtw } from '@olivierzal/melcloud-api'

export = class extends BaseMELCloudDriver<'Atw'> {
class MELCloudDriverAtw extends BaseMELCloudDriver<'Atw'> {
public readonly energyCapabilityTagMapping = energyCapabilityTagMappingAtw

public readonly getCapabilitiesOptions = getCapabilitiesOptionsAtw
Expand Down Expand Up @@ -75,3 +75,5 @@ export = class extends BaseMELCloudDriver<'Atw'> {
]
}
}

export default MELCloudDriverAtw
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {
type ListDeviceDataErv,
} from '@olivierzal/melcloud-api'

import { BaseMELCloudDevice } from '../../bases'
import { BaseMELCloudDevice } from '../../bases/index.mjs'
import {
ThermostatModeErv,
type ConvertFromDevice,
type ConvertToDevice,
type OpCapabilitiesErv,
type SetCapabilitiesErv,
} from '../../types'
} from '../../types/index.mjs'

export = class extends BaseMELCloudDevice<'Erv'> {
class MELCloudDeviceErv extends BaseMELCloudDevice<'Erv'> {
protected readonly fromDevice: Partial<
Record<keyof OpCapabilitiesErv, ConvertFromDevice<'Erv'>>
> = {
Expand All @@ -33,3 +33,5 @@ export = class extends BaseMELCloudDevice<'Erv'> {

protected EnergyReportTotal = undefined
}

export default MELCloudDeviceErv
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseMELCloudDriver } from '../../bases'
import { BaseMELCloudDriver } from '../../bases/index.mjs'
import {
energyCapabilityTagMappingErv,
getCapabilitiesOptionsAtaErv,
getCapabilityTagMappingErv,
listCapabilityTagMappingErv,
setCapabilityTagMappingErv,
} from '../../types'
} from '../../types/index.mjs'

import type { ListDeviceDataErv } from '@olivierzal/melcloud-api'

export = class extends BaseMELCloudDriver<'Erv'> {
class MELCloudDriverErv extends BaseMELCloudDriver<'Erv'> {
public readonly energyCapabilityTagMapping = energyCapabilityTagMappingErv

public readonly getCapabilitiesOptions = getCapabilitiesOptionsAtaErv
Expand Down Expand Up @@ -38,3 +38,5 @@ export = class extends BaseMELCloudDriver<'Erv'> {
]
}
}

export default MELCloudDriverErv
Loading

0 comments on commit c3b99f3

Please sign in to comment.