Skip to content

Commit 54a9d4c

Browse files
Manual devices (#158)
* Add MANUAL battery types to avoid discovery of unusual devices * Temporarily remove the Google Topaz from manual * Add back Google Topaz * Improve discovery * Lint fix
1 parent 5aa3fdf commit 54a9d4c

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Fork the repository, add your device details to the JSON document `custom_compon
129129
* The `battery_type` data should follow the most common naming for general batteries (ex. AAA, D) and the IEC naming for battery cells according to [Wikipedia](https://en.wikipedia.org/wiki/List_of_battery_sizes) (ex. CR2032, 18650)
130130
* If a device has a bespoke rechargeable battery you can use `"battery_type": "Rechargeable"`
131131
* For devices like smoke alarms where the battery is not replaceable you can use `"battery_type": "Irreplaceable"`
132+
* If a device shouldn't be discovered because there are multiple revisions with the same model number but different battery types or it's optionally mains powered, it can be added to the library with a `"battery_type": "MANUAL"` to note it is a device that shouldn't have a battery definition added to the library to save removal/re-add because people don't realise there are variants.
132133

133134
For the example image below, your JSON entry will look like this:
134135

custom_components/battery_notes/config_flow.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ async def async_step_user(
129129
)
130130

131131
if device_battery_details:
132-
_LOGGER.debug(
133-
"Found device %s %s", device_entry.manufacturer, device_entry.model
134-
)
135-
self.data[
136-
CONF_BATTERY_TYPE
137-
] = device_battery_details.battery_type_and_quantity
132+
if not device_battery_details.is_manual:
133+
_LOGGER.debug(
134+
"Found device %s %s", device_entry.manufacturer, device_entry.model
135+
)
136+
self.data[
137+
CONF_BATTERY_TYPE
138+
] = device_battery_details.battery_type_and_quantity
138139

139140
return await self.async_step_battery()
140141

custom_components/battery_notes/data/library.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@
313313
"model": "KR1",
314314
"battery_type": "CR2"
315315
},
316+
{
317+
"manufacturer": "Google",
318+
"model": "Topaz-2.7",
319+
"battery_type": "MANUAL"
320+
},
316321
{
317322
"manufacturer": "Govee",
318323
"model": "H5101/H5102/H5177",
@@ -1422,4 +1427,4 @@
14221427
"battery_quantity": 2
14231428
}
14241429
]
1425-
}
1430+
}

custom_components/battery_notes/discovery.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ async def start_discovery(self) -> None:
103103
if not device_battery_details:
104104
continue
105105

106+
if device_battery_details.is_manual:
107+
continue
108+
106109
self._init_entity_discovery(device_entry, device_battery_details)
107110
else:
108111
_LOGGER.error("Library not loaded")

custom_components/battery_notes/library.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class DeviceBatteryDetails(NamedTuple):
105105
battery_type: str
106106
battery_quantity: int
107107

108+
@property
109+
def is_manual(self):
110+
"""Return whether the device should be discovered or battery type suggested."""
111+
if self.battery_type.casefold() == "manual".casefold():
112+
return True
113+
return False
114+
108115
@property
109116
def battery_type_and_quantity(self):
110117
"""Return battery type with quantity prefix."""

custom_components/battery_notes/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"integration_type": "device",
1010
"iot_class": "calculated",
1111
"issue_tracker": "https://github.com/andrew-codechimp/ha-battery-notes/issues",
12-
"version": "1.3.2"
12+
"version": "1.3.3"
1313
}

0 commit comments

Comments
 (0)