Skip to content

Commit

Permalink
Merge branch 'main' into watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Jan 8, 2024
2 parents 392cb2a + eb54d97 commit addadc2
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.formatting.provider": "none"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Andrew Jackson
Copyright (c) 2023-2024 Andrew Jackson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![Downloads][download-latest-shield]](Downloads)
[![License][license-shield]](LICENSE)
[![hacs][hacsbadge]][hacs]
[![Community Forum][forum-shield]][forum]
Expand Down Expand Up @@ -177,3 +178,5 @@ Thanks to everyone who has submitted devices to the library.
[license-shield]: https://img.shields.io/github/license/andrew-codechimp/HA-Battery-Notes.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/andrew-codechimp/HA-Battery-Notes.svg?style=for-the-badge
[releases]: https://github.com/andrew-codechimp/HA-Battery-Notes/releases
[download-latest-shield]: https://img.shields.io/github/downloads/andrew-codechimp/ha-battery-notes/latest/total?style=for-the-badge

17 changes: 11 additions & 6 deletions custom_components/battery_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
SERVICE_BATTERY_REPLACED_SCHEMA,
DATA_COORDINATOR,
ATTR_REMOVE,
ATTR_DEVICE_ID,
ATTR_DATE_TIME_REPLACED
)

MIN_HA_VERSION = "2023.7"
Expand All @@ -63,8 +65,6 @@
extra=vol.ALLOW_EXTRA,
)

ATTR_SERVICE_DEVICE_ID = "device_id"

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Integration setup."""

Expand Down Expand Up @@ -154,7 +154,13 @@ def register_services(hass):

async def handle_battery_replaced(call):
"""Handle the service call."""
device_id = call.data.get(ATTR_SERVICE_DEVICE_ID, "")
device_id = call.data.get(ATTR_DEVICE_ID, "")
datetime_replaced_entry = call.data.get(ATTR_DATE_TIME_REPLACED)

if datetime_replaced_entry:
datetime_replaced = dt_util.as_utc(datetime_replaced_entry).replace(tzinfo=None)
else:
datetime_replaced = datetime.utcnow()

device_registry = dr.async_get(hass)

Expand All @@ -166,10 +172,9 @@ async def handle_battery_replaced(call):
if (
entry := hass.config_entries.async_get_entry(entry_id)
) and entry.domain == DOMAIN:
date_replaced = datetime.utcnow()

coordinator: BatteryNotesCoordinator = hass.data[DOMAIN][DATA_COORDINATOR]
device_entry = {"battery_last_replaced": date_replaced}
device_entry = {"battery_last_replaced": datetime_replaced}

coordinator.async_update_device_config(
device_id=device_id, data=device_entry
Expand All @@ -178,7 +183,7 @@ async def handle_battery_replaced(call):
await coordinator.async_request_refresh()

_LOGGER.debug(
"Device %s battery replaced on %s", device_id, str(date_replaced)
"Device %s battery replaced on %s", device_id, str(datetime_replaced)
)

hass.services.async_register(
Expand Down
1 change: 1 addition & 0 deletions custom_components/battery_notes/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
SERVICE_BATTERY_REPLACED_SCHEMA = vol.Schema(
{
vol.Required(ATTR_DEVICE_ID): cv.string,
vol.Optional(ATTR_DATE_TIME_REPLACED): cv.datetime
}
)

Expand Down
62 changes: 62 additions & 0 deletions custom_components/battery_notes/data/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@
"battery_type": "AA",
"battery_quantity": 4
},
{
"manufacturer": "August Home Inc.",
"model": "AUG-SL03-C02-G03",
"battery_type": "AA",
"battery_quantity": 4
},
{
"manufacturer": "August Home Inc.",
"model": "AUG-SL04-M01-G04",
"battery_type": "AA",
"battery_quantity": 4
},
{
"manufacturer": "August Home Inc.",
"model": "AUG-SL05-M01-S01",
Expand Down Expand Up @@ -354,6 +366,11 @@
"model": "TILTZWAVE1",
"battery_type": "CR123A"
},
{
"manufacturer": "Elexa Consumer Products Inc.",
"model": "DMWS1",
"battery_type": "CR2"
},
{
"manufacturer": "eQ-3",
"model": "HM-CC-RT-DN",
Expand Down Expand Up @@ -625,12 +642,24 @@
"battery_type": "AA",
"battery_quantity": 2
},
{
"manufacturer": "Frient",
"model": "EMIZB-141",
"battery_type": "AA",
"battery_quantity": 2
},
{
"manufacturer": "frient",
"model": "MOSZB-140",
"battery_type": "AA",
"battery_quantity": 2
},
{
"manufacturer": "Frient",
"model": "ZHEMI101",
"battery_type": "AA",
"battery_quantity": 3
},
{
"manufacturer": "frient A/S",
"model": "HESZB-120",
Expand All @@ -657,6 +686,12 @@
"model": "Topaz-2.7",
"battery_type": "MANUAL"
},
{
"manufacturer": "Govee",
"model": "H5054",
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "Govee",
"model": "H5072/H5075",
Expand Down Expand Up @@ -885,6 +920,11 @@
"model": "3326-L",
"battery_type": "CR2"
},
{
"manufacturer": "Iris",
"model": "Contact and temperature sensor (IL06_1)",
"battery_type": "CR2"
},
{
"manufacturer": "iRobot",
"model": "i715640",
Expand Down Expand Up @@ -1288,6 +1328,18 @@
"model": "RWL022",
"battery_type": "CR2032"
},
{
"manufacturer": "Philips",
"model": "SML001",
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "Philips Hue",
"model": "SML001",
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "Poly-control",
"model": "Danalock V3-BTZE",
Expand Down Expand Up @@ -1402,6 +1454,16 @@
"battery_type": "AA",
"battery_quantity": 4
},
{
"manufacturer": "Shenzhen Neo Electronics Co., Ltd.",
"model": "NAS-DS01Z",
"battery_type": "CR2"
},
{
"manufacturer": "Shenzhen Neo Electronics Co., Ltd.",
"model": "NAS-WS01Z",
"battery_type": "CR2"
},
{
"manufacturer": "Signify Netherlands B.V.",
"model": "Hue dimmer switch (RWL020)",
Expand Down
8 changes: 7 additions & 1 deletion custom_components/battery_notes/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set_battery_replaced:
name: Set battery replaced
description: "Set the battery last replaced to now."
description: "Set the battery last replaced."
fields:
device_id:
name: Device
Expand All @@ -11,3 +11,9 @@ set_battery_replaced:
device:
filter:
- integration: battery_notes
datetime_replaced:
name: Date
description: Date replaced.
required: false
selector:
datetime:
8 changes: 6 additions & 2 deletions custom_components/battery_notes/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
},
"services": {
"set_battery_replaced": {
"description": "Indstil det sidst udskiftede batteri til nu.",
"description": "Indstil det sidst udskiftede batteri.",
"fields": {
"device_id": {
"description": "Enhed, der har fået skiftet batteri.",
"name": "Enhed"
},
"datetime_replaced": {
"description": "Dato udskiftet.",
"name": "Dato"
}
},
"name": "Sæt batteri udskiftet"
}
}
}
}
8 changes: 6 additions & 2 deletions custom_components/battery_notes/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
},
"services": {
"set_battery_replaced": {
"description": "ktualisiert den Zeitpunkt des letzten Batteriewechsels auf den jetzigen Zeitpunkt.",
"description": "Stellen Sie die zuletzt ausgetauschte Batterie ein.",
"fields": {
"device_id": {
"description": "Gerät, bei dem die Batterie ersetzt wurde.",
"name": "Gerät"
},
"datetime_replaced": {
"description": "Datum ersetzt.",
"name": "Datum"
}
},
"name": "ktualisiert den Zeitpunkt des letzten Batteriewechsels"
}
}
}
}
6 changes: 5 additions & 1 deletion custom_components/battery_notes/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@
},
"services": {
"set_battery_replaced": {
"description": "Set the battery last replaced to now.",
"description": "Set the battery last replaced.",
"fields": {
"device_id": {
"description": "Device that has had it's battery replaced.",
"name": "Device"
},
"datetime_replaced": {
"description": "Date replaced.",
"name": "Date"
}
},
"name": "Set battery replaced"
Expand Down
8 changes: 6 additions & 2 deletions custom_components/battery_notes/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
},
"services": {
"set_battery_replaced": {
"description": "Utolsó elemcsere időpont beállítása mostra.",
"description": "Állítsa be az utoljára cserélt akkumulátort.",
"fields": {
"device_id": {
"description": "Az eszköz eleme cserélve lett.",
"name": "Eszköz"
},
"datetime_replaced": {
"description": "Csere dátuma.",
"name": "Dátum"
}
},
"name": "Elemcsere beállítása"
}
}
}
}
8 changes: 6 additions & 2 deletions custom_components/battery_notes/translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
},
"services": {
"set_battery_replaced": {
"description": "Nastavte poslednú vymenenú batériu na teraz.",
"description": "Nastavte batériu ako poslednú vymenenú.",
"fields": {
"device_id": {
"description": "Zariadenie, v ktorom bola vymenená batéria.",
"name": "Zariadenie"
},
"datetime_replaced": {
"description": "Dátum nahradený.",
"name": "Dátum"
}
},
"name": "Sada vymenená batéria"
}
}
}
}
13 changes: 12 additions & 1 deletion library.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 421 Devices in library
## 432 Devices in library

This file is auto generated, do not modify

Expand Down Expand Up @@ -42,6 +42,8 @@ This file is auto generated, do not modify
|August Home Inc. |AK-R1 |2x AAA |
|August Home Inc. |ASL6_05/101200/SI |4x AA |
|August Home Inc. |ASL6_05/101300/SI |4x AA |
|August Home Inc. |AUG-SL03-C02-G03 |4x AA |
|August Home Inc. |AUG-SL04-M01-G04 |4x AA |
|August Home Inc. |AUG-SL05-M01-S01 |2x CR123A |
|Bosch |ISW-ZPR1-WP13 |4x AA |
|Bosch |Radiator thermostat II (BTH-RA) |2x AA |
Expand All @@ -68,6 +70,7 @@ This file is auto generated, do not modify
|Ecolink |FF-ZWAVE5-ECO |CR123 |
|Ecolink |TILT-ZWAVE2.5-ECO |CR123A |
|Ecolink |TILTZWAVE1 |CR123A |
|Elexa Consumer Products Inc. |DMWS1 |CR2 |
|eQ-3 |HM-CC-RT-DN |2x AA |
|eQ-3 |HM-Dis-EP-WM55 |2x AAA |
|eQ-3 |HM-ES-TX-WM |4x AA |
Expand Down Expand Up @@ -116,12 +119,15 @@ This file is auto generated, do not modify
|Fibargroup |FGMS001 |CR123A |
|Fibargroup |FGSD002 |CR123A |
|First Alert (BRK Brands Inc) |ZCOMBO |2x AA |
|Frient |EMIZB-141 |2x AA |
|frient |MOSZB-140 |2x AA |
|Frient |ZHEMI101 |3x AA |
|frient A/S |HESZB-120 |CR123A |
|frient A/S |SMSZB-120 |CR123 |
|GiEX |Water irrigation valve (QT06_2) |4x AA |
|Google |KR1 |CR2 |
|Google |Topaz-2.7 |MANUAL |
|Govee |H5054 |2x AAA |
|Govee |H5072/H5075 |2x AAA |
|Govee |H5101/H5102/H5177 |AAA |
|HAB Home Intelligence LLC |iblinds V3 |Rechargeable |
Expand Down Expand Up @@ -165,6 +171,7 @@ This file is auto generated, do not modify
|INKBIRD |IBS-TH2/P01B |2x AAA |
|iNode |iNode Energy Meter |CR2032 |
|Iris |3326-L |CR2 |
|Iris |Contact and temperature sensor (IL06_1) |CR2 |
|iRobot |i715640 |Rechargeable |
|Konke |3AFE28010402000D |CR2450 |
|Kwikset |910 |4x AA |
Expand Down Expand Up @@ -239,6 +246,8 @@ This file is auto generated, do not modify
|Philips |Hue wall switch module (929003017102) |CR2450 |
|Philips |RWL021 |CR2450 |
|Philips |RWL022 |CR2032 |
|Philips |SML001 |2x AAA |
|Philips Hue |SML001 |2x AAA |
|Poly-control |Danalock V3-BTZE |4x CR123A |
|Ring |Contact Sensor |2x CR2032 |
|Ring |Doorbell 2 |Rechargeable |
Expand All @@ -260,6 +269,8 @@ This file is auto generated, do not modify
|Shelly |Shelly Plus Smoke |CR123A |
|Shenzhen Heiman Technology Co., Ltd. |Smoke Detector (HS1SA-Z) |CR123A |
|Shenzhen Kaadas Intelligent Technology Co., Ltd.|DB1 |4x AA |
|Shenzhen Neo Electronics Co., Ltd. |NAS-DS01Z |CR2 |
|Shenzhen Neo Electronics Co., Ltd. |NAS-WS01Z |CR2 |
|Signify Netherlands B.V. |Hue dimmer switch (RWL020) |CR2450 |
|Signify Netherlands B.V. |Hue dimmer switch (RWL021) |CR2450 |
|Signify Netherlands B.V. |Hue dimmer switch (RWL022) |CR2032 |
Expand Down

0 comments on commit addadc2

Please sign in to comment.