@@ -261,14 +261,102 @@ async def async_setup_entry(
261
261
"""Set up the habitica sensors."""
262
262
263
263
coordinator = config_entry .runtime_data
264
+ ent_reg = er .async_get (hass )
265
+ entities : list [SensorEntity ] = []
266
+ description : SensorEntityDescription
267
+ for description in SENSOR_DESCRIPTIONS :
268
+ if description .key is HabitipySensorEntity .HEALTH_MAX :
269
+ if entity_id := ent_reg .async_get_entity_id (
270
+ SENSOR_DOMAIN ,
271
+ DOMAIN ,
272
+ f"{ config_entry .unique_id } _{ description .key } " ,
273
+ ):
274
+ entity_entry = ent_reg .async_get (entity_id )
275
+ assert entity_entry
276
+ if entity_entry .disabled :
277
+ ent_reg .async_remove (entity_id )
278
+ async_delete_issue (
279
+ hass ,
280
+ DOMAIN ,
281
+ f"deprecated_entity_{ description .key } " ,
282
+ )
283
+ else :
284
+ entities .append (HabitipySensor (coordinator , description ))
285
+ if entity_used_in (hass , entity_id ):
286
+ async_create_issue (
287
+ hass ,
288
+ DOMAIN ,
289
+ f"deprecated_entity_{ description .key } " ,
290
+ breaks_in_ha_version = "2025.8.0" ,
291
+ is_fixable = False ,
292
+ severity = IssueSeverity .WARNING ,
293
+ translation_key = "deprecated_entity" ,
294
+ translation_placeholders = {
295
+ "name" : str (
296
+ entity_entry .name or entity_entry .original_name
297
+ ),
298
+ "entity" : entity_id ,
299
+ },
300
+ )
301
+ else :
302
+ entities .append (HabitipySensor (coordinator , description ))
303
+
304
+ for description in TASK_SENSOR_DESCRIPTION :
305
+ if entity_id := ent_reg .async_get_entity_id (
306
+ SENSOR_DOMAIN ,
307
+ DOMAIN ,
308
+ f"{ config_entry .unique_id } _{ description .key } " ,
309
+ ):
310
+ entity_entry = ent_reg .async_get (entity_id )
311
+ assert entity_entry
312
+ if entity_entry .disabled :
313
+ ent_reg .async_remove (entity_id )
314
+ async_delete_issue (
315
+ hass ,
316
+ DOMAIN ,
317
+ f"deprecated_task_entity_{ description .key } " ,
318
+ )
319
+ else :
320
+ entities .append (HabitipyTaskSensor (coordinator , description ))
321
+ if description .key in (
322
+ HabitipySensorEntity .TODOS ,
323
+ HabitipySensorEntity .DAILIES ,
324
+ ) and entity_used_in (hass , entity_id ):
325
+ async_create_issue (
326
+ hass ,
327
+ DOMAIN ,
328
+ f"deprecated_task_entity_{ description .key } " ,
329
+ breaks_in_ha_version = "2025.2.0" ,
330
+ is_fixable = False ,
331
+ severity = IssueSeverity .WARNING ,
332
+ translation_key = "deprecated_task_entity" ,
333
+ translation_placeholders = {
334
+ "task_name" : str (
335
+ entity_entry .name or entity_entry .original_name
336
+ ),
337
+ "entity" : entity_id ,
338
+ },
339
+ )
340
+ elif description .key in (
341
+ HabitipySensorEntity .REWARDS ,
342
+ HabitipySensorEntity .HABITS ,
343
+ ) and entity_used_in (hass , entity_id ):
344
+ async_create_issue (
345
+ hass ,
346
+ DOMAIN ,
347
+ f"deprecated_task_entity_{ description .key } " ,
348
+ breaks_in_ha_version = "2025.8.0" ,
349
+ is_fixable = False ,
350
+ severity = IssueSeverity .WARNING ,
351
+ translation_key = "deprecated_entity" ,
352
+ translation_placeholders = {
353
+ "name" : str (
354
+ entity_entry .name or entity_entry .original_name
355
+ ),
356
+ "entity" : entity_id ,
357
+ },
358
+ )
264
359
265
- entities : list [SensorEntity ] = [
266
- HabitipySensor (coordinator , description ) for description in SENSOR_DESCRIPTIONS
267
- ]
268
- entities .extend (
269
- HabitipyTaskSensor (coordinator , description )
270
- for description in TASK_SENSOR_DESCRIPTION
271
- )
272
360
async_add_entities (entities , True )
273
361
274
362
@@ -303,33 +391,7 @@ async def async_added_to_hass(self) -> None:
303
391
"""Raise issue when entity is registered and was not disabled."""
304
392
if TYPE_CHECKING :
305
393
assert self .unique_id
306
- if entity_id := er .async_get (self .hass ).async_get_entity_id (
307
- SENSOR_DOMAIN , DOMAIN , self .unique_id
308
- ):
309
- if (
310
- self .enabled
311
- and self .entity_description .key is HabitipySensorEntity .HEALTH_MAX
312
- and entity_used_in (self .hass , entity_id )
313
- ):
314
- async_create_issue (
315
- self .hass ,
316
- DOMAIN ,
317
- f"deprecated_entity_{ self .entity_description .key } " ,
318
- breaks_in_ha_version = "2025.8.0" ,
319
- is_fixable = False ,
320
- severity = IssueSeverity .WARNING ,
321
- translation_key = "deprecated_entity" ,
322
- translation_placeholders = {
323
- "name" : str (self .name ),
324
- "entity" : entity_id ,
325
- },
326
- )
327
- else :
328
- async_delete_issue (
329
- self .hass ,
330
- DOMAIN ,
331
- f"deprecated_entity_{ self .entity_description .key } " ,
332
- )
394
+
333
395
await super ().async_added_to_hass ()
334
396
335
397
@@ -359,56 +421,3 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
359
421
task [map_key ] = value
360
422
attrs [str (task_id )] = task
361
423
return attrs
362
-
363
- async def async_added_to_hass (self ) -> None :
364
- """Raise issue when entity is registered and was not disabled."""
365
- if TYPE_CHECKING :
366
- assert self .unique_id
367
- if entity_id := er .async_get (self .hass ).async_get_entity_id (
368
- SENSOR_DOMAIN , DOMAIN , self .unique_id
369
- ):
370
- if (
371
- self .enabled
372
- and self .entity_description .key
373
- in (HabitipySensorEntity .TODOS , HabitipySensorEntity .DAILIES )
374
- and entity_used_in (self .hass , entity_id )
375
- ):
376
- async_create_issue (
377
- self .hass ,
378
- DOMAIN ,
379
- f"deprecated_task_entity_{ self .entity_description .key } " ,
380
- breaks_in_ha_version = "2025.2.0" ,
381
- is_fixable = False ,
382
- severity = IssueSeverity .WARNING ,
383
- translation_key = "deprecated_task_entity" ,
384
- translation_placeholders = {
385
- "task_name" : str (self .name ),
386
- "entity" : entity_id ,
387
- },
388
- )
389
- elif (
390
- self .enabled
391
- and self .entity_description .key
392
- in (HabitipySensorEntity .REWARDS , HabitipySensorEntity .HABITS )
393
- and entity_used_in (self .hass , entity_id )
394
- ):
395
- async_create_issue (
396
- self .hass ,
397
- DOMAIN ,
398
- f"deprecated_task_entity_{ self .entity_description .key } " ,
399
- breaks_in_ha_version = "2025.8.0" ,
400
- is_fixable = False ,
401
- severity = IssueSeverity .WARNING ,
402
- translation_key = "deprecated_entity" ,
403
- translation_placeholders = {
404
- "name" : str (self .name ),
405
- "entity" : entity_id ,
406
- },
407
- )
408
- else :
409
- async_delete_issue (
410
- self .hass ,
411
- DOMAIN ,
412
- f"deprecated_task_entity_{ self .entity_description .key } " ,
413
- )
414
- await super ().async_added_to_hass ()
0 commit comments