Skip to content

Commit 41f1dfe

Browse files
Add area name to all services/events
1 parent ebe9d9c commit 41f1dfe

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

custom_components/battery_notes/coordinator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from .common import validate_is_float
3636
from .const import (
37+
ATTR_AREA_NAME,
3738
ATTR_BATTERY_LAST_REPLACED,
3839
ATTR_BATTERY_LEVEL,
3940
ATTR_BATTERY_LOW,
@@ -476,6 +477,7 @@ def battery_low_template_state(self, value):
476477
{
477478
ATTR_DEVICE_ID: self.device_id or "",
478479
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
480+
ATTR_AREA_NAME: self.area_name,
479481
ATTR_DEVICE_NAME: self.device_name,
480482
ATTR_BATTERY_LOW: self.battery_low,
481483
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
@@ -509,6 +511,7 @@ def battery_low_template_state(self, value):
509511
{
510512
ATTR_DEVICE_ID: self.device_id or "",
511513
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
514+
ATTR_AREA_NAME: self.area_name,
512515
ATTR_DEVICE_NAME: self.device_name,
513516
ATTR_BATTERY_LOW: self.battery_low,
514517
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
@@ -544,6 +547,7 @@ def battery_low_binary_state(self, value):
544547
{
545548
ATTR_DEVICE_ID: self.device_id or "",
546549
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
550+
ATTR_AREA_NAME: self.area_name,
547551
ATTR_DEVICE_NAME: self.device_name,
548552
ATTR_BATTERY_LOW: self.battery_low,
549553
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
@@ -577,6 +581,7 @@ def battery_low_binary_state(self, value):
577581
{
578582
ATTR_DEVICE_ID: self.device_id or "",
579583
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
584+
ATTR_AREA_NAME: self.area_name,
580585
ATTR_DEVICE_NAME: self.device_name,
581586
ATTR_BATTERY_LOW: self.battery_low,
582587
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
@@ -630,6 +635,7 @@ def current_battery_level(self, value):
630635
{
631636
ATTR_DEVICE_ID: self.device_id or "",
632637
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
638+
ATTR_AREA_NAME: self.area_name,
633639
ATTR_DEVICE_NAME: self.device_name,
634640
ATTR_BATTERY_LOW: self.battery_low,
635641
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
@@ -666,6 +672,7 @@ def current_battery_level(self, value):
666672
{
667673
ATTR_DEVICE_ID: self.device_id or "",
668674
ATTR_SOURCE_ENTITY_ID: self.source_entity_id or "",
675+
ATTR_AREA_NAME: self.area_name,
669676
ATTR_DEVICE_NAME: self.device_name,
670677
ATTR_BATTERY_LOW: self.battery_low,
671678
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,

custom_components/battery_notes/services.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ async def _async_battery_replaced(call: ServiceCall) -> ServiceResponse: # noqa
146146
{
147147
ATTR_DEVICE_ID: coordinator.device_id or "",
148148
ATTR_SOURCE_ENTITY_ID: coordinator.source_entity_id or "",
149+
ATTR_AREA_NAME: coordinator.area_name,
149150
ATTR_DEVICE_NAME: coordinator.device_name,
150151
ATTR_BATTERY_TYPE_AND_QUANTITY: coordinator.battery_type_and_quantity,
151152
ATTR_BATTERY_TYPE: coordinator.battery_type,
@@ -203,6 +204,7 @@ async def _async_battery_replaced(call: ServiceCall) -> ServiceResponse: # noqa
203204
{
204205
ATTR_DEVICE_ID: coordinator.device_id or "",
205206
ATTR_SOURCE_ENTITY_ID: coordinator.source_entity_id or "",
207+
ATTR_AREA_NAME: coordinator.area_name,
206208
ATTR_DEVICE_NAME: coordinator.device_name,
207209
ATTR_BATTERY_TYPE_AND_QUANTITY: coordinator.battery_type_and_quantity,
208210
ATTR_BATTERY_TYPE: coordinator.battery_type,
@@ -272,8 +274,8 @@ async def _async_battery_last_replaced(call: ServiceCall) -> ServiceResponse:
272274
ATTR_DEVICE_ID: coordinator.device_id or "",
273275
ATTR_SOURCE_ENTITY_ID: coordinator.source_entity_id
274276
or "",
275-
ATTR_DEVICE_NAME: coordinator.device_name,
276277
ATTR_AREA_NAME: coordinator.area_name,
278+
ATTR_DEVICE_NAME: coordinator.device_name,
277279
ATTR_BATTERY_TYPE_AND_QUANTITY: coordinator.battery_type_and_quantity,
278280
ATTR_BATTERY_TYPE: coordinator.battery_type,
279281
ATTR_BATTERY_QUANTITY: coordinator.battery_quantity,
@@ -354,8 +356,8 @@ async def _async_battery_last_reported(call: ServiceCall) -> ServiceResponse:
354356
ATTR_DEVICE_ID: coordinator.device_id or "",
355357
ATTR_SOURCE_ENTITY_ID: coordinator.source_entity_id
356358
or "",
357-
ATTR_DEVICE_NAME: coordinator.device_name,
358359
ATTR_AREA_NAME: coordinator.area_name,
360+
ATTR_DEVICE_NAME: coordinator.device_name,
359361
ATTR_BATTERY_TYPE_AND_QUANTITY: coordinator.battery_type_and_quantity,
360362
ATTR_BATTERY_TYPE: coordinator.battery_type,
361363
ATTR_BATTERY_QUANTITY: coordinator.battery_quantity,

0 commit comments

Comments
 (0)