Skip to content

Commit

Permalink
Zigbee2mqtt: Add battery icon in device box (#2036)
Browse files Browse the repository at this point in the history
  • Loading branch information
William-De71 authored Mar 21, 2024
1 parent f6e38db commit da3bd2b
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { Link } from 'preact-router/match';
import get from 'get-value';

import { RequestStatus } from '../../../../../utils/consts';
import { DEVICE_FEATURE_CATEGORIES } from '../../../../../../../server/utils/constants';
import DeviceFeatures from '../../../../../components/device/view/DeviceFeatures';
import BatteryLevelFeature from '../../../../../components/device/view/BatteryLevelFeature';

class Zigbee2mqttBox extends Component {
updateName = e => {
Expand Down Expand Up @@ -79,10 +81,33 @@ class Zigbee2mqttBox extends Component {
});
};

getDeviceProperty = () => {
if (!this.props.device.features) {
return null;
}
const batteryLevelDeviceFeature = this.props.device.features.find(
deviceFeature => deviceFeature.category === DEVICE_FEATURE_CATEGORIES.BATTERY
);
const batteryLevel = get(batteryLevelDeviceFeature, 'last_value');

return {
batteryLevel
};
};

render(props, { loading, saveError, tooMuchStatesError, statesNumber }) {
const { batteryLevel } = this.getDeviceProperty();
return (
<div class="col-md-6">
<div class="card">
<div class="card-header">
{props.device.name}{' '}
{batteryLevel && (
<div class="page-options d-flex">
<BatteryLevelFeature batteryLevel={batteryLevel} />
</div>
)}
</div>
<div
class={cx('dimmer', {
active: loading
Expand Down

0 comments on commit da3bd2b

Please sign in to comment.