Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Nov 29, 2024
1 parent ce01ddb commit 2395537
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 107 deletions.
76 changes: 32 additions & 44 deletions widgets/ata-group-setting/public/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,10 @@ const generateDelay = (delay: number, speed: number): number =>
DEFAULT_DIVISOR)

const setDocumentLanguage = async (homey: Homey): Promise<void> => {
try {
const language = await homey.api('GET', '/language')
document.documentElement.lang =
typeof language === 'string' ? language : 'en'
} catch {}
document.documentElement.lang = (await homey.api(
'GET',
'/language',
)) as string
}

const createLabelElement = (
Expand Down Expand Up @@ -842,13 +841,8 @@ const getDetailedAtaValues = async (homey: Homey): Promise<GroupAtaStates> =>
} satisfies Required<GetAtaOptions>)}`,
)) as GroupAtaStates

const getModes = async (homey: Homey): Promise<OperationMode[]> => {
try {
return (await getDetailedAtaValues(homey)).OperationMode
} catch {
return []
}
}
const getModes = async (homey: Homey): Promise<OperationMode[]> =>
(await getDetailedAtaValues(homey)).OperationMode

const resetFireAnimation = async (
homey: Homey,
Expand Down Expand Up @@ -968,12 +962,10 @@ const handleAnimation = async (
}

const fetchAtaValues = async (homey: Homey): Promise<void> => {
try {
const values = await getAtaValues(homey)
updateZoneMapping({ ...defaultAtaValues, ...values })
refreshAtaValues()
await handleAnimation(homey, values)
} catch {}
const values = await getAtaValues(homey)
updateZoneMapping({ ...defaultAtaValues, ...values })
refreshAtaValues()
await handleAnimation(homey, values)
}

const generateAtaValue = (
Expand Down Expand Up @@ -1025,36 +1017,32 @@ const generateZones = async (zones: Zone[]): Promise<void> =>
}, Promise.resolve())

const fetchBuildings = async (homey: Homey): Promise<void> => {
try {
const buildings = (await homey.api(
'GET',
`/buildings?${new URLSearchParams({
type: '0',
} satisfies { type: `${DeviceType}` })}`,
)) as BuildingZone[]
if (buildings.length) {
generateAtaValues(homey)
await generateZones(buildings)
if (settings.default_zone) {
;({
default_zone: { id: zoneElement.value },
} = settings)
}
await fetchAtaValues(homey)
const buildings = (await homey.api(
'GET',
`/buildings?${new URLSearchParams({
type: '0',
} satisfies { type: `${DeviceType}` })}`,
)) as BuildingZone[]
if (buildings.length) {
generateAtaValues(homey)
await generateZones(buildings)
if (settings.default_zone) {
;({
default_zone: { id: zoneElement.value },
} = settings)
}
} catch {}
await fetchAtaValues(homey)
}
}

const fetchAtaCapabilities = async (homey: Homey): Promise<void> => {
try {
ataCapabilities = (await homey.api('GET', '/capabilities/ata')) as [
keyof GroupState,
DriverCapabilitiesOptions,
][]
defaultAtaValues = Object.fromEntries(
ataCapabilities.map(([ataKey]) => [ataKey, null]),
)
} catch {}
ataCapabilities = (await homey.api('GET', '/capabilities/ata')) as [
keyof GroupState,
DriverCapabilitiesOptions,
][]
defaultAtaValues = Object.fromEntries(
ataCapabilities.map(([ataKey]) => [ataKey, null]),
)
}

const setAtaValues = async (homey: Homey): Promise<void> => {
Expand Down
45 changes: 0 additions & 45 deletions widgets/temperatures/public/echarts.min.js

This file was deleted.

4 changes: 2 additions & 2 deletions widgets/temperatures/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="MELCloud air-to-air device setting" name="description">
<meta content="MELCloud temperature log" name="description">
<meta content="width=device-width, initial-scale=1.0, user-scalable=0" name="viewport">
<title>Air-to-air device values</title>
<link href="output.css" rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<script src="echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
</head>
<body class="homey-widget">
<select
Expand Down
29 changes: 13 additions & 16 deletions widgets/temperatures/public/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ const draw = async (homey: Homey): Promise<void> => {
}

const setDocumentLanguage = async (homey: Homey): Promise<void> => {
try {
const language = await homey.api('GET', '/language')
document.documentElement.lang =
typeof language === 'string' ? language : 'en'
} catch {}
document.documentElement.lang = (await homey.api(
'GET',
'/language',
)) as string
}

const createOptionElement = (
Expand All @@ -90,18 +89,16 @@ const generateZones = (zones: BaseZone[]): void => {
}

const fetchDevices = async (homey: Homey): Promise<void> => {
try {
const devices = (await homey.api('GET', '/devices')) as BaseZone[]
if (devices.length) {
generateZones(devices)
if (settings.default_zone) {
;({
default_zone: { id: zoneElement.value },
} = settings)
}
await draw(homey)
const devices = (await homey.api('GET', '/devices')) as BaseZone[]
if (devices.length) {
generateZones(devices)
if (settings.default_zone) {
;({
default_zone: { id: zoneElement.value },
} = settings)
}
} catch {}
await draw(homey)
}
}

const addEventListeners = (homey: Homey): void => {
Expand Down

0 comments on commit 2395537

Please sign in to comment.