@@ -150,7 +150,7 @@ async def async_step_device(
150
150
user_input : dict | None = None ,
151
151
) -> config_entries .FlowResult :
152
152
"""Handle a flow for a device or discovery."""
153
- _errors = {}
153
+ errors : dict [ str , str ] = {}
154
154
if user_input is not None :
155
155
self .data = user_input
156
156
@@ -205,7 +205,7 @@ async def async_step_device(
205
205
return self .async_show_form (
206
206
step_id = "device" ,
207
207
data_schema = schema ,
208
- errors = _errors ,
208
+ errors = errors ,
209
209
last_step = False ,
210
210
)
211
211
@@ -214,7 +214,7 @@ async def async_step_entity(
214
214
user_input : dict | None = None ,
215
215
) -> config_entries .FlowResult :
216
216
"""Handle a flow for a device or discovery."""
217
- _errors = {}
217
+ errors : dict [ str , str ] = {}
218
218
if user_input is not None :
219
219
self .data = user_input
220
220
@@ -226,52 +226,57 @@ async def async_step_entity(
226
226
# Default battery quantity if not found in library lookup
227
227
self .data [CONF_BATTERY_QUANTITY ] = 1
228
228
229
- if entity_entry . device_id :
229
+ if entity_entry :
230
230
231
- self . data [ CONF_DEVICE_ID ] = entity_entry .device_id
231
+ if entity_entry .device_id :
232
232
233
- if (
234
- DOMAIN in self .hass .data
235
- and DATA_LIBRARY_UPDATER in self .hass .data [DOMAIN ]
236
- ):
237
- library_updater : LibraryUpdater = self .hass .data [DOMAIN ][
238
- DATA_LIBRARY_UPDATER
239
- ]
240
- await library_updater .get_library_updates (dt_util .utcnow ())
233
+ self .data [CONF_DEVICE_ID ] = entity_entry .device_id
241
234
242
- device_registry = dr .async_get (self .hass )
243
- device_entry = device_registry .async_get (entity_entry .device_id )
235
+ if (
236
+ DOMAIN in self .hass .data
237
+ and DATA_LIBRARY_UPDATER in self .hass .data [DOMAIN ]
238
+ ):
239
+ library_updater : LibraryUpdater = self .hass .data [DOMAIN ][
240
+ DATA_LIBRARY_UPDATER
241
+ ]
242
+ await library_updater .get_library_updates (dt_util .utcnow ())
244
243
245
- _LOGGER .debug (
246
- "Looking up device %s %s %s" , device_entry .manufacturer , device_entry .model , device_entry .hw_version
247
- )
244
+ device_registry = dr .async_get (self .hass )
245
+ device_entry = device_registry .async_get (entity_entry .device_id )
248
246
249
- model_info = ModelInfo (device_entry .manufacturer , device_entry .model , device_entry .hw_version )
247
+ _LOGGER .debug (
248
+ "Looking up device %s %s %s" , device_entry .manufacturer , device_entry .model , device_entry .hw_version
249
+ )
250
250
251
- library = await Library . factory ( self . hass )
251
+ model_info = ModelInfo ( device_entry . manufacturer , device_entry . model , device_entry . hw_version )
252
252
253
- device_battery_details = await library .get_device_battery_details (
254
- model_info
255
- )
253
+ library = await Library .factory (self .hass )
256
254
257
- if device_battery_details and not device_battery_details .is_manual :
258
- _LOGGER .debug (
259
- "Found device %s %s %s" , device_entry .manufacturer , device_entry .model , device_entry .hw_version
255
+ device_battery_details = await library .get_device_battery_details (
256
+ model_info
260
257
)
261
- self .data [CONF_BATTERY_TYPE ] = device_battery_details .battery_type
262
258
263
- self .data [
264
- CONF_BATTERY_QUANTITY
265
- ] = device_battery_details .battery_quantity
259
+ if device_battery_details and not device_battery_details .is_manual :
260
+ _LOGGER .debug (
261
+ "Found device %s %s %s" , device_entry .manufacturer , device_entry .model , device_entry .hw_version
262
+ )
263
+ self .data [CONF_BATTERY_TYPE ] = device_battery_details .battery_type
266
264
267
- return await self .async_step_battery ()
265
+ self .data [
266
+ CONF_BATTERY_QUANTITY
267
+ ] = device_battery_details .battery_quantity
268
+
269
+ return await self .async_step_battery ()
270
+ else :
271
+ # No entity_registry entry, must be a config.yaml entity which we can't support
272
+ errors ["base" ] = "unconfigurable_entity"
268
273
269
274
schema = ENTITY_SCHEMA_ALL
270
275
271
276
return self .async_show_form (
272
277
step_id = "entity" ,
273
278
data_schema = schema ,
274
- errors = _errors ,
279
+ errors = errors ,
275
280
last_step = False ,
276
281
)
277
282
0 commit comments