kingsleyadam / local-abbfreeathome-hass

This is the Home Assistant custom_components (HACS) repository for Busch Jaeger/ABB Free@Home (Local API)
MIT License
4 stars 2 forks source link

Implement forced option as select entity #78

Open derjoerg opened 4 days ago

kingsleyadam commented 11 hours 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.

derjoerg commented 10 hours 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:

  1. to check for the different valid states in the lib for Switches (0, 4, 5) and Covers (0, 2, 3)?
  2. to check for the valid states in the different HA-devices?
kingsleyadam commented 10 hours ago

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.

Screenshot 2024-11-14 at 14 30 45

derjoerg commented 10 hours ago

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.

kingsleyadam commented 10 hours ago

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

derjoerg commented 10 hours ago

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

derjoerg commented 10 hours ago

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

kingsleyadam commented 10 hours ago

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.

kingsleyadam commented 10 hours ago

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.

derjoerg commented 9 hours ago

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?