Open derjoerg opened 4 days ago
I think I may want to re-look at this implementation in the PyPi package. Having two separate enum's make implementing this more complex than it probably needs to be, and makes adding other select entities more complex.
Sure, What I see is that it would be possible to have a combined enum:
class ForcedState(enum.Enum):
"""An Enum class for the force states."""
unknown = None
deactivated = "0"
forced_open = "2"
forced_close = "3"
forced_on = "4"
forced_off = "5"
But how easy it is:
Switches
(0, 4, 5) and Covers
(0, 2, 3)?I'm currently testing this, having that number of options wouldn't work in Home Assistant.
What you want is three options, but the translation from state to command needs to happen somewhere as the values are different. I'm thinking about updating the python package set_force methods to accept the state value and translate it to the command value.
That way home assistant will only have to know about the state and the Python package does the work on translating it to a proper command.
I'm so sorry, I've just mixed things up. Forget what I wrote about Cover
. This is - luckily - pretty clear.
Yeah, now I'm on the same line.
So you mean, set_forced()
will accept deactivated
, forced_off
and forced_on
. The method is responsible to convert this to the correct commands (0, 2, 3).
Right?
So this would rather be a small change? The Command-Enum can be deleted and only set_forced()
needs to be updated.
Yep, that's exactly correct.
This is my first time playing around with this functionality so I didn't even know this was a thing in the Free@Home interface.
What would be nice, and I tested this, is to make the actuator unavailable if the forced option is enabled.
I was able to do this in my dev environment, but we'll need to add a new property to the switch actuator called available
which we can use to set the home assistant property. This is just a boolean value. Then when forced is On
or Off
the entity becomes unavailable.
https://github.com/user-attachments/assets/2da8ac44-e931-4e59-a954-6a8a28953935
COOOOOOL I asked exactly this on discord and the only possibility I got was to delete the entity. This is exactly what I had in mind
Just a final question: Does the available
option in HA has any other side-effects? I'm asking because it is not 100% correct to mark it unavailable. The entity is still there (and has a state) it is just not controllable at this moment. available
sounds more like e.g. unresponsive
or something like that "Not available through the API."
Do you understand what I mean?
The best - IMHO - would be to have the possibility to switch an entity to "read only", but this is not possible in HA
Just a final question: Does the
available
option in HA has any other side-effects? I'm asking because it is not 100% correct to mark it unavailable. The entity is still there (and has a state) it is just not controllable at this moment.available
sounds more like e.g.unresponsive
or something like that "Not available through the API." Do you understand what I mean? The best - IMHO - would be to have the possibility to switch an entity to "read only", but this is not possible in HA
It's a good question, looking at the entity class code I don't see any other side affects, but that's just the class code. There may be other parts of the Home Assistant code that may produce some adverse affects if the entity is marked as not available.
And yea, I don't think this is the intended purpose of the available
flag. I think it's to be used when an entity really is no longer reachable. It's not the end of the world to keep it available, when you try to toggle the switch it just goes back to the previous state.
I should also add, the only thing I can find in the documentation is this.
Indicate if Home Assistant is able to read the state and control the underlying device.
https://developers.home-assistant.io/docs/core/entity/#generic-properties
Based on that I think this is an ok use of the available property. Although the reading the state is not true, the state can still be read and it reflects correctly based on the forced position.
I would say the following: Implement it with the available
feature an document it. If someone in the future comes around with a valid reason, why this is bad, we can simple remove it :smiley:
Or is it possible to control this feature through a config-option?
I think I may want to re-look at this implementation in the PyPi package. Having two separate enum's make implementing this more complex than it probably needs to be, and makes adding other select entities more complex.