Skip to content

Commit ed87878

Browse files
Ricc68Ricc68
andauthored
feat(ota): add a warning icon to OTA page for battery devices when battery is too low to safely run an update (#2478)
* feat: add a danger icon to OTA page for battery devices when battery is too low to run an update * style: run pretty * fix: replace red circle danger icon with yellow triangle warning one --------- Co-authored-by: Ricc68 <ricc68@local>
1 parent b53ce97 commit ed87878

File tree

4 files changed

+90
-11
lines changed

4 files changed

+90
-11
lines changed

src/components/ota-page/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ModelLink, OTALink, VendorLink } from '../vendor-links/vendor-links';
1313
import { useTranslation, WithTranslation, withTranslation } from 'react-i18next';
1414
import { Column } from 'react-table';
1515
import { Table } from '../grid/ReactTableCom';
16+
import PowerSourceOTA from '../power-source/powerSourceOTA';
1617
import cx from 'classnames';
1718

1819
type OtaRowProps = {
@@ -59,6 +60,7 @@ const StateCell: FunctionComponent<OtaRowProps & OtaApi> = (props) => {
5960
>
6061
<i className={cx('fa', 'fa-clock')} />
6162
</Button>
63+
<PowerSourceOTA device={device} deviceState={state} />
6264
</div>
6365
);
6466
case 'scheduled':
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { Fragment, FunctionComponent } from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { Device, DeviceState } from '../../types';
4+
import style from './style.module.css';
5+
import type { PowerSource } from '../../types';
6+
7+
interface PowerSourceOTAProps {
8+
device?: Device;
9+
deviceState?: DeviceState;
10+
}
11+
12+
const PowerSourceOTA: FunctionComponent<PowerSourceOTAProps> = ({ device, deviceState, ...rest }) => {
13+
const { t } = useTranslation('ota');
14+
let source: PowerSource | undefined = undefined;
15+
16+
if (device !== undefined) {
17+
source = device.power_source;
18+
}
19+
20+
if (source !== 'Battery') {
21+
return null;
22+
}
23+
24+
let batteryPercent: number | undefined = undefined;
25+
let batteryState: string | undefined = undefined;
26+
let batteryLow: boolean | undefined = undefined;
27+
28+
if (deviceState !== undefined) {
29+
if (deviceState?.battery !== undefined) {
30+
batteryPercent = deviceState.battery as number;
31+
}
32+
if (deviceState?.battery_state !== undefined) {
33+
batteryState = deviceState.battery_state as string;
34+
}
35+
if (deviceState?.battery_low !== undefined) {
36+
batteryLow = deviceState.battery_low as boolean;
37+
}
38+
}
39+
40+
// Some devices do not use the standardized feature `battery` to report power level.
41+
if (
42+
(batteryPercent !== undefined && batteryPercent <= 50) ||
43+
(batteryState !== undefined && batteryState === 'low') ||
44+
(batteryLow !== undefined && batteryLow === true)
45+
) {
46+
return (
47+
<Fragment>
48+
<i title={t('ota:battery_low_upd')} className="fa fa-triangle-exclamation text-warning ms-2" />
49+
</Fragment>
50+
);
51+
}
52+
};
53+
54+
export default PowerSourceOTA;

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@
25772577
"touchlink": "Touchlink"
25782578
},
25792579
"ota": {
2580+
"battery_low_upd": "The firmware update may fail if the batteries are not replaced",
25802581
"check": "Check for new updates",
25812582
"check_all": "Check all",
25822583
"empty_ota_message": "You don't have any devices that support OTA",

ws-messages/onConnect.json

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@
14071407
},
14081408
"friendly_name": "0xbc33acfffe17628b",
14091409
"ieee_address": "0xbc33acfffe17628b",
1410-
"interview_state": "FAILED",
1410+
"interview_state": "SUCCESSFUL",
14111411
"manufacturer": "IKEA of Sweden",
14121412
"model_id": "TRADFRI on/off switch",
14131413
"network_address": 25249,
@@ -2010,7 +2010,7 @@
20102010
"value_on": true
20112011
}
20122012
],
2013-
"supports_ota": false,
2013+
"supports_ota": true,
20142014
"vendor": "Xiaomi"
20152015
},
20162016
"endpoints": {
@@ -2327,7 +2327,7 @@
23272327
"type": "numeric"
23282328
}
23292329
],
2330-
"supports_ota": false,
2330+
"supports_ota": true,
23312331
"vendor": "Xiaomi"
23322332
},
23332333
"endpoints": {
@@ -2596,7 +2596,7 @@
25962596
"type": "numeric"
25972597
}
25982598
],
2599-
"supports_ota": false,
2599+
"supports_ota": true,
26002600
"vendor": "Xiaomi"
26012601
},
26022602
"endpoints": {
@@ -8652,7 +8652,7 @@
86528652
"topic": "bridge/extensions"
86538653
},
86548654
{
8655-
"payload": "offline",
8655+
"payload": "online",
86568656
"topic": "0xbc33acfffe17628b/availability"
86578657
},
86588658
{
@@ -8707,7 +8707,13 @@
87078707
},
87088708
{
87098709
"payload": {
8710-
"last_seen": "2022-04-15T16:33:53+08:00"
8710+
"battery": 45,
8711+
"last_seen": "2022-04-15T16:33:53+08:00",
8712+
"update": {
8713+
"installed_version": 65552,
8714+
"latest_version": 16777233,
8715+
"state": "available"
8716+
}
87118717
},
87128718
"topic": "0xbc33acfffe17628b"
87138719
},
@@ -8748,7 +8754,12 @@
87488754
"battery": 100,
87498755
"last_seen": "2022-05-16T20:46:44+08:00",
87508756
"linkquality": 66,
8751-
"voltage": 3042
8757+
"voltage": 3042,
8758+
"update": {
8759+
"installed_version": 65552,
8760+
"latest_version": 16777233,
8761+
"state": "available"
8762+
}
87528763
},
87538764
"topic": "0x00158d000224154d"
87548765
},
@@ -8780,12 +8791,17 @@
87808791
},
87818792
{
87828793
"payload": {
8783-
"battery": 100,
8794+
"battery": 65,
87848795
"humidity": 65.59,
87858796
"last_seen": "2022-05-16T20:37:54+08:00",
87868797
"linkquality": 90,
87878798
"temperature": 25.84,
8788-
"voltage": 3035
8799+
"voltage": 3035,
8800+
"update": {
8801+
"installed_version": 65552,
8802+
"latest_version": 16777233,
8803+
"state": "available"
8804+
}
87898805
},
87908806
"topic": "livingroom/temp_humidity"
87918807
},
@@ -8811,13 +8827,19 @@
88118827
},
88128828
{
88138829
"payload": {
8814-
"battery": 0,
8830+
"battery": 5,
88158831
"humidity": 59.96,
88168832
"last_seen": "2022-05-16T21:06:04+08:00",
8833+
"state": "ON",
88178834
"linkquality": 12,
88188835
"pressure": 1009.8,
88198836
"temperature": 32.9,
8820-
"voltage": 2815
8837+
"voltage": 2815,
8838+
"update": {
8839+
"installed_version": 65552,
8840+
"latest_version": 16777233,
8841+
"state": "available"
8842+
}
88218843
},
88228844
"topic": "0x00158d0004866f11"
88238845
},

0 commit comments

Comments
 (0)