It's just a 'placeholder' method that isn't used. I used it for EXACTLY the same purpose, getting rid of states from a previous driver. I copy paste the needed lines into updated() then click save preferences then go back and remove the lines from updated()
Shouldn't I be able to do more than one at a time??? On the code above, if I just comment out all but one, that one gets removed when the updated() function runs. I can then comment out that one, uncomment out the next one, and it gets removed - and so on.
I also tried this, but it doesn't ever remove anything either:
state.each {key, val ->
log.debug "state key: $key, value: $val"
state.remove("$key")
}
It outputs the $key and $val variables correctly in the log.debug... I would swear that worked in ST...
Once upon a time I went looking for a usable driver for the Aeon Multisensor6. I tried everything I found, incurring many attributes. I've still got this left in the source:
Sorry to revive this thread, but state.remove("something") won't work if the driver capability has that state built in. For example, if you have a device that supports both AC power and battery and you try to do state.remove("battery") it won't work. The only way to remove battery as a state is to remove the device and recreate/re-add it. The device won't have that state until the first event with that attribute and then it seems to be there forever more.
I wish there was a way to clear a state though in this situation because I have a device that shows battery on the dashboard because ONE time I plugged it in. I also have some Ring devices that support the battery capability and some show and others don't show battery because in the driver I have diligently never sent a battery event when I shouldn't (until a bug that I'm fixing now and thus this revival).
Is there a way to remove the state even when it is the capability of one of the driver capabilities? In addition to what was tried above I tried getting the states with getCurrentStates() and removing it. Hubitat's com.hubitat.hub.domain.State class doesn't seem to be implementing the equals method or the list is immutable. I also tried device.currentStates but the same thing applies I think.
I wish there was a setCurrentValue or setCurrentState that would take a null or a clearCurrentValue or clearCurrentState. That way I could better support the device drivers that support multiple devices (some with battery and some without) or devices that are installed permanently with cords that don't have batteries in them.
Are you confusing the state’s with the attributes?
I use state .clear() in a number of my drivers just fine.
State is just a variable in the driver and the attributes are ‘states a device is currently in’ which are available to apps to query. Not sure if I confused things more with that explanation though.
No, I don't think I'm confused. I think there is some overlap. As far as I can tell the attributes are retrieved via getCurrentStates() with a class that is called "com.hubitat.hub.domain.State" even. Iterate over device.getCurrentStates() and check device.currentStates if you don't know what I mean.
A more correct way to say a state that is covered by a device capability is just to say attribute though. So, I will refer to them as built-in attributes to hopefully lessen any confusion going forward.
Ya. I think its just some bad naming. state.clear() though works on the state object which I think is just a map or list (or a special version of one of the two) which is separate from the attributes.
That's how I understand it though. If I'm wrong I'm sure one of the devs will chime in and I'll learn something new.
Ah, yeah, I just checked again because it's been a long time since I iterated "state" and you are right. No overlap here.
Okay, so my question is slightly different but since I already @mentioned Mike to come here I'll leave my question here.
To sum up, I would like a way to clear an attribute (or a state from getCurrentStates). The attributes won't show up until the first event and are then there forever. I would like to remove one without removing the device and re-adding so that device drivers that support multiple device types can code around showing attributes that don't really apply on the dashboard for examples.