@@ -146,8 +146,9 @@ def __init__(
146146 self .config_entry .data .get (CONF_BATTERY_LOW_THRESHOLD , 0 )
147147 )
148148
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
151152
152153 self .battery_low_template = self .config_entry .data .get (
153154 CONF_BATTERY_LOW_TEMPLATE
@@ -594,6 +595,9 @@ def battery_type_and_quantity(self) -> str:
594595 @property
595596 def last_replaced (self ) -> datetime | None :
596597 """Get the last replaced datetime."""
598+ if not hasattr (self .config_entry , "runtime_data" ):
599+ return None
600+
597601 if self .source_entity_id :
598602 entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
599603 else :
@@ -610,6 +614,9 @@ def last_replaced(self) -> datetime | None:
610614 @last_replaced .setter
611615 def last_replaced (self , value : datetime ):
612616 """Set the last replaced datetime and store it."""
617+ if not hasattr (self .config_entry , "runtime_data" ):
618+ return
619+
613620 entry = {LAST_REPLACED : value }
614621
615622 if self .source_entity_id :
@@ -621,6 +628,9 @@ def last_replaced(self, value: datetime):
621628 def last_reported (self ) -> datetime | None :
622629 """Get the last reported datetime."""
623630
631+ if not hasattr (self .config_entry , "runtime_data" ):
632+ return None
633+
624634 if self .source_entity_id :
625635 entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
626636 else :
@@ -639,6 +649,10 @@ def last_reported(self) -> datetime | None:
639649 @last_reported .setter
640650 def last_reported (self , value ):
641651 """Set the last reported datetime and store it."""
652+
653+ if not hasattr (self .config_entry , "runtime_data" ):
654+ return
655+
642656 entry = {LAST_REPORTED : value }
643657
644658 if self .source_entity_id :
@@ -650,6 +664,8 @@ def last_reported(self, value):
650664 @property
651665 def last_reported_level (self ) -> float | None :
652666 """Get the last reported level."""
667+ if not hasattr (self .config_entry , "runtime_data" ):
668+ return None
653669
654670 if self .source_entity_id :
655671 entry = self .config_entry .runtime_data .store .async_get_entity (self .source_entity_id )
@@ -715,6 +731,9 @@ async def _async_update_data(self):
715731 def async_update_device_config (self , device_id : str , data : dict ):
716732 """Conditional create, update or remove device from store."""
717733
734+ if not hasattr (self .config_entry , "runtime_data" ):
735+ return
736+
718737 if ATTR_REMOVE in data :
719738 self .config_entry .runtime_data .store .async_delete_device (device_id )
720739 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):
725744 def async_update_entity_config (self , entity_id : str , data : dict ):
726745 """Conditional create, update or remove entity from store."""
727746
747+ if not hasattr (self .config_entry , "runtime_data" ):
748+ return
749+
728750 if ATTR_REMOVE in data :
729751 self .config_entry .runtime_data .store .async_delete_entity (entity_id )
730752 elif self .config_entry .runtime_data .store .async_get_entity (entity_id ):
0 commit comments