Skip to content

Commit

Permalink
Manual devices (#158)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andrew-codechimp authored Dec 27, 2023
1 parent 5aa3fdf commit 54a9d4c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Fork the repository, add your device details to the JSON document `custom_compon
* 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)
* If a device has a bespoke rechargeable battery you can use `"battery_type": "Rechargeable"`
* For devices like smoke alarms where the battery is not replaceable you can use `"battery_type": "Irreplaceable"`
* 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.

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

Expand Down
13 changes: 7 additions & 6 deletions custom_components/battery_notes/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ async def async_step_user(
)

if device_battery_details:
_LOGGER.debug(
"Found device %s %s", device_entry.manufacturer, device_entry.model
)
self.data[
CONF_BATTERY_TYPE
] = device_battery_details.battery_type_and_quantity
if not device_battery_details.is_manual:
_LOGGER.debug(
"Found device %s %s", device_entry.manufacturer, device_entry.model
)
self.data[
CONF_BATTERY_TYPE
] = device_battery_details.battery_type_and_quantity

return await self.async_step_battery()

Expand Down
7 changes: 6 additions & 1 deletion custom_components/battery_notes/data/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@
"model": "KR1",
"battery_type": "CR2"
},
{
"manufacturer": "Google",
"model": "Topaz-2.7",
"battery_type": "MANUAL"
},
{
"manufacturer": "Govee",
"model": "H5101/H5102/H5177",
Expand Down Expand Up @@ -1422,4 +1427,4 @@
"battery_quantity": 2
}
]
}
}
3 changes: 3 additions & 0 deletions custom_components/battery_notes/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ async def start_discovery(self) -> None:
if not device_battery_details:
continue

if device_battery_details.is_manual:
continue

self._init_entity_discovery(device_entry, device_battery_details)
else:
_LOGGER.error("Library not loaded")
Expand Down
7 changes: 7 additions & 0 deletions custom_components/battery_notes/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class DeviceBatteryDetails(NamedTuple):
battery_type: str
battery_quantity: int

@property
def is_manual(self):
"""Return whether the device should be discovered or battery type suggested."""
if self.battery_type.casefold() == "manual".casefold():
return True
return False

@property
def battery_type_and_quantity(self):
"""Return battery type with quantity prefix."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/battery_notes/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"integration_type": "device",
"iot_class": "calculated",
"issue_tracker": "https://github.com/andrew-codechimp/ha-battery-notes/issues",
"version": "1.3.2"
"version": "1.3.3"
}

0 comments on commit 54a9d4c

Please sign in to comment.