SmartThingsCommunity / smartthings-cli

Command-line Interface for the SmartThings APIs.
https://developer.smartthings.com/docs/sdks/cli/introduction
Apache License 2.0
230 stars 102 forks source link

[feat] Add a flag to the `devices` command to filter devices by which Hub they're joined to #588

Open dljsjr opened 7 months ago

dljsjr commented 7 months ago

Is your feature request related to a problem? Please describe. My specific use-case is probably pretty niche, but I think this could be a valuable filter either way.

I have several locations where I have more than one hub, and I will often have the same devices joined to multiple hubs in the same location. This makes it challenging to determine exactly which device record to isolate when using smartthings devices.

Here are two examples of where this happens:

  1. I have various LAN devices that will auto-join any time I trigger a "Scan Nearby" flavored discovery. I want to remove them from some of my hubs, but not all of them.
  2. I frequently like to test the same device on multiple versions of hub-core by using different hub products. For example, I'll test things on the newest hubcore using my Aeotec v3, and I'll use my TV or ST Station hubs to test slightly older firmware.

Describe the solution you'd like A -H flag or something similar to the capital H flag used in other commands to identify a Hub Device UUID that would only return devices that are joined to the given hub.

Describe alternatives you've considered

  1. Put all of my hubs in different locations and filter by location

This doesn't work great because it's a lot of friction/moving around in the app that slows me down. Also, with more and more products having ST Hub functionality built-in, there is certainly going to be more occurrences for multiple hubs in the same location across the fleet. So there's potential value in getting ahead of that.

  1. Doing my own filtering with jq

This gets me part way there. For example, I do have a one-liner I sometimes use that looks like this:

st devices -p production -j | jq -r --arg hub $HUB_UUID '.[] | select(.parentDeviceId == $hub)'

Where this falls down, though, is that I work with a lot of parent-child devices. This is only a top-level filter, meaning I'd have to craft a gnarly pipeline if I wanted to get all the devices joined to my hub plus child devices.