Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Jan 16, 2025
1 parent 2baddc1 commit 97d2e56
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 45 deletions.
9 changes: 6 additions & 3 deletions app.mts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const drivers: Record<DeviceType, string> = {
[DeviceType.Ata]: 'melcloud',
[DeviceType.Atw]: 'melcloud_atw',
[DeviceType.Erv]: 'melcloud_erv',
} as const
}

const hasChangelogLanguage = (
versionChangelog: object,
Expand Down Expand Up @@ -124,8 +124,11 @@ const getDriverLoginSetting = (
title: '',
type: isPassword ? 'password' : 'text',
}
acc[key][option.endsWith('Placeholder') ? 'placeholder' : 'title'] =
label[language] ?? label.en
acc[key] = {
...acc[key],
[option.endsWith('Placeholder') ? 'placeholder' : 'title']:
label[language] ?? label.en,
}
return acc
}, {}),
)
Expand Down
4 changes: 2 additions & 2 deletions drivers/melcloud/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class MELCloudDeviceAta extends BaseMELCloudDevice<DeviceType.Ata
: ThermostatModeAta.off) as ConvertFromDevice<DeviceType.Ata>,
vertical: ((value: Vertical) =>
Vertical[value]) as ConvertFromDevice<DeviceType.Ata>,
} as const
}

protected readonly thermostatMode = ThermostatModeAta

Expand All @@ -64,5 +64,5 @@ export default class MELCloudDeviceAta extends BaseMELCloudDevice<DeviceType.Ata
OperationMode[value]) as ConvertToDevice<DeviceType.Ata>,
vertical: ((value: keyof typeof Vertical) =>
Vertical[value]) as ConvertToDevice<DeviceType.Ata>,
} as const
}
}
4 changes: 2 additions & 2 deletions drivers/melcloud_atw/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class MELCloudDeviceAtw extends BaseMELCloudDevice<DeviceType.Atw
),
thermostat_mode: convertFromDeviceOperationZone,
'thermostat_mode.zone2': convertFromDeviceOperationZone,
} as const
}

protected readonly thermostatMode = null

Expand All @@ -129,7 +129,7 @@ export default class MELCloudDeviceAtw extends BaseMELCloudDevice<DeviceType.Atw
OperationModeZone[value]) as ConvertToDevice<DeviceType.Atw>,
'thermostat_mode.zone2': ((value: keyof typeof OperationModeZone) =>
OperationModeZone[value]) as ConvertToDevice<DeviceType.Atw>,
} as const
}

protected override async setCapabilityValues(
data: ListDeviceData<DeviceType.Atw>,
Expand Down
8 changes: 4 additions & 4 deletions drivers/melcloud_atw/driver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ export default class MELCloudDriverAtw extends BaseMELCloudDriver<DeviceType.Atw
'measure_frequency',
'measure_power',
'measure_power.produced',
] as const
]

readonly #zone1CoolCapabilities: (keyof Capabilities<DeviceType.Atw>)[] = [
'target_temperature.flow_cool',
] as const
]

readonly #zone2Capabilities: (keyof Capabilities<DeviceType.Atw>)[] = [
'measure_temperature.zone2',
'target_temperature.zone2',
'target_temperature.flow_heat_zone2',
'thermostat_mode.zone2',
'operational_state.zone2',
] as const
]

readonly #zone2CoolCapabilities: (keyof Capabilities<DeviceType.Atw>)[] = [
'target_temperature.flow_cool_zone2',
] as const
]

public getRequiredCapabilities({
CanCool: canCool,
Expand Down
4 changes: 2 additions & 2 deletions drivers/melcloud_erv/device.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class MELCloudDeviceErv extends BaseMELCloudDevice<DeviceType.Erv
data.Power ?
VentilationMode[value]
: ThermostatModeErv.off) as ConvertFromDevice<DeviceType.Erv>,
} as const
}

protected readonly thermostatMode = ThermostatModeErv

Expand All @@ -44,5 +44,5 @@ export default class MELCloudDeviceErv extends BaseMELCloudDevice<DeviceType.Erv
> = {
thermostat_mode: ((value: keyof typeof VentilationMode) =>
VentilationMode[value]) as ConvertToDevice<DeviceType.Erv>,
} as const
}
}
9 changes: 6 additions & 3 deletions mixins/with-timers.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import type Homey from 'homey/lib/Homey'
interface TimerOptions {
readonly actionType: string
readonly timerType: 'setInterval' | 'setTimeout'
readonly timerWords: { dateSpecifier: string; timeSpecifier: string }
readonly timerWords: {
readonly dateSpecifier: string
readonly timeSpecifier: string
}
}

type HomeyClass = new (
Expand All @@ -20,8 +23,8 @@ type Timer = (
) => NodeJS.Timeout

type TimerClass = new (...args: any[]) => {
setInterval: Timer
setTimeout: Timer
readonly setInterval: Timer
readonly setTimeout: Timer
}

const FIRST_CHAR = 0
Expand Down
2 changes: 1 addition & 1 deletion settings/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PLURAL_EXCEPTION_13 = 13
const PLURAL_EXCEPTION_14 = 14
const PLURAL_THRESHOLD = 2

const frostProtectionTemperatureRange = { max: 16, min: 4 } as const
const frostProtectionTemperatureRange = { max: 16, min: 4 }
const FROST_PROTECTION_TEMPERATURE_GAP = 2

const zoneMapping: Partial<Record<string, Partial<ZoneSettings>>> = {}
Expand Down
8 changes: 4 additions & 4 deletions types/ata.mts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ export const setCapabilityTagMappingAta: Record<
target_temperature: 'SetTemperature',
thermostat_mode: 'OperationMode',
vertical: 'VaneVertical',
} as const
}

export const getCapabilityTagMappingAta: Record<
keyof GetCapabilitiesAta,
keyof GetDeviceData<DeviceType.Ata>
> = {
'alarm_generic.silent': 'SetFanSpeed',
measure_temperature: 'RoomTemperature',
} as const
}

export const listCapabilityTagMappingAta: Record<
keyof ListCapabilitiesAta,
Expand All @@ -108,7 +108,7 @@ export const listCapabilityTagMappingAta: Record<
measure_signal_strength: 'WifiSignalStrength',
'measure_temperature.outdoor': 'OutdoorTemperature',
vertical: 'VaneVerticalDirection',
} as const
}

export const energyCapabilityTagMappingAta: Record<
keyof EnergyCapabilitiesAta,
Expand Down Expand Up @@ -149,7 +149,7 @@ export const energyCapabilityTagMappingAta: Record<
'meter_power.fan': ['TotalFanConsumed'],
'meter_power.heating': ['TotalHeatingConsumed'],
'meter_power.other': ['TotalOtherConsumed'],
} as const
}

export interface FlowArgsAta extends SetCapabilitiesAta {
readonly device: MELCloudDeviceAta
Expand Down
16 changes: 8 additions & 8 deletions types/atw.mts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const curve: CapabilitiesOptionsValues<'curve'> = {
no: 'Varmekurve',
sv: 'Värmekurva',
},
} as const
}

const flow: CapabilitiesOptionsValues<'flow'> = {
id: 'flow',
Expand All @@ -57,7 +57,7 @@ const flow: CapabilitiesOptionsValues<'flow'> = {
no: 'Fast fremløpstemperatur',
sv: 'Fast framledningstemperatur',
},
} as const
}

const room: CapabilitiesOptionsValues<'room'> = {
id: 'room',
Expand All @@ -70,7 +70,7 @@ const room: CapabilitiesOptionsValues<'room'> = {
no: 'Innendørs føler',
sv: 'Inomhusgivare',
},
} as const
}

const COOL_SUFFIX = 'cool'

Expand Down Expand Up @@ -109,7 +109,7 @@ const thermostatModeValuesAtw = [
curve,
createCoolObject(room),
createCoolObject(flow),
] as const
]

export const getCapabilitiesOptionsAtw = ({
CanCool: canCool,
Expand Down Expand Up @@ -245,7 +245,7 @@ export const setCapabilityTagMappingAtw: Record<
'target_temperature.zone2': 'SetTemperatureZone2',
thermostat_mode: 'OperationModeZone1',
'thermostat_mode.zone2': 'OperationModeZone2',
} as const
}

export const getCapabilityTagMappingAtw: Record<
keyof GetCapabilitiesAtw,
Expand All @@ -256,7 +256,7 @@ export const getCapabilityTagMappingAtw: Record<
'measure_temperature.tank_water': 'TankWaterTemperature',
'measure_temperature.zone2': 'RoomTemperatureZone2',
operational_state: 'OperationMode',
} as const
}

export const listCapabilityTagMappingAtw: Record<
keyof ListCapabilitiesAtw,
Expand All @@ -283,7 +283,7 @@ export const listCapabilityTagMappingAtw: Record<
'measure_temperature.tank_water_mixing': 'MixingTankWaterTemperature',
'measure_temperature.target_curve': 'TargetHCTemperatureZone1',
'measure_temperature.target_curve_zone2': 'TargetHCTemperatureZone2',
} as const
}

export const energyCapabilityTagMappingAtw: Record<
keyof EnergyCapabilitiesAtw,
Expand Down Expand Up @@ -348,7 +348,7 @@ export const energyCapabilityTagMappingAtw: Record<
'meter_power.produced_daily_hotwater': ['TotalHotWaterProduced'],
'meter_power.produced_heating': ['TotalHeatingProduced'],
'meter_power.produced_hotwater': ['TotalHotWaterProduced'],
} as const
}

export interface CapabilitiesOptionsAtw {
readonly 'target_temperature.flow_cool': RangeOptions
Expand Down
16 changes: 8 additions & 8 deletions types/common.mts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const zoneModel = {
buildings: BuildingModel,
devices: DeviceModel,
floors: FloorModel,
} as const
}

export const getCapabilitiesOptionsAtaErv = ({
HasAutomaticFanSpeed: hasAutomaticFanSpeed,
Expand Down Expand Up @@ -99,7 +99,7 @@ const auto: CapabilitiesOptionsValues<'auto'> = {
no: 'Automatisk',
sv: 'Automatiskt',
},
} as const
}

const fast: CapabilitiesOptionsValues<'fast'> = {
id: 'fast',
Expand All @@ -112,7 +112,7 @@ const fast: CapabilitiesOptionsValues<'fast'> = {
no: 'Rask',
sv: 'Snabb',
},
} as const
}

const moderate: CapabilitiesOptionsValues<'moderate'> = {
id: 'moderate',
Expand All @@ -125,7 +125,7 @@ const moderate: CapabilitiesOptionsValues<'moderate'> = {
no: 'Moderat',
sv: 'Måttlig',
},
} as const
}

const slow: CapabilitiesOptionsValues<'slow'> = {
id: 'slow',
Expand All @@ -138,7 +138,7 @@ const slow: CapabilitiesOptionsValues<'slow'> = {
no: 'Sakte',
sv: 'Långsam',
},
} as const
}

const createVeryObject = ({
id,
Expand Down Expand Up @@ -166,7 +166,7 @@ export const fanSpeedValues = [
moderate,
slow,
createVeryObject(slow),
] as const
]

export interface AreaZone extends Omit<DeviceZone, 'model'> {
readonly model: 'areas'
Expand Down Expand Up @@ -213,13 +213,13 @@ export interface DriverCapabilitiesOptions {
export interface DriverSetting {
readonly driverId: string
readonly id: string
title: string
readonly title: string
readonly type: string
readonly groupId?: string
readonly groupLabel?: string
readonly max?: number
readonly min?: number
placeholder?: string
readonly placeholder?: string
readonly units?: string
readonly values?: readonly { readonly id: string; readonly label: string }[]
}
Expand Down
8 changes: 4 additions & 4 deletions types/erv.mts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const setCapabilityTagMappingErv: Record<
fan_speed: 'SetFanSpeed',
onoff: 'Power',
thermostat_mode: 'VentilationMode',
} as const
}

export const getCapabilityTagMappingErv: Record<
keyof GetCapabilitiesErv,
Expand All @@ -58,17 +58,17 @@ export const getCapabilityTagMappingErv: Record<
measure_co2: 'RoomCO2Level',
measure_temperature: 'RoomTemperature',
'measure_temperature.outdoor': 'OutdoorTemperature',
} as const
}

export const listCapabilityTagMappingErv: Record<
keyof ListCapabilitiesErv,
keyof ListDeviceDataErv
> = {
measure_pm25: 'PM25Level',
measure_signal_strength: 'WifiSignalStrength',
} as const
}

export const energyCapabilityTagMappingErv: Record<string, never> = {} as const
export const energyCapabilityTagMappingErv: Record<string, never> = {}

export interface FlowArgsErv extends SetCapabilitiesErv {
readonly device: MELCloudDeviceErv
Expand Down
6 changes: 3 additions & 3 deletions widgets/ata-group-setting/public/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import type {
} from '../../../types/common.mts'

declare interface Homey extends HomeyWidget {
getSettings: () => HomeySettings
readonly getSettings: () => HomeySettings
}

interface ResetParams {
isSomethingOn: boolean
mode: number
readonly isSomethingOn: boolean
readonly mode: number
}

type AnimatedElement = 'flame' | 'leaf' | 'snowflake' | 'sun'
Expand Down
2 changes: 1 addition & 1 deletion widgets/charts/public/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
} from '../../../types/common.mts'

declare interface Homey extends HomeyWidget {
getSettings: () => HomeySettings
readonly getSettings: () => HomeySettings
}

const FONT_SIZE_SMALL = '14px'
Expand Down

0 comments on commit 97d2e56

Please sign in to comment.