Skip to content

Commit 8c1c6e3

Browse files
andrew-codechimpgithub-actions[bot]gsemetnepozsmikosoft83
authored
Low templates (#1038)
* Start of config flow for template * WIP * Config template entity chooser * WIP * Add template config to coordinator * Add battery low if template configured * Docs * Update device: Smart_motion_sensor_HS3MS_by_HEIMAN by HEIMAN (#942) * Apply automatic changes * Update device: Cube_MFKZQ01LM by Aqara (#944) * Apply automatic changes * Fix Smart motion sensor (HS3MS) * Apply automatic changes * Update device: SRT321 by Secure_Meters (#947) Co-authored-by: gsemet <[email protected]> * Apply automatic changes * Update device: ZW120 by AEON_Labs (#949) Co-authored-by: gsemet <[email protected]> * Apply automatic changes * Update device: Smart_garden_irrigation_control_R7060 by Woox (#951) Co-authored-by: gsemet <[email protected]> * Apply automatic changes * Update device: FGPB_101 by Fibargroup (#953) Co-authored-by: gsemet <[email protected]> * Apply automatic changes * Update library.json (#954) correction for LYWDS02 * Apply automatic changes * Update device: 66666 by eWeLink (#956) Co-authored-by: mikosoft83 <[email protected]> * Apply automatic changes * Update device: TS1201 by _TZ3290_ot6ewjvmejq5ekhl (#958) Co-authored-by: nicknol <[email protected]> * Apply automatic changes * Update device: TS004F by _TZ3000_ixla93vd (#960) * Apply automatic changes * Update device: TS0207 by _TZ3000_85czd6fy (#962) * Apply automatic changes * Update device: TS0203 by _TZ3000_bpkijo14 (#964) * Apply automatic changes * New Crowdin translations by GitHub Action (#968) Co-authored-by: Crowdin Bot <[email protected]> * New Crowdin translations by GitHub Action (#969) Co-authored-by: Crowdin Bot <[email protected]> * Remove entity id as not needed * WIP * WIP * First working template sensor * Docs * Apply automatic changes * Template events * Change config link to docs * Docs * Docs * Battery last reported service/event * docs * Docs * WIP * WIP * Docs * Docs * Docs * Update gitignore * Add days to battery not reported event * Lint fixes * lint * Lint fixes * Lint fixes --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: andrew-codechimp <[email protected]> Co-authored-by: gsemet <[email protected]> Co-authored-by: nepozs <[email protected]> Co-authored-by: mikosoft83 <[email protected]> Co-authored-by: nicknol <[email protected]> Co-authored-by: Crowdin Bot <[email protected]>
1 parent e5def5a commit 8c1c6e3

File tree

23 files changed

+680
-42
lines changed

23 files changed

+680
-42
lines changed

custom_components/battery_notes/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,20 @@
5252
SERVICE_BATTERY_REPLACED,
5353
SERVICE_BATTERY_REPLACED_SCHEMA,
5454
SERVICE_DATA_DATE_TIME_REPLACED,
55+
SERVICE_CHECK_BATTERY_LAST_REPORTED,
56+
SERVICE_DATA_DAYS_LAST_REPORTED,
57+
SERVICE_CHECK_BATTERY_LAST_REPORTED_SCHEMA,
58+
EVENT_BATTERY_NOT_REPORTED,
5559
DATA_STORE,
5660
ATTR_REMOVE,
5761
ATTR_DEVICE_ID,
62+
ATTR_DEVICE_NAME,
63+
ATTR_BATTERY_TYPE_AND_QUANTITY,
64+
ATTR_BATTERY_TYPE,
65+
ATTR_BATTERY_QUANTITY,
66+
ATTR_BATTERY_LAST_REPORTED,
67+
ATTR_BATTERY_LAST_REPORTED_DAYS,
68+
ATTR_BATTERY_LAST_REPORTED_LEVEL,
5869
CONF_BATTERY_TYPE,
5970
CONF_BATTERY_QUANTITY,
6071
)
@@ -311,9 +322,48 @@ async def handle_battery_replaced(call):
311322
device_id,
312323
)
313324

325+
async def handle_battery_last_reported(call):
326+
"""Handle the service call."""
327+
days_last_reported = call.data.get(SERVICE_DATA_DAYS_LAST_REPORTED)
328+
329+
device: BatteryNotesDevice
330+
for device in hass.data[DOMAIN][DATA].devices.values():
331+
if device.coordinator.last_reported:
332+
time_since_lastreported = datetime.fromisoformat(str(datetime.utcnow())+"+00:00") - device.coordinator.last_reported
333+
334+
if time_since_lastreported.days > days_last_reported:
335+
336+
hass.bus.async_fire(
337+
EVENT_BATTERY_NOT_REPORTED,
338+
{
339+
ATTR_DEVICE_ID: device.coordinator.device_id,
340+
ATTR_DEVICE_NAME: device.coordinator.device_name,
341+
ATTR_BATTERY_TYPE_AND_QUANTITY: device.coordinator.battery_type_and_quantity,
342+
ATTR_BATTERY_TYPE: device.coordinator.battery_type,
343+
ATTR_BATTERY_QUANTITY: device.coordinator.battery_quantity,
344+
ATTR_BATTERY_LAST_REPORTED: device.coordinator.last_reported,
345+
ATTR_BATTERY_LAST_REPORTED_DAYS: time_since_lastreported.days,
346+
ATTR_BATTERY_LAST_REPORTED_LEVEL: device.coordinator.last_reported_level,
347+
},
348+
)
349+
350+
_LOGGER.debug(
351+
"Raised event device %s not reported since %s",
352+
device.coordinator.device_id,
353+
str(device.coordinator.last_reported),
354+
)
355+
356+
314357
hass.services.async_register(
315358
DOMAIN,
316359
SERVICE_BATTERY_REPLACED,
317360
handle_battery_replaced,
318361
schema=SERVICE_BATTERY_REPLACED_SCHEMA,
319362
)
363+
364+
hass.services.async_register(
365+
DOMAIN,
366+
SERVICE_CHECK_BATTERY_LAST_REPORTED,
367+
handle_battery_last_reported,
368+
schema=SERVICE_CHECK_BATTERY_LAST_REPORTED_SCHEMA,
369+
)

0 commit comments

Comments
 (0)