|
25 | 25 | Event, |
26 | 26 | HomeAssistant, |
27 | 27 | callback, |
28 | | - split_entity_id, |
29 | 28 | ) |
30 | 29 | from homeassistant.exceptions import TemplateError |
31 | 30 | from homeassistant.helpers import ( |
|
54 | 53 | TemplateStateFromEntityId, |
55 | 54 | ) |
56 | 55 |
|
57 | | -from .common import utcnow_no_timezone, validate_is_float |
| 56 | +from .common import ( |
| 57 | + utcnow_no_timezone, |
| 58 | + validate_is_float, |
| 59 | +) |
58 | 60 | from .const import ( |
59 | 61 | ATTR_BATTERY_LAST_REPLACED, |
60 | 62 | ATTR_BATTERY_LOW_THRESHOLD, |
@@ -288,23 +290,6 @@ def __init__( |
288 | 290 | self._template_attrs: dict[Template, list[_TemplateAttribute]] = {} |
289 | 291 | self._template_result_info: TrackTemplateResultInfo | None = None |
290 | 292 |
|
291 | | - if coordinator.source_entity_id and not coordinator.device_id: |
292 | | - self._attr_translation_placeholders = { |
293 | | - "device_name": coordinator.device_name + " " |
294 | | - } |
295 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
296 | | - elif coordinator.source_entity_id and coordinator.device_id: |
297 | | - _, source_object_id = split_entity_id(coordinator.source_entity_id) |
298 | | - self._attr_translation_placeholders = { |
299 | | - "device_name": coordinator.source_entity_name + " " |
300 | | - } |
301 | | - self.entity_id = ( |
302 | | - f"binary_sensor.{source_object_id}_{entity_description.key}" |
303 | | - ) |
304 | | - else: |
305 | | - self._attr_translation_placeholders = {"device_name": ""} |
306 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
307 | | - |
308 | 293 | self._template = battery_low_template |
309 | 294 | self._state: bool | None = None |
310 | 295 |
|
@@ -476,23 +461,6 @@ def __init__( |
476 | 461 | hass=hass, coordinator=coordinator, entity_description=entity_description |
477 | 462 | ) |
478 | 463 |
|
479 | | - if coordinator.source_entity_id and not coordinator.device_id: |
480 | | - self._attr_translation_placeholders = { |
481 | | - "device_name": coordinator.device_name + " " |
482 | | - } |
483 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
484 | | - elif coordinator.source_entity_id and coordinator.device_id: |
485 | | - _, source_object_id = split_entity_id(coordinator.source_entity_id) |
486 | | - self._attr_translation_placeholders = { |
487 | | - "device_name": coordinator.source_entity_name + " " |
488 | | - } |
489 | | - self.entity_id = ( |
490 | | - f"binary_sensor.{source_object_id}_{entity_description.key}" |
491 | | - ) |
492 | | - else: |
493 | | - self._attr_translation_placeholders = {"device_name": ""} |
494 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
495 | | - |
496 | 464 | self._attr_unique_id = unique_id |
497 | 465 |
|
498 | 466 | async def async_added_to_hass(self) -> None: |
@@ -538,29 +506,13 @@ def __init__( |
538 | 506 | unique_id: str, |
539 | 507 | ) -> None: |
540 | 508 | """Create a low battery binary sensor.""" |
| 509 | + |
| 510 | + self._attr_unique_id = unique_id |
| 511 | + |
541 | 512 | super().__init__( |
542 | 513 | hass=hass, coordinator=coordinator, entity_description=entity_description |
543 | 514 | ) |
544 | 515 |
|
545 | | - if coordinator.source_entity_id and not coordinator.device_id: |
546 | | - self._attr_translation_placeholders = { |
547 | | - "device_name": coordinator.device_name + " " |
548 | | - } |
549 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
550 | | - elif coordinator.source_entity_id and coordinator.device_id: |
551 | | - _, source_object_id = split_entity_id(coordinator.source_entity_id) |
552 | | - self._attr_translation_placeholders = { |
553 | | - "device_name": coordinator.source_entity_name + " " |
554 | | - } |
555 | | - self.entity_id = ( |
556 | | - f"binary_sensor.{source_object_id}_{entity_description.key}" |
557 | | - ) |
558 | | - else: |
559 | | - self._attr_translation_placeholders = {"device_name": ""} |
560 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
561 | | - |
562 | | - self._attr_unique_id = unique_id |
563 | | - |
564 | 516 | async def async_added_to_hass(self) -> None: |
565 | 517 | """Handle added to Hass.""" |
566 | 518 |
|
@@ -620,23 +572,6 @@ def __init__( |
620 | 572 | hass=hass, coordinator=coordinator, entity_description=entity_description |
621 | 573 | ) |
622 | 574 |
|
623 | | - if coordinator.source_entity_id and not coordinator.device_id: |
624 | | - self._attr_translation_placeholders = { |
625 | | - "device_name": coordinator.device_name + " " |
626 | | - } |
627 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
628 | | - elif coordinator.source_entity_id and coordinator.device_id: |
629 | | - _, source_object_id = split_entity_id(coordinator.source_entity_id) |
630 | | - self._attr_translation_placeholders = { |
631 | | - "device_name": coordinator.source_entity_name + " " |
632 | | - } |
633 | | - self.entity_id = ( |
634 | | - f"binary_sensor.{source_object_id}_{entity_description.key}" |
635 | | - ) |
636 | | - else: |
637 | | - self._attr_translation_placeholders = {"device_name": ""} |
638 | | - self.entity_id = f"binary_sensor.{coordinator.device_name.lower()}_{entity_description.key}" |
639 | | - |
640 | 575 | self._attr_unique_id = unique_id |
641 | 576 |
|
642 | 577 | self._state: bool | None = None |
|
0 commit comments