diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..89a1af7cd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index 5cb0cb62d..6744f3fc5 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index f7dba75c7..2b0d99aa8 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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 + diff --git a/custom_components/battery_notes/__init__.py b/custom_components/battery_notes/__init__.py index 541f03f3a..3020877c1 100644 --- a/custom_components/battery_notes/__init__.py +++ b/custom_components/battery_notes/__init__.py @@ -41,6 +41,8 @@ SERVICE_BATTERY_REPLACED_SCHEMA, DATA_COORDINATOR, ATTR_REMOVE, + ATTR_DEVICE_ID, + ATTR_DATE_TIME_REPLACED ) MIN_HA_VERSION = "2023.7" @@ -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.""" @@ -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) @@ -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 @@ -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( diff --git a/custom_components/battery_notes/const.py b/custom_components/battery_notes/const.py index 225b1a0c4..940b3c373 100644 --- a/custom_components/battery_notes/const.py +++ b/custom_components/battery_notes/const.py @@ -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 } ) diff --git a/custom_components/battery_notes/data/library.json b/custom_components/battery_notes/data/library.json index c944ecb78..2442c1ac0 100644 --- a/custom_components/battery_notes/data/library.json +++ b/custom_components/battery_notes/data/library.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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)", diff --git a/custom_components/battery_notes/services.yaml b/custom_components/battery_notes/services.yaml index d3f142da3..063edfdc7 100644 --- a/custom_components/battery_notes/services.yaml +++ b/custom_components/battery_notes/services.yaml @@ -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 @@ -11,3 +11,9 @@ set_battery_replaced: device: filter: - integration: battery_notes + datetime_replaced: + name: Date + description: Date replaced. + required: false + selector: + datetime: diff --git a/custom_components/battery_notes/translations/da.json b/custom_components/battery_notes/translations/da.json index 07e7dd313..cb9791515 100644 --- a/custom_components/battery_notes/translations/da.json +++ b/custom_components/battery_notes/translations/da.json @@ -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" } } -} +} \ No newline at end of file diff --git a/custom_components/battery_notes/translations/de.json b/custom_components/battery_notes/translations/de.json index 8293c5534..c39defbef 100644 --- a/custom_components/battery_notes/translations/de.json +++ b/custom_components/battery_notes/translations/de.json @@ -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" } } -} +} \ No newline at end of file diff --git a/custom_components/battery_notes/translations/en.json b/custom_components/battery_notes/translations/en.json index 095c6f561..eea3d0e20 100644 --- a/custom_components/battery_notes/translations/en.json +++ b/custom_components/battery_notes/translations/en.json @@ -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" diff --git a/custom_components/battery_notes/translations/hu.json b/custom_components/battery_notes/translations/hu.json index 792bc4ca3..d30b54029 100644 --- a/custom_components/battery_notes/translations/hu.json +++ b/custom_components/battery_notes/translations/hu.json @@ -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" } } -} +} \ No newline at end of file diff --git a/custom_components/battery_notes/translations/sk.json b/custom_components/battery_notes/translations/sk.json index 944527c0c..7674aeceb 100644 --- a/custom_components/battery_notes/translations/sk.json +++ b/custom_components/battery_notes/translations/sk.json @@ -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" } } -} +} \ No newline at end of file diff --git a/library.md b/library.md index f5fc4ff2f..4b99f3bca 100644 --- a/library.md +++ b/library.md @@ -1,4 +1,4 @@ -## 421 Devices in library +## 432 Devices in library This file is auto generated, do not modify @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 |