]> git.basschouten.com Git - openhab-addons.git/blob
be7f7ade06675742a3ea0e3ea9634f5511b7f73d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.miio.internal.robot;
14
15 import java.util.concurrent.TimeUnit;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Vacuum Consumables
21  *
22  * @author Marcel Verpaalen - Initial contribution
23  */
24 @NonNullByDefault
25 public enum ConsumablesType {
26     MAIN_BRUSH(300, "Main Brush"),
27     SIDE_BRUSH(200, "Side Brush"),
28     FILTER(150, "Filter"),
29     SENSOR(30, "Sensor"),
30     UNKNOWN(0, "Unknown");
31
32     private final int lifeTime;
33     private final String description;
34
35     ConsumablesType(int lifeTime, String description) {
36         this.lifeTime = lifeTime;
37         this.description = description;
38     }
39
40     public static double remainingHours(int usedSeconds, ConsumablesType consumableType) {
41         return Math.max((double) consumableType.lifeTime - TimeUnit.SECONDS.toHours(usedSeconds), 0);
42     }
43
44     public static int remainingPercent(int usedSeconds, ConsumablesType consumableType) {
45         return (int) (100D * remainingHours(usedSeconds, consumableType) / consumableType.lifeTime);
46     }
47
48     public int getLifeTime() {
49         return lifeTime;
50     }
51
52     public String getDescription() {
53         return description;
54     }
55
56     @Override
57     public String toString() {
58         return description;
59     }
60 }