Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filterdevices #146

Merged
merged 8 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ Unfortunately where there are multiple integrations associated with a device Hom
* Can I edit a battery note?
Go into Settings -> Integrations -> Battery Notes and click Configure on the device you want to edit.

* Why am I only able to see some of my devices when adding manually?
By default Battery Notes filters the device list to only devices with a battery, if you want to add a battery note to a random device then you can disable this filtering by adding the following configuration to your `configuration.yaml` and restart Home Assistant to see all devices.
```
battery_notes:
show_all_devices: true
```

* I only want to add notes to a few devices, can I disable auto discovery?
If you want to disable this functionality you can add the following to your `configuration.yaml`, after a restart of Home Assistant you will not see discovered battery notes.
```
Expand All @@ -98,6 +105,7 @@ battery_notes:
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/codechimp)



## Contributing to the Battery Library

<!-- To add a device definition to the battery library so that it will be automatically configured there are two options:
Expand Down
3 changes: 3 additions & 0 deletions custom_components/battery_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_ENABLE_AUTODISCOVERY,
CONF_LIBRARY,
DATA_UPDATE_COORDINATOR,
CONF_SHOW_ALL_DEVICES,
)

MIN_HA_VERSION = "2023.7"
Expand All @@ -44,6 +45,7 @@
{
vol.Optional(CONF_ENABLE_AUTODISCOVERY, default=True): cv.boolean,
vol.Optional(CONF_LIBRARY, default="library.json"): cv.string,
vol.Optional(CONF_SHOW_ALL_DEVICES, default=False): cv.boolean,
},
),
),
Expand All @@ -66,6 +68,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:

domain_config: ConfigType = config.get(DOMAIN) or {
CONF_ENABLE_AUTODISCOVERY: True,
CONF_SHOW_ALL_DEVICES: False,
}

hass.data[DOMAIN] = {
Expand Down
38 changes: 35 additions & 3 deletions custom_components/battery_notes/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from homeassistant.config_entries import ConfigEntry, OptionsFlow
from homeassistant.helpers import selector
from homeassistant.helpers.typing import DiscoveryInfoType

from homeassistant.const import Platform
from homeassistant.components.sensor import SensorDeviceClass
import homeassistant.helpers.device_registry as dr

from homeassistant.const import (
Expand All @@ -30,14 +31,38 @@
CONF_MANUFACTURER,
CONF_MODEL,
DATA_UPDATE_COORDINATOR,
DOMAIN_CONFIG,
CONF_SHOW_ALL_DEVICES,
)

_LOGGER = logging.getLogger(__name__)

DEVICE_SCHEMA_ALL = vol.Schema(
{
vol.Required(CONF_DEVICE_ID): selector.DeviceSelector(
config=selector.DeviceFilterSelectorConfig()
),
vol.Optional(CONF_NAME): selector.TextSelector(
selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT),
),
}
)

DEVICE_SCHEMA = vol.Schema(
{
vol.Required(CONF_DEVICE_ID): selector.DeviceSelector(
# selector.DeviceSelectorConfig(model="otgw-nodo")
config=selector.DeviceSelectorConfig(
entity=[
selector.EntityFilterSelectorConfig(
domain=Platform.SENSOR,
device_class=SensorDeviceClass.BATTERY,
),
selector.EntityFilterSelectorConfig(
domain=Platform.BINARY_SENSOR,
device_class=SensorDeviceClass.BATTERY,
),
]
)
),
vol.Optional(CONF_NAME): selector.TextSelector(
selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT),
Expand Down Expand Up @@ -112,9 +137,16 @@ async def async_step_user(

return await self.async_step_battery()

domain_config = self.hass.data[DOMAIN][DOMAIN_CONFIG]

schema = DEVICE_SCHEMA
# If show_all_devices = is specified and true, don't filter
if domain_config.get(CONF_SHOW_ALL_DEVICES, False):
schema = DEVICE_SCHEMA_ALL

return self.async_show_form(
step_id="user",
data_schema=DEVICE_SCHEMA,
data_schema=schema,
errors=_errors,
last_step=False,
)
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 @@ -28,6 +28,7 @@
CONF_MANUFACTURER = "manufacturer"
CONF_DEVICE_NAME = "device_name"
CONF_LIBRARY_URL = "https://raw.githubusercontent.com/andrew-codechimp/HA-Battery-Notes/main/custom_components/battery_notes/data/library.json" # pylint: disable=line-too-long
CONF_SHOW_ALL_DEVICES = "show_all_devices"

DATA_CONFIGURED_ENTITIES = "configured_entities"
DATA_DISCOVERED_ENTITIES = "discovered_entities"
Expand Down
Loading