Skip to content

Commit

Permalink
Events fix (#1751)
Browse files Browse the repository at this point in the history
* Ensure device and sensor not null

* Device and entity id's blank not null
  • Loading branch information
andrew-codechimp authored Jun 12, 2024
1 parent aea6db8 commit defea52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions custom_components/battery_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions custom_components/battery_notes/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/battery_notes/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit defea52

Please sign in to comment.