Skip to content

Commit defea52

Browse files
Events fix (#1751)
* Ensure device and sensor not null * Device and entity id's blank not null
1 parent aea6db8 commit defea52

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

custom_components/battery_notes/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ async def handle_battery_last_reported(call):
387387
hass.bus.async_fire(
388388
EVENT_BATTERY_NOT_REPORTED,
389389
{
390-
ATTR_DEVICE_ID: device.coordinator.device_id,
391-
ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id,
390+
ATTR_DEVICE_ID: device.coordinator.device_id or "",
391+
ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id or "",
392392
ATTR_DEVICE_NAME: device.coordinator.device_name,
393393
ATTR_BATTERY_TYPE_AND_QUANTITY: device.coordinator.battery_type_and_quantity,
394394
ATTR_BATTERY_TYPE: device.coordinator.battery_type,
@@ -415,9 +415,9 @@ async def handle_battery_low(call):
415415
hass.bus.async_fire(
416416
EVENT_BATTERY_THRESHOLD,
417417
{
418-
ATTR_DEVICE_ID: device.coordinator.device_id,
418+
ATTR_DEVICE_ID: device.coordinator.device_id or "",
419419
ATTR_DEVICE_NAME: device.coordinator.device_name,
420-
ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id,
420+
ATTR_SOURCE_ENTITY_ID: device.coordinator.source_entity_id or "",
421421
ATTR_BATTERY_LOW: device.coordinator.battery_low,
422422
ATTR_BATTERY_TYPE_AND_QUANTITY: device.coordinator.battery_type_and_quantity,
423423
ATTR_BATTERY_TYPE: device.coordinator.battery_type,

custom_components/battery_notes/coordinator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def battery_low_template_state(self, value):
109109
self.hass.bus.async_fire(
110110
EVENT_BATTERY_THRESHOLD,
111111
{
112-
ATTR_DEVICE_ID: self.device_id,
113-
ATTR_SOURCE_ENTITY_ID: self.source_entity_id,
112+
ATTR_DEVICE_ID: self.device_id or "",
113+
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
114114
ATTR_DEVICE_NAME: self.device_name,
115115
ATTR_BATTERY_LOW: self.battery_low,
116116
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
@@ -129,8 +129,8 @@ def battery_low_template_state(self, value):
129129
self.hass.bus.async_fire(
130130
EVENT_BATTERY_INCREASED,
131131
{
132-
ATTR_DEVICE_ID: self.device_id,
133-
ATTR_SOURCE_ENTITY_ID: self.source_entity_id,
132+
ATTR_DEVICE_ID: self.device_id or "",
133+
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
134134
ATTR_DEVICE_NAME: self.device_name,
135135
ATTR_BATTERY_LOW: self.battery_low,
136136
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
@@ -159,8 +159,8 @@ def current_battery_level(self, value):
159159
self.hass.bus.async_fire(
160160
EVENT_BATTERY_THRESHOLD,
161161
{
162-
ATTR_DEVICE_ID: self.device_id,
163-
ATTR_SOURCE_ENTITY_ID: self.source_entity_id,
162+
ATTR_DEVICE_ID: self.device_id or "",
163+
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
164164
ATTR_DEVICE_NAME: self.device_name,
165165
ATTR_BATTERY_LOW: self.battery_low,
166166
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
@@ -192,8 +192,8 @@ def current_battery_level(self, value):
192192
self.hass.bus.async_fire(
193193
EVENT_BATTERY_INCREASED,
194194
{
195-
ATTR_DEVICE_ID: self.device_id,
196-
ATTR_SOURCE_ENTITY_ID: self.source_entity_id,
195+
ATTR_DEVICE_ID: self.device_id or "",
196+
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
197197
ATTR_DEVICE_NAME: self.device_name,
198198
ATTR_BATTERY_LOW: self.battery_low,
199199
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,

custom_components/battery_notes/sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ def extra_state_attributes(self) -> dict[str, str] | None:
551551
attrs[ATTR_BATTERY_LAST_REPLACED] = self.coordinator.last_replaced
552552

553553
# Other attributes that should follow battery, attribute list is unsorted
554-
attrs[ATTR_DEVICE_ID] = self.coordinator.device_id
555-
attrs[ATTR_SOURCE_ENTITY_ID] = self.coordinator.source_entity_id
554+
attrs[ATTR_DEVICE_ID] = self.coordinator.device_id or ""
555+
attrs[ATTR_SOURCE_ENTITY_ID] = self.coordinator.source_entity_id or ""
556556
attrs[ATTR_DEVICE_NAME] = self.coordinator.device_name
557557

558558
super_attrs = super().extra_state_attributes

0 commit comments

Comments
 (0)