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 6, 2024
2 parents 26fa88e + 5846d19 commit ad8ee2b
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ __pycache__

# misc
.coverage
.vscode
coverage.xml


Expand Down
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Home Assistant",
"type": "python",
"request": "launch",
"module": "homeassistant",
"justMyCode": false,
"args": [
"--debug",
"-c",
"config"
]
},
{
// Example of attaching to my production server
"name": "Python: Attach Remote",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
],
}
]
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,21 @@
"command": "scripts/develop",
"problemMatcher": []
}
],
"configurations": [
{
// Example of attaching to local debug server
"name": "Python: Attach Local",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
}
]
}
3 changes: 3 additions & 0 deletions custom_components/battery_notes/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
ATTR_DEVICE_ID = "device_id"
ATTR_DATE_TIME_REPLACED = "datetime_replaced"
ATTR_REMOVE = "remove"
ATTR_BATTERY_QUANTITY = "battery_quantity"
ATTR_BATTERY_TYPE = "battery_type"


SERVICE_BATTERY_REPLACED_SCHEMA = vol.Schema(
{
Expand Down
69 changes: 63 additions & 6 deletions custom_components/battery_notes/data/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "_TZ3000_mh9px7cq",
"model": "TS0044",
"battery_type": "A23"
},
{
"manufacturer": "_TZ3000_wkai4ga5",
"model": "TS0044",
Expand All @@ -67,6 +72,11 @@
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "_TZ3210_j4pdtz9v",
"model": "TS0001",
"battery_type": "CR2"
},
{
"manufacturer": "_TZ3210_up3pngle",
"model": "TS0205",
Expand Down Expand Up @@ -156,11 +166,21 @@
"battery_type": "AAA",
"battery_quantity": 4
},
{
"manufacturer": "American Power Conversion",
"model": "Back-UPS ES 600M1",
"battery_type": "Rechargable"
},
{
"manufacturer": "American Power Conversion",
"model": "Back-UPS XS 1500M",
"battery_type": "Rechargable"
},
{
"manufacturer": "APC",
"model": "Back-UPS XS 1500M",
"battery_type": "Rechargeable"
},
{
"manufacturer": "Aqara",
"model": "Aqara Door and Window Sensor P2",
Expand Down Expand Up @@ -553,12 +573,22 @@
"model": "TH01",
"battery_type": "CR2450"
},
{
"manufacturer": "eWeLink",
"model": "WB01",
"battery_type": "CR2450"
},
{
"manufacturer": "Fantem",
"model": "4 in 1 multi sensor (ZB003-X)",
"battery_type": "CR123A",
"battery_quantity": 2
},
{
"manufacturer": "Fibargroup",
"model": "FGCD001",
"battery_type": "CR123A"
},
{
"manufacturer": "Fibargroup",
"model": "FGDW002",
Expand Down Expand Up @@ -1152,6 +1182,11 @@
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "Nyce",
"model": "Door/window sensor (NCZ-3011-HA)",
"battery_type": "CR2032"
},
{
"manufacturer": "OpenEpaperLink",
"model": "ST\u2010GR16000 1.54\"",
Expand Down Expand Up @@ -1286,12 +1321,24 @@
"model": "roborock.vacuum.a15",
"battery_type": "Rechargeable"
},
{
"manufacturer": "rtl_433",
"model": "Acurite-986",
"battery_type": "AA",
"battery_quantity": 2
},
{
"manufacturer": "rtl_433",
"model": "Acurite-Tower",
"battery_type": "AA",
"battery_quantity": 2
},
{
"manufacturer": "rtl_433",
"model": "Vauno-EN8822C",
"battery_type": "AAA",
"battery_quantity": 2
},
{
"manufacturer": "Ruuvi",
"model": "Ruuvitag",
Expand Down Expand Up @@ -1448,11 +1495,6 @@
"model": "Compact magnetic contact sensor (AV2010/21A)",
"battery_type": "CR2"
},
{
"manufacturer": "Smartthing",
"model": "STS-WTR-250",
"battery_type": "CR2"
},
{
"manufacturer": "SmartThings",
"model": "Button (IM6001-BTP01)",
Expand All @@ -1473,10 +1515,15 @@
"model": "Multipurpose sensor (2018 model) (IM6001-MPP01)",
"battery_type": "CR2450"
},
{
"manufacturer": "Smartthings",
"model": "Water leak sensor (2016 model) (STS-WTR-250)",
"battery_type": "CR2"
},
{
"manufacturer": "SOMFY",
"model": "Sonesse 28 WF Li-Ion Roller",
"battery_type": "Rechargeable"
"battery_type": "MANUAL"
},
{
"manufacturer": "Sonoff",
Expand Down Expand Up @@ -2067,6 +2114,11 @@
"model": "ble XMWSDJ04MMC",
"battery_type": "CR2450"
},
{
"manufacturer": "Xiaomi",
"model": "BTHome sensor",
"battery_type": "CR2032"
},
{
"manufacturer": "Xiaomi",
"model": "GZCGQ01LM",
Expand Down Expand Up @@ -2149,6 +2201,11 @@
"model": "Temperature & humidity sensor (LYWSD03MMC)",
"battery_type": "CR2032"
},
{
"manufacturer": "Xiaomi",
"model": "Temperature/Humidity sensor",
"battery_type": "CR2032"
},
{
"manufacturer": "Xiaomi",
"model": "WSDCGQ01LM",
Expand Down
29 changes: 29 additions & 0 deletions custom_components/battery_notes/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from dataclasses import dataclass
import voluptuous as vol
import re

from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
Expand Down Expand Up @@ -47,6 +48,8 @@
LAST_REPLACED,
DOMAIN_CONFIG,
CONF_ENABLE_REPLACED,
ATTR_BATTERY_QUANTITY,
ATTR_BATTERY_TYPE,
)

from .coordinator import BatteryNotesCoordinator
Expand Down Expand Up @@ -247,6 +250,32 @@ def native_value(self) -> str:

return self._battery_type

@property
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the battery type."""

matches: re.Match = re.search(
r"^(\d+)(?=x)(?:x\s)(\w+$)|([\s\S]+)", self._battery_type
)
if matches:
_qty = matches.group(1) if matches.group(1) is not None else "1"
_type = (
matches.group(2) if matches.group(2) is not None else matches.group(3)
)
else:
_qty = 1
_type = self._battery_type

attrs = {
ATTR_BATTERY_QUANTITY: _qty,
ATTR_BATTERY_TYPE: _type,
}

super_attrs = super().extra_state_attributes
if super_attrs:
attrs.update(super_attrs)
return attrs


class BatteryNotesLastReplacedSensor(SensorEntity, CoordinatorEntity):
"""Represents a battery note sensor."""
Expand Down
17 changes: 14 additions & 3 deletions library.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 410 Devices in library
## 421 Devices in library

This file is auto generated, do not modify

Expand All @@ -13,9 +13,11 @@ This file is auto generated, do not modify
|_TZ3000_fllyghyj |TS0201 |2x AAA |
|_TZ3000_k4ej3ww2 |TS0207 |CR2032 |
|_TZ3000_lf56vpxj |TS0202 |2x AAA |
|_TZ3000_mh9px7cq |TS0044 |A23 |
|_TZ3000_wkai4ga5 |TS0044 |CR2430 |
|_TZ3000_xr3htd96 |TS0201 |2x AAA |
|_TZ3000_yxqnffam |TS0203 |2x AAA |
|_TZ3210_j4pdtz9v |TS0001 |CR2 |
|_TZ3210_up3pngle |TS0205 |2x AAA |
|_TZE200_b6wax7g0 |TS0601 |2x AA |
|_TZE200_c88teujp |TS0601 |2x AA |
Expand All @@ -32,7 +34,9 @@ This file is auto generated, do not modify
|Aldi |MEGOS switch and dimming light remote control (141L100RC) |CR2450 |
|Allegion |BE469 |4x AA |
|Allegion |BE469ZP |4x AAA |
|American Power Conversion |Back-UPS ES 600M1 |Rechargable |
|American Power Conversion |Back-UPS XS 1500M |Rechargable |
|APC |Back-UPS XS 1500M |Rechargeable |
|Aqara |Aqara Door and Window Sensor P2 |CR123A |
|August |TEST200228 |4x AA |
|August Home Inc. |AK-R1 |2x AAA |
Expand Down Expand Up @@ -102,7 +106,9 @@ This file is auto generated, do not modify
|eWeLink |MS01 |CR2450 |
|eWeLink |SNZB-02P |CR2477 |
|eWeLink |TH01 |CR2450 |
|eWeLink |WB01 |CR2450 |
|Fantem |4 in 1 multi sensor (ZB003-X) |2x CR123A |
|Fibargroup |FGCD001 |CR123A |
|Fibargroup |FGDW002 |ER14250 |
|Fibargroup |FGFS101 |CR123A |
|Fibargroup |FGFS101 |CR123A |
Expand Down Expand Up @@ -213,6 +219,7 @@ This file is auto generated, do not modify
|Nuki |Nuki Opener |4x AAA |
|Nuki |Nuki Smart Lock |4x AA |
|NYCE |3043 |2x AAA |
|Nyce |Door/window sensor (NCZ-3011-HA) |CR2032 |
|OpenEpaperLink |ST‐GR16000 1.54 |CR2450 |
|OpenEpaperLink |ST‐GR29000 2.9 |2x CR2450 |
|Oral-B |Genius X |Rechargeable |
Expand All @@ -238,7 +245,9 @@ This file is auto generated, do not modify
|Ring |Motion Sensor |2x AA |
|Ring |Security Keypad |Rechargeable |
|Roborock |roborock.vacuum.a15 |Rechargeable |
|rtl_433 |Acurite-986 |2x AA |
|rtl_433 |Acurite-Tower |2x AA |
|rtl_433 |Vauno-EN8822C |2x AAA |
|Ruuvi |Ruuvitag |CR2477T |
|Samjin |motion |CR2 |
|Samjin |multi |CR2450 |
Expand Down Expand Up @@ -268,12 +277,12 @@ This file is auto generated, do not modify
|Signify Netherlands B.V. |SML003 |2x AAA |
|Siterwell |Radiator valve with thermostat (GS361A-H04) |2x AA |
|SMaBiT (Bitron Video) |Compact magnetic contact sensor (AV2010/21A) |CR2 |
|Smartthing |STS-WTR-250 |CR2 |
|SmartThings |Button (IM6001-BTP01) |CR2450 |
|SmartThings |moisturev4 |CR2 |
|SmartThings |Motion sensor (2018 model) (IM6001-MTP01) |CR2 |
|SmartThings |Multipurpose sensor (2018 model) (IM6001-MPP01) |CR2450 |
|SOMFY |Sonesse 28 WF Li-Ion Roller |Rechargeable |
|Smartthings |Water leak sensor (2016 model) (STS-WTR-250) |CR2 |
|SOMFY |Sonesse 28 WF Li-Ion Roller |MANUAL |
|Sonoff |Contact sensor (SNZB-04) |CR2032 |
|SONOFF |Motion sensor (SNZB-03) |CR2450 |
|Sonoff |SNZB-02 |CR2450 |
Expand Down Expand Up @@ -383,6 +392,7 @@ This file is auto generated, do not modify
|Xiaomi |ble RTCGQ02LM |CR2450 |
|Xiaomi |ble XMPIR02SXS |CR2450 |
|Xiaomi |ble XMWSDJ04MMC |CR2450 |
|Xiaomi |BTHome sensor |CR2032 |
|Xiaomi |GZCGQ01LM |CR2450 |
|Xiaomi |HHCCJCY01 |CR2032 |
|Xiaomi |LYWSD03MMC |CR2032 |
Expand All @@ -399,6 +409,7 @@ This file is auto generated, do not modify
|Xiaomi |RTCGQ01LM |CR2450 |
|Xiaomi |SRTS-A01 |2x AA |
|Xiaomi |Temperature & humidity sensor (LYWSD03MMC) |CR2032 |
|Xiaomi |Temperature/Humidity sensor |CR2032 |
|Xiaomi |WSDCGQ01LM |CR2032 |
|Xiaomi |XMTZC02HM/XMTZC05HM/NUN4049CN |4x AAA |
|Xiaomi |XMWSDJ04MMC |CR2450 |
Expand Down

0 comments on commit ad8ee2b

Please sign in to comment.