@@ -10,19 +10,20 @@ async def async_setup_entry(hass, entry, async_add_devices):
10
10
"""Configure the sensor platform."""
11
11
central_sys = hass .data [DOMAIN ][entry .entry_id ]
12
12
13
- metrics = []
13
+ entities = []
14
+
14
15
for measurand in entry .data [CONF_MONITORED_VARIABLES ].split ("," ):
15
- metrics .append (
16
+ entities .append (
16
17
ChargePointMetric (measurand , central_sys , "M" , entry .data [CONF_NAME ])
17
18
)
18
19
for condition in CONDITIONS :
19
- metrics .append (
20
+ entities .append (
20
21
ChargePointMetric (condition , central_sys , "S" , entry .data [CONF_NAME ])
21
22
)
22
23
for gen in GENERAL :
23
- metrics .append (ChargePointMetric (gen , central_sys , "G" , entry .data [CONF_NAME ]))
24
+ entities .append (ChargePointMetric (gen , central_sys , "G" , entry .data [CONF_NAME ]))
24
25
25
- async_add_devices (metrics )
26
+ async_add_devices (entities )
26
27
27
28
28
29
class ChargePointMetric (Entity ):
@@ -32,6 +33,7 @@ def __init__(self, metric, central_sys, genre, prefix):
32
33
"""Instantiate instance of a ChargePointMetrics."""
33
34
self .metric = metric
34
35
self .central_sys = central_sys
36
+ self ._id = "." .join ([DOMAIN , "sensor" , self .central_sys .id , self .metric ])
35
37
self ._genre = genre
36
38
self .prefix = prefix
37
39
self ._state = None
@@ -40,13 +42,13 @@ def __init__(self, metric, central_sys, genre, prefix):
40
42
@property
41
43
def name (self ):
42
44
"""Return the name of the sensor."""
43
- return self .prefix + "." + self .metric
45
+ return DOMAIN + "." + self .prefix + "." + self .metric
44
46
45
47
@property
46
48
def unique_id (self ):
47
49
"""Return the unique id of this sensor."""
48
50
# This may need to be improved, perhaps use the vendor, model and serial number?
49
- return "." . join ([ "sensor" , self .central_sys . id , self . metric ])
51
+ return self ._id
50
52
51
53
@property
52
54
def state (self ):
@@ -68,6 +70,19 @@ def icon(self):
68
70
"""Return the icon to use in the frontend, if any."""
69
71
return ICON
70
72
73
+ @property
74
+ def device_info (self ):
75
+ """Return device information."""
76
+ return self .central_sys .device_info ()
77
+
78
+ @property
79
+ def extra_state_attributes (self ):
80
+ """Return the state attributes."""
81
+ return {
82
+ "unique_id" : self .unique_id ,
83
+ "integration" : DOMAIN ,
84
+ }
85
+
71
86
def update (self ):
72
87
"""Get the latest data and update the states."""
73
88
pass
0 commit comments