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

Show only battery-holding devices in device-dropdown when creating a new Battery-Note #93

Closed
3 tasks done
marcelhoogantink opened this issue Dec 18, 2023 · 10 comments · Fixed by #146
Closed
3 tasks done
Labels
enhancement New feature or request

Comments

@marcelhoogantink
Copy link

marcelhoogantink commented Dec 18, 2023

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

The list of devices the dropdown for devices when creating a new battery-note contains all available devices. This is/can be a very long list. Most many devices do not have a battery and are unnecessary in the list.

Describe the solution you'd like

Fill the devices list with a filter that only includes devices which has a battery

Describe alternatives you've considered

NA

Additional context

NA

@andrew-codechimp
Copy link
Owner

I did look at this but couldn't seem to find a way to filter devices to those with a certain entity

vol.Required(CONF_DEVICE_ID): selector.DeviceSelector(

@andrew-codechimp andrew-codechimp added the help wanted Extra attention is needed label Dec 18, 2023
@uvjim
Copy link
Contributor

uvjim commented Dec 20, 2023

Have a gander here... The example shows how to look for devices that provide a battery sensor.

@andrew-codechimp
Copy link
Owner

Thanks, I did see that but translating that YAML example to Python is where I'm getting stuck at the moment.
My HA integration/Python skills are fairly new so it's learning by example on a lot of these things.

@uvjim
Copy link
Contributor

uvjim commented Dec 20, 2023

I'll take a look.

@uvjim
Copy link
Contributor

uvjim commented Dec 20, 2023

I'm not in a position to test but I think this should work (or at least get you close)

You will need to add the following to the block of imports...

from homeassistant.const import Platform
from homeassistant.components.sensor import SensorDeviceClass

This would be your device selector

        vol.Required(CONF_DEVICE_ID): selector.DeviceSelector(
            config=selector.DeviceSelectorConfig(
                entity=[
                    selector.EntityFilterSelectorConfig(
                        domain=Platform.SENSOR,
                        device_class=SensorDeviceClass.BATTERY,
                    )
                ]
            )
        ),

UPDATE: Realised I'd used the wrong selector definitions in places.

@andrew-codechimp
Copy link
Owner

Thanks, just tested that and it seems to work. A lot more testing and a config option to override this before I release.

For dev I'm always adding a PP3 battery to the Sun to save adding physical devices to my dev instance :)

@andrew-codechimp andrew-codechimp added enhancement New feature or request and removed help wanted Extra attention is needed labels Dec 20, 2023
@uvjim
Copy link
Contributor

uvjim commented Dec 20, 2023

There's a possibility that you may need to add an entity filter to check for the binary_sensor domain as well. I know the blink integration uses that domain for battery sensors as it can only report on good/bad state.

The entity parameter is a list so you should be able to add that in easily enough. I can't recall if the selector is then matching against "one of" or "all". It would make sense to be "one of" though.

@andrew-codechimp
Copy link
Owner

@uvjim Pleased to say the selector is "one of", even though I've not got binary_sensor batteries I'm not losing my sensor batteries by adding them. My testing will continue but looks like this is going to work.

@uvjim
Copy link
Contributor

uvjim commented Dec 21, 2023

@andrew-codechimp that's good then. Glad I could be of some help. Keep up the learning and good work.

@andrew-codechimp andrew-codechimp linked a pull request Dec 26, 2023 that will close this issue
@andrew-codechimp
Copy link
Owner

A Beta version has now been released with the both Battery Last Replaced sensor, button & service plus the device picker when manually adding now only shows devices with batteries (can be changed, see FAQ).

If you wish to try this version please go into HACS, select Battery Notes and in the top right menu choose Redownload, switch on Show Beta Versions and select the latest version (starts with 1.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants