@@ -108,39 +108,41 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
108
108
if cd is not None :
109
109
# Retrieve the available operationModes, we can only provide consumption data for
110
110
# supported operation modes
111
- operation_modes = management_point ["operationMode" ]["values" ]
112
- cdv = cd .get ("value" )
113
- if cdv is not None :
114
- cdve = cdv .get ("electrical" )
115
- if cdve is not None :
116
- _LOGGER .info ("Device '%s' provides electrical" , device .name )
117
- for mode in cdve :
118
- # Only handle consumptionData for an operation mode supported by this device
119
- if mode in operation_modes :
120
- _LOGGER .info (
121
- "Device '%s' provides mode %s %s" ,
122
- device .name ,
123
- management_point_type ,
124
- mode ,
125
- )
126
- for period in cdve [mode ]:
111
+ opmode = management_point .get ("operationMode" )
112
+ if opmode is not None :
113
+ operation_modes = opmode ["values" ]
114
+ cdv = cd .get ("value" )
115
+ if cdv is not None :
116
+ cdve = cdv .get ("electrical" )
117
+ if cdve is not None :
118
+ _LOGGER .info ("Device '%s' provides electrical" , device .name )
119
+ for mode in cdve :
120
+ # Only handle consumptionData for an operation mode supported by this device
121
+ if mode in operation_modes :
127
122
_LOGGER .info (
128
- "Device '%s:%s ' provides mode %s %s supports period %s" ,
123
+ "Device '%s' provides mode %s %s" ,
129
124
device .name ,
130
- embedded_id ,
131
125
management_point_type ,
132
126
mode ,
133
- period ,
134
127
)
135
- periodName = SENSOR_PERIODS [period ]
136
- sensor = f"{ device .name } { management_point_type } { mode } { periodName } "
137
- _LOGGER .info ("Proposing sensor '%s'" , sensor )
138
- sensors .append (DaikinEnergySensor (device , coordinator , embedded_id , management_point_type , mode , period ))
139
- else :
140
- _LOGGER .info (
141
- "Ignoring consumption data '%s', not a supported operation_mode" ,
142
- mode ,
143
- )
128
+ for period in cdve [mode ]:
129
+ _LOGGER .info (
130
+ "Device '%s:%s' provides mode %s %s supports period %s" ,
131
+ device .name ,
132
+ embedded_id ,
133
+ management_point_type ,
134
+ mode ,
135
+ period ,
136
+ )
137
+ periodName = SENSOR_PERIODS [period ]
138
+ sensor = f"{ device .name } { management_point_type } { mode } { periodName } "
139
+ _LOGGER .info ("Proposing sensor '%s'" , sensor )
140
+ sensors .append (DaikinEnergySensor (device , coordinator , embedded_id , management_point_type , mode , period ))
141
+ else :
142
+ _LOGGER .info (
143
+ "Ignoring consumption data '%s', not a supported operation_mode" ,
144
+ mode ,
145
+ )
144
146
145
147
async_add_entities (sensors )
146
148
0 commit comments