@@ -146,8 +146,9 @@ def __init__(
146
146
self .config_entry .data .get (CONF_BATTERY_LOW_THRESHOLD , 0 )
147
147
)
148
148
149
- if self .battery_low_threshold == 0 :
150
- self .battery_low_threshold = self .config_entry .runtime_data .domain_config .default_battery_low_threshold
149
+ if hasattr (self .config_entry , "runtime_data" ):
150
+ if self .battery_low_threshold == 0 :
151
+ self .battery_low_threshold = self .config_entry .runtime_data .domain_config .default_battery_low_threshold
151
152
152
153
self .battery_low_template = self .config_entry .data .get (
153
154
CONF_BATTERY_LOW_TEMPLATE
@@ -594,6 +595,9 @@ def battery_type_and_quantity(self) -> str:
594
595
@property
595
596
def last_replaced (self ) -> datetime | None :
596
597
"""Get the last replaced datetime."""
598
+ if not hasattr (self .config_entry , "runtime_data" ):
599
+ return None
600
+
597
601
if self .source_entity_id :
598
602
entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
599
603
else :
@@ -610,6 +614,9 @@ def last_replaced(self) -> datetime | None:
610
614
@last_replaced .setter
611
615
def last_replaced (self , value : datetime ):
612
616
"""Set the last replaced datetime and store it."""
617
+ if not hasattr (self .config_entry , "runtime_data" ):
618
+ return
619
+
613
620
entry = {LAST_REPLACED : value }
614
621
615
622
if self .source_entity_id :
@@ -621,6 +628,9 @@ def last_replaced(self, value: datetime):
621
628
def last_reported (self ) -> datetime | None :
622
629
"""Get the last reported datetime."""
623
630
631
+ if not hasattr (self .config_entry , "runtime_data" ):
632
+ return None
633
+
624
634
if self .source_entity_id :
625
635
entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
626
636
else :
@@ -639,6 +649,10 @@ def last_reported(self) -> datetime | None:
639
649
@last_reported .setter
640
650
def last_reported (self , value ):
641
651
"""Set the last reported datetime and store it."""
652
+
653
+ if not hasattr (self .config_entry , "runtime_data" ):
654
+ return
655
+
642
656
entry = {LAST_REPORTED : value }
643
657
644
658
if self .source_entity_id :
@@ -650,6 +664,8 @@ def last_reported(self, value):
650
664
@property
651
665
def last_reported_level (self ) -> float | None :
652
666
"""Get the last reported level."""
667
+ if not hasattr (self .config_entry , "runtime_data" ):
668
+ return None
653
669
654
670
if self .source_entity_id :
655
671
entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
@@ -715,6 +731,9 @@ async def _async_update_data(self):
715
731
def async_update_device_config (self , device_id : str , data : dict ):
716
732
"""Conditional create, update or remove device from store."""
717
733
734
+ if not hasattr (self .config_entry , "runtime_data" ):
735
+ return
736
+
718
737
if ATTR_REMOVE in data :
719
738
self .config_entry .runtime_data .store .async_delete_device (device_id )
720
739
elif self .config_entry .runtime_data .store .async_get_device (device_id ):
@@ -725,6 +744,9 @@ def async_update_device_config(self, device_id: str, data: dict):
725
744
def async_update_entity_config (self , entity_id : str , data : dict ):
726
745
"""Conditional create, update or remove entity from store."""
727
746
747
+ if not hasattr (self .config_entry , "runtime_data" ):
748
+ return
749
+
728
750
if ATTR_REMOVE in data :
729
751
self .config_entry .runtime_data .store .async_delete_entity (entity_id )
730
752
elif self .config_entry .runtime_data .store .async_get_entity (entity_id ):
0 commit comments