1
1
from typing import Optional
2
2
3
- from homeassistant .const import DEVICE_CLASS_TEMPERATURE , TEMP_CELSIUS , \
4
- DEVICE_CLASS_HUMIDITY , DEVICE_CLASS_ILLUMINANCE
3
+ from homeassistant .const import DEVICE_CLASS_TEMPERATURE , \
4
+ DEVICE_CLASS_HUMIDITY , DEVICE_CLASS_ILLUMINANCE , DEVICE_CLASS_POWER , \
5
+ DEVICE_CLASS_SIGNAL_STRENGTH
5
6
from homeassistant .helpers .entity import Entity
6
7
7
8
from . import DOMAIN , EWeLinkRegistry
8
9
from .sonoff_main import EWeLinkDevice
9
10
10
- SONOFF_SC = {
11
- 'temperature' : [DEVICE_CLASS_TEMPERATURE , TEMP_CELSIUS , None ],
11
+ SENSORS = {
12
+ 'temperature' : [DEVICE_CLASS_TEMPERATURE , '°C' , None ],
12
13
# UNIT_PERCENTAGE is not on old versions
13
- 'humidity' : [DEVICE_CLASS_HUMIDITY , "%" , None ],
14
+ 'humidity' : [DEVICE_CLASS_HUMIDITY , '%' , None ],
14
15
'dusty' : [None , None , 'mdi:cloud' ],
15
16
'light' : [DEVICE_CLASS_ILLUMINANCE , None , None ],
16
- 'noise' : [None , None , 'mdi:bell-ring' ]
17
+ 'noise' : [None , None , 'mdi:bell-ring' ],
18
+ 'power' : [DEVICE_CLASS_POWER , 'W' , None ],
19
+ 'current' : [DEVICE_CLASS_POWER , 'A' , None ],
20
+ 'voltage' : [DEVICE_CLASS_POWER , 'V' , None ],
21
+ 'rssi' : [DEVICE_CLASS_SIGNAL_STRENGTH , 'dBm' , None ]
17
22
}
18
23
24
+ SONOFF_SC = {'temperature' , 'humidity' , 'dusty' , 'light' , 'noise' }
25
+
19
26
20
27
async def async_setup_platform (hass , config , add_entities ,
21
28
discovery_info = None ):
@@ -24,13 +31,19 @@ async def async_setup_platform(hass, config, add_entities,
24
31
25
32
deviceid = discovery_info ['deviceid' ]
26
33
registry = hass .data [DOMAIN ]
34
+
35
+ if 'attribute' in discovery_info :
36
+ add_entities ([EWeLinkSensor (registry , deviceid ,
37
+ discovery_info ['attribute' ])])
38
+ return
39
+
27
40
device = registry .devices [deviceid ]
28
41
if device .get ('uiid' ) == 18 :
29
- add_entities ([SonoffSC (registry , deviceid , attr )
42
+ add_entities ([EWeLinkSensor (registry , deviceid , attr )
30
43
for attr in SONOFF_SC ])
31
44
32
45
33
- class SonoffSC (EWeLinkDevice , Entity ):
46
+ class EWeLinkSensor (EWeLinkDevice , Entity ):
34
47
_state = None
35
48
36
49
def __init__ (self , registry : EWeLinkRegistry , deviceid : str , attr : str ):
@@ -76,12 +89,12 @@ def available(self) -> bool:
76
89
77
90
@property
78
91
def device_class (self ):
79
- return SONOFF_SC [self ._attr ][0 ]
92
+ return SENSORS [self ._attr ][0 ] if self . _attr in SENSORS else None
80
93
81
94
@property
82
95
def unit_of_measurement (self ):
83
- return SONOFF_SC [self ._attr ][1 ]
96
+ return SENSORS [self ._attr ][1 ] if self . _attr in SENSORS else None
84
97
85
98
@property
86
99
def icon (self ):
87
- return SONOFF_SC [self ._attr ][2 ]
100
+ return SENSORS [self ._attr ][2 ] if self . _attr in SENSORS else None
0 commit comments