2
2
3
3
from __future__ import annotations
4
4
5
- from typing import TYPE_CHECKING
6
-
7
5
from ...feature import Feature
8
6
from ..smartmodule import SmartModule
9
7
10
- if TYPE_CHECKING :
11
- from ..smartdevice import SmartDevice
12
-
13
8
14
9
class BatterySensor (SmartModule ):
15
10
"""Implementation of battery module."""
16
11
17
12
REQUIRED_COMPONENT = "battery_detect"
18
13
QUERY_GETTER_NAME = "get_battery_detect_info"
19
14
20
- def __init__ (self , device : SmartDevice , module : str ):
21
- super (). __init__ ( device , module )
15
+ def _initialize_features (self ):
16
+ """Initialize features."""
22
17
self ._add_feature (
23
18
Feature (
24
- device ,
25
- "battery_level" ,
26
- "Battery level" ,
27
- container = self ,
28
- attribute_getter = "battery" ,
29
- icon = "mdi:battery" ,
30
- unit = "%" ,
31
- category = Feature .Category .Info ,
32
- )
33
- )
34
- self ._add_feature (
35
- Feature (
36
- device ,
19
+ self ._device ,
37
20
"battery_low" ,
38
21
"Battery low" ,
39
22
container = self ,
@@ -44,6 +27,22 @@ def __init__(self, device: SmartDevice, module: str):
44
27
)
45
28
)
46
29
30
+ # Some devices, like T110 contact sensor do not report the battery percentage
31
+ if "battery_percentage" in self ._device .sys_info :
32
+ self ._add_feature (
33
+ Feature (
34
+ self ._device ,
35
+ "battery_level" ,
36
+ "Battery level" ,
37
+ container = self ,
38
+ attribute_getter = "battery" ,
39
+ icon = "mdi:battery" ,
40
+ unit = "%" ,
41
+ category = Feature .Category .Info ,
42
+ type = Feature .Type .Sensor ,
43
+ )
44
+ )
45
+
47
46
@property
48
47
def battery (self ):
49
48
"""Return battery level."""
0 commit comments