Skip to content

Commit d76f3cc

Browse files
Ricc68Ricc68
andauthored
fix(ota): report installed_version and available_version states in OTA page instead of build id and date (#2470)
* fix: report installed_version and available_version states in OTA page instead of build id and date * fix: improved code and formatting * fix: translation of 'N/A' is not required --------- Co-authored-by: Ricc68 <ricc68@local>
1 parent 3cef5d5 commit d76f3cc

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

src/components/ota-page/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { OtaApi } from '../../actions/OtaApi';
66
import { GlobalState } from '../../store';
77
import Button from '../button';
88
import { DeviceImage } from '../device-image/DeviceImage';
9-
import { genDeviceDetailsLink, isDeviceDisabled, toHHMMSS } from '../../utils';
9+
import { genDeviceDetailsLink, isDeviceDisabled, toHHMMSS, fileVersion2String } from '../../utils';
1010
import { Link } from 'react-router-dom';
1111
import { Device, DeviceState, OTAState } from '../../types';
1212
import { ModelLink, OTALink, VendorLink } from '../vendor-links/vendor-links';
@@ -132,6 +132,7 @@ class OtaPage extends Component<PropsFromStore & OtaApi & WithTranslation<'ota'>
132132
const otaDevices = this.getAllOtaDevices();
133133
otaDevices.forEach(({ device }) => checkOTA(device.friendly_name));
134134
};
135+
135136
render() {
136137
const { checkOTA, scheduleOTA, unscheduleOTA, updateOTA, t } = this.props;
137138
const otaApi = { checkOTA, scheduleOTA, unscheduleOTA, updateOTA };
@@ -182,17 +183,23 @@ class OtaPage extends Component<PropsFromStore & OtaApi & WithTranslation<'ota'>
182183
}) => <ModelLink device={device} />,
183184
},
184185
{
185-
Header: t('zigbee:firmware_build_date') as string,
186-
accessor: ({ device }) => device.date_code,
186+
Header: t('zigbee:firmware_installed_version') as string,
187+
accessor: ({ state }) => {
188+
const installed_version = ((state?.update ?? {}) as OTAState).installed_version;
189+
190+
if (typeof installed_version === 'number' && installed_version)
191+
return fileVersion2String(installed_version);
192+
else return t('zigbee:firmware_installed_version_na');
193+
},
187194
},
188195
{
189-
Header: t('zigbee:firmware_version') as string,
190-
accessor: ({ device }) => device.software_build_id,
191-
Cell: ({
192-
row: {
193-
original: { device },
194-
},
195-
}) => <OTALink device={device} />,
196+
Header: t('zigbee:firmware_available_version') as string,
197+
accessor: ({ state }) => {
198+
const latest_version = ((state?.update ?? {}) as OTAState).latest_version;
199+
200+
if (typeof latest_version === 'number' && latest_version) return fileVersion2String(latest_version);
201+
else return 'N/A';
202+
},
196203
},
197204
{
198205
Header: () => (

src/i18n/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,9 @@
26592659
"endpoint": "Endpoint",
26602660
"firmware_build_date": "Firmware build date",
26612661
"firmware_version": "Firmware version",
2662+
"firmware_installed_version": "Firmware installed version",
2663+
"firmware_available_version": "Firmware available version",
2664+
"firmware_installed_version_na": "Not yet reported by device",
26622665
"force_remove": "Force remove",
26632666
"friendly_name": "Friendly name",
26642667
"ieee_address": "IEEE Address",

src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export const toHHMMSS = (secs: number): string => {
3131
.join(":");
3232
};
3333

34+
export const fileVersion2String = (file_version: number): string => {
35+
const versionString = file_version.toString(16).padStart(8, "0");
36+
const appRelease = `${versionString[0]}.${versionString[1]}`;
37+
const appBuild = versionString.slice(2, 4);
38+
const stackRelease = `${versionString[4]}.${versionString[5]}`;
39+
const stackBuild = versionString.slice(6);
40+
41+
return `${appRelease}.${appBuild}-${stackRelease}.${stackBuild}`;
42+
};
43+
3444
export const lastSeen = (state: DeviceState, lastSeenType: LastSeenType): Date | undefined => {
3545
if (!state.last_seen) {
3646
return undefined;

ws-messages/onConnect.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8734,7 +8734,12 @@
87348734
"color_temp": 454,
87358735
"color_temp_startup": 500,
87368736
"last_seen": "2022-04-15T17:48:28+08:00",
8737-
"state": "ON"
8737+
"state": "ON",
8738+
"update": {
8739+
"installed_version": 65552,
8740+
"latest_version": 16777233,
8741+
"state": "available"
8742+
}
87388743
},
87398744
"topic": "hue_back_tv"
87408745
},

0 commit comments

Comments
 (0)