diff --git a/custom_components/battery_notes/__init__.py b/custom_components/battery_notes/__init__.py index fac414420..ad07fdde2 100644 --- a/custom_components/battery_notes/__init__.py +++ b/custom_components/battery_notes/__init__.py @@ -387,8 +387,8 @@ async def handle_battery_last_reported(call): hass.bus.async_fire( EVENT_BATTERY_NOT_REPORTED, { - ATTR_DEVICE_ID: device.coordinator.device_id, - ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id, + ATTR_DEVICE_ID: device.coordinator.device_id or "", + ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id or "", ATTR_DEVICE_NAME: device.coordinator.device_name, ATTR_BATTERY_TYPE_AND_QUANTITY: device.coordinator.battery_type_and_quantity, ATTR_BATTERY_TYPE: device.coordinator.battery_type, @@ -415,9 +415,9 @@ async def handle_battery_low(call): hass.bus.async_fire( EVENT_BATTERY_THRESHOLD, { - ATTR_DEVICE_ID: device.coordinator.device_id, + ATTR_DEVICE_ID: device.coordinator.device_id or "", ATTR_DEVICE_NAME: device.coordinator.device_name, - ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id, + ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id or "", ATTR_BATTERY_LOW: device.coordinator.battery_low, ATTR_BATTERY_TYPE_AND_QUANTITY: device.coordinator.battery_type_and_quantity, ATTR_BATTERY_TYPE: device.coordinator.battery_type, diff --git a/custom_components/battery_notes/coordinator.py b/custom_components/battery_notes/coordinator.py index 6a3a1046c..c4762a8af 100644 --- a/custom_components/battery_notes/coordinator.py +++ b/custom_components/battery_notes/coordinator.py @@ -109,8 +109,8 @@ def battery_low_template_state(self, value): self.hass.bus.async_fire( EVENT_BATTERY_THRESHOLD, { - ATTR_DEVICE_ID: self.device_id, - ATTR_SOURCE_ENTITY_ID: self.source_entity_id, + ATTR_DEVICE_ID: self.device_id or "", + ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "", ATTR_DEVICE_NAME: self.device_name, ATTR_BATTERY_LOW: self.battery_low, ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity, @@ -129,8 +129,8 @@ def battery_low_template_state(self, value): self.hass.bus.async_fire( EVENT_BATTERY_INCREASED, { - ATTR_DEVICE_ID: self.device_id, - ATTR_SOURCE_ENTITY_ID: self.source_entity_id, + ATTR_DEVICE_ID: self.device_id or "", + ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "", ATTR_DEVICE_NAME: self.device_name, ATTR_BATTERY_LOW: self.battery_low, ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity, @@ -159,8 +159,8 @@ def current_battery_level(self, value): self.hass.bus.async_fire( EVENT_BATTERY_THRESHOLD, { - ATTR_DEVICE_ID: self.device_id, - ATTR_SOURCE_ENTITY_ID: self.source_entity_id, + ATTR_DEVICE_ID: self.device_id or "", + ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "", ATTR_DEVICE_NAME: self.device_name, ATTR_BATTERY_LOW: self.battery_low, ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity, @@ -192,8 +192,8 @@ def current_battery_level(self, value): self.hass.bus.async_fire( EVENT_BATTERY_INCREASED, { - ATTR_DEVICE_ID: self.device_id, - ATTR_SOURCE_ENTITY_ID: self.source_entity_id, + ATTR_DEVICE_ID: self.device_id or "", + ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "", ATTR_DEVICE_NAME: self.device_name, ATTR_BATTERY_LOW: self.battery_low, ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity, diff --git a/custom_components/battery_notes/sensor.py b/custom_components/battery_notes/sensor.py index 914e7709f..d5b557b57 100644 --- a/custom_components/battery_notes/sensor.py +++ b/custom_components/battery_notes/sensor.py @@ -551,8 +551,8 @@ def extra_state_attributes(self) -> dict[str, str] | None: attrs[ATTR_BATTERY_LAST_REPLACED] = self.coordinator.last_replaced # Other attributes that should follow battery, attribute list is unsorted - attrs[ATTR_DEVICE_ID] = self.coordinator.device_id - attrs[ATTR_SOURCE_ENTITY_ID] = self.coordinator.source_entity_id + attrs[ATTR_DEVICE_ID] = self.coordinator.device_id or "" + attrs[ATTR_SOURCE_ENTITY_ID] = self.coordinator.source_entity_id or "" attrs[ATTR_DEVICE_NAME] = self.coordinator.device_name super_attrs = super().extra_state_attributes