-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add autodl for Hue (partial) #663
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import {getJson, getLatestImage, readCacheJson, writeCacheJson} from '../common.js'; | ||
import {processFirmwareImage} from '../process_firmware_image.js'; | ||
|
||
type ImageJson = { | ||
createdAt: string; | ||
updatedAt: string; | ||
fileSize: number; | ||
md5: string; | ||
binaryUrl: string; | ||
version: number; | ||
versionName: string; | ||
releaseNotes: string; | ||
}; | ||
type PageJson = {updates: ImageJson[]}; | ||
|
||
const NAME = 'Hue'; | ||
const BASE_URL = 'https://firmware.meethue.com/v1/checkupdate?version=0&deviceTypeId='; | ||
const DEVICE_TYPE_IDS: string[] = [ | ||
'100b-111', | ||
'100b-112', | ||
// '100b-113', | ||
'100b-114', | ||
'100b-115', | ||
// '100b-116', | ||
'100b-117', | ||
'100b-118', | ||
// '100b-119', | ||
'100b-11a', | ||
// '100b-11b', | ||
// '100b-11c', | ||
'100b-11d', | ||
'100b-11e', | ||
'100b-11f', | ||
'100b-120', | ||
// '100b-121', | ||
// '100b-122', | ||
'100b-123', | ||
// '100b-124', | ||
'100b-125', | ||
// '100b-126', | ||
'100b-127', | ||
// '100b-128', | ||
'100b-129', | ||
// '100b-12a', | ||
// '100b-12b', | ||
// '100b-12c', | ||
// '100b-12d', | ||
// '100b-12e', | ||
// '100b-12f', | ||
]; | ||
|
||
function sortByVersion(a: ImageJson, b: ImageJson): number { | ||
return a.version < b.version ? -1 : a.version > b.version ? 1 : 0; | ||
} | ||
|
||
function isDifferent(newData: PageJson, cachedData?: PageJson): boolean { | ||
return ( | ||
Boolean(process.env.IGNORE_CACHE) || | ||
!cachedData?.updates.length || | ||
getLatestImage(cachedData.updates, sortByVersion)?.version !== getLatestImage(newData.updates, sortByVersion)?.version | ||
); | ||
} | ||
|
||
export async function writeCache(): Promise<void> { | ||
for (const deviceTypeId of DEVICE_TYPE_IDS) { | ||
const url = `${BASE_URL}${deviceTypeId}`; | ||
const page = await getJson<PageJson>(NAME, url); | ||
|
||
if (page?.updates.length) { | ||
writeCacheJson(`${NAME}_${deviceTypeId}`, page); | ||
} | ||
} | ||
} | ||
|
||
export async function download(): Promise<void> { | ||
for (const deviceTypeId of DEVICE_TYPE_IDS) { | ||
const logPrefix = `[${NAME}:${deviceTypeId}]`; | ||
const url = `${BASE_URL}${deviceTypeId}`; | ||
const page = await getJson<PageJson>(NAME, url); | ||
|
||
if (!page?.updates.length) { | ||
console.error(`${logPrefix} No image data.`); | ||
continue; | ||
} | ||
|
||
const cacheFileName = `${NAME}_${deviceTypeId}`; | ||
|
||
if (!isDifferent(page, readCacheJson(cacheFileName))) { | ||
console.log(`${logPrefix} No change from last run.`); | ||
continue; | ||
} | ||
|
||
writeCacheJson(cacheFileName, page); | ||
|
||
const image = getLatestImage(page.updates, sortByVersion); | ||
|
||
if (!image) { | ||
continue; | ||
} | ||
|
||
const firmwareFileName = image.binaryUrl.split('/').pop()!; | ||
|
||
await processFirmwareImage(NAME, firmwareFileName, image.binaryUrl, {releaseNotes: image.releaseNotes || undefined}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always using
version=0
here will give you old updates if intermediary updates are required, since you will always get a compatible image forversion=0
per cid/type, which is always an old image.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script is comparing actual versions in the list once fetched (sorting by version and picking latest).
Currently, there are no device with anything other than 1 update though, so I'm not sure how the intermediary updates work for Hue. I assume version limit if they followed spec? If using that scheme, it should be handled, since the update logic won't let an OTA file with a limitation be overridden, it will always keep both, which, in turn, should allow Z2M to update in the appropriate order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other scripts might handle this properly, but by always sending
version=0
, you won't fetch the newest firmware in the first place. As an example, say you sendversion=0
and get a firmware with version 1.If you then send
version=1
, you might get another image with version 2 (which you did not get by sending ver=0).This is why the parameter exists in the first place. The Hue mobile app always calls that with the currently installed version on the lamp.
So, the script would have to be updated to not only send
0
, but also the latest known version number for that model, until no more updates are returned.However, it seems like no intermediary updates are returned by the mobile API at the moment. I'm getting different results via the proper Hue Bridge AP, which is a bit weird...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I saw with the Hue bridge device ID, by sending version
0
, you get all versions returned at once in the array. But yea, that's the only one that currently returns more than 1 firmware, so, it's more of an assumption.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, only versions that can be installed from the current version are returned. For the OTA API used by the Hue Bridge, with older TI or ATmel-baed lights, you only get older firmware images until you increase
version
to the next image.And the mobile API isn't used for updating the Bridge (anymore?) IIRC.
Using the Hue Bridge OTA API for querying images for
BSB002
withversion=0
returns the latest update and not the two older ones, so it seems like there are no required intermediary updates for the Bridge.So, the two year old results that are included in
BSB002
for the mobile API seem to be unintentional.Btw., see your Discord DMs if you have some time.