jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Configure all switching devices as switch (not light) in HA #169

Closed EnricoBilla closed 6 months ago

EnricoBilla commented 8 months ago

Hi all, as discussed in #168 and #141 I've implemented the configuration of all switching devices as switch in HA (instead of light) as previously done.

This is a HUGE breaking change for this integration, but it would allow to customize the behaviour of that switch directly from HA with the switch_as_x helper.

Also, I'm not sure how dimmable devices are handled. I hope they are not exposed twice (both as switch, for the on/off action, and as light, for the set_brightness action). If anyone can try with a dimmable device please let me know.

Tho85 commented 8 months ago

I think this is the right approach :+1:

Regarding the breaking change: Maybe we should add a config option to the config flow somehow: "Expose switching actuators as lights". Default should be false for new configurations, so new users can use the switch_as_x functionality. And maybe it is possible to set this config option to true for existing / upgrading installations, so this change wouldn't be a breaking change for existing users.

EnricoBilla commented 8 months ago

I don't know if there's a way to default two different values based on if the integration is already configured or a new installation. If it could be possible that would be perfect. Otherwise we can default to switch-as-x and write about the breaking change in the readme and release a new version for HACS

Ruko2010 commented 8 months ago

I tested the code and can say: It works like it should. Just have to change my switches to lights after the configuration via https://www.home-assistant.io/integrations/switch_as_x/

EnricoBilla commented 7 months ago

As reported by @Ruko2010 in #141 this PR is working fine with dimmable lights too

jheling commented 7 months ago

Looks good. Can you make it optional like @Tho85 proposed?

EnricoBilla commented 7 months ago

I don't know how to implement different default values based on if the component is already installed or not. Anyway, it should be pretty easy to add a parameter to the component for switch_as_x. I was thinking to default it to false, so that it will be backwards compatible. What do you think?

EnricoBilla commented 7 months ago

Hi all, I pushed the code to allow the configuration of switching devices as switch in HA instead of light. The configuration attribute is switch_as_x, and it defaults to True for any new (and upgrading) installation. Already configured instances are made backward compatible by defaulting it to False. I tested it and it seems to work correctly, please try it and give me your feedback

jheling commented 7 months ago

Hi, I have installed the objects on my test pi. Here the freeAtHome is setup through the configuration.yaml. If I add the switch_as_x: True nothing happens. The log shows this message: No switch_as_x option found in saved config, consider adding it If I remove the freeAtHome from the configuration.yaml the new option works ok.

EnricoBilla commented 7 months ago

@jheling that's the same flow I experienced. I think it's like that because the 'switch_as_x' parameter isn't set in the current configuration loaded by HA. The only way I found to let HA know the configuration has changed is to remove it from the UI or removing from the yaml and readding it. I don't know if that's the expected behaviour

jheling commented 7 months ago

I saw that some integrations have a configure at the integration level (bluetooth, zigbee). This seems to be the Options Flow (https://developers.home-assistant.io/docs/config_entries_options_flow_handler/) . I haven't had time to dive deeper in this, but this looks like the place for this option and also the use_room_names.

EnricoBilla commented 7 months ago

That may be the solution but I don't think that's so easy to implement because we need to fully reload the integration. Is there an easy way to do it? Also, I don't think it's a big deal to remove the integration and readding it with the new configuration. That can be done through the WebUI without even restarting HA