Skip to content

Commit

Permalink
Low templates (#1038)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
8 people authored Feb 15, 2024
1 parent e5def5a commit 8c1c6e3
Show file tree
Hide file tree
Showing 23 changed files with 680 additions and 42 deletions.
50 changes: 50 additions & 0 deletions custom_components/battery_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@
SERVICE_BATTERY_REPLACED,
SERVICE_BATTERY_REPLACED_SCHEMA,
SERVICE_DATA_DATE_TIME_REPLACED,
SERVICE_CHECK_BATTERY_LAST_REPORTED,
SERVICE_DATA_DAYS_LAST_REPORTED,
SERVICE_CHECK_BATTERY_LAST_REPORTED_SCHEMA,
EVENT_BATTERY_NOT_REPORTED,
DATA_STORE,
ATTR_REMOVE,
ATTR_DEVICE_ID,
ATTR_DEVICE_NAME,
ATTR_BATTERY_TYPE_AND_QUANTITY,
ATTR_BATTERY_TYPE,
ATTR_BATTERY_QUANTITY,
ATTR_BATTERY_LAST_REPORTED,
ATTR_BATTERY_LAST_REPORTED_DAYS,
ATTR_BATTERY_LAST_REPORTED_LEVEL,
CONF_BATTERY_TYPE,
CONF_BATTERY_QUANTITY,
)
Expand Down Expand Up @@ -311,9 +322,48 @@ async def handle_battery_replaced(call):
device_id,
)

async def handle_battery_last_reported(call):
"""Handle the service call."""
days_last_reported = call.data.get(SERVICE_DATA_DAYS_LAST_REPORTED)

device: BatteryNotesDevice
for device in hass.data[DOMAIN][DATA].devices.values():
if device.coordinator.last_reported:
time_since_lastreported = datetime.fromisoformat(str(datetime.utcnow())+"+00:00") - device.coordinator.last_reported

if time_since_lastreported.days > days_last_reported:

hass.bus.async_fire(
EVENT_BATTERY_NOT_REPORTED,
{
ATTR_DEVICE_ID: device.coordinator.device_id,
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,
ATTR_BATTERY_QUANTITY: device.coordinator.battery_quantity,
ATTR_BATTERY_LAST_REPORTED: device.coordinator.last_reported,
ATTR_BATTERY_LAST_REPORTED_DAYS: time_since_lastreported.days,
ATTR_BATTERY_LAST_REPORTED_LEVEL: device.coordinator.last_reported_level,
},
)

_LOGGER.debug(
"Raised event device %s not reported since %s",
device.coordinator.device_id,
str(device.coordinator.last_reported),
)


hass.services.async_register(
DOMAIN,
SERVICE_BATTERY_REPLACED,
handle_battery_replaced,
schema=SERVICE_BATTERY_REPLACED_SCHEMA,
)

hass.services.async_register(
DOMAIN,
SERVICE_CHECK_BATTERY_LAST_REPORTED,
handle_battery_last_reported,
schema=SERVICE_CHECK_BATTERY_LAST_REPORTED_SCHEMA,
)
Loading

0 comments on commit 8c1c6e3

Please sign in to comment.