superbox-dev / unipi-control

Control Unipi I/O directly with MQTT commands.
Apache License 2.0
7 stars 3 forks source link

Support for switches as lights #119

Open kepi opened 8 months ago

kepi commented 8 months ago

Hi,

I discovered your project yesterday when I tried to replace some of custom scripts I'm using on my Unipi. After some digging, it seems it is much much better then I hoped for, thanks for it!

I'm currently using modbus integration in HA, but unipi-control seems much faster (more responsive), so I would like to ditch all my modbus configs and switch over to it. But I realized that all RO's are discovered as switches and there is no option in Features to handle RO as light instead of switch.

TBH, I'm not 100 % sure at this moment why I need light switches as lights :) but I remember I had troubles with this in HA before and it had been worth it to change modbus switches to lights.

I'm opening this issue more as a discussion - are you open to have this feature in unipi-control? If yes, I can try to prepare PR, but I would appreciate any tips for where to begin and how you would like to have this configured. My thought was add something like device_integration next to device_class.

mh-superbox commented 8 months ago

This is a feature that I also wanted to add. I just haven't needed it yet ;-) I'm still not quite sure what the big difference is between a switch and light, except that I have a different icon in Home Assistant. You can't use all the extra features of Light (hue, ..) anyway.

This feature should not be too difficult to implement. The name device_integration is appropriate in my opinion.

First of all, a config option is required: https://github.com/superbox-dev/unipi-control/blob/856d0121d3f4bf4d3d8c38343f961119861786ab/unipi_control/config.py#L208

Then a property method: https://github.com/superbox-dev/unipi-control/blob/856d0121d3f4bf4d3d8c38343f961119861786ab/unipi_control/features/neuron.py#L142

In the publish method of switches.py, we only add features that also have the appropriate device_integration: https://github.com/superbox-dev/unipi-control/blob/856d0121d3f4bf4d3d8c38343f961119861786ab/unipi_control/mqtt/discovery/switches.py#L97

After that a lights.py is needed, with a class like HassLightsMqttPlugin() https://github.com/superbox-dev/unipi-control/blob/856d0121d3f4bf4d3d8c38343f961119861786ab/unipi_control/unipi_control.py#L73

kepi commented 8 months ago

I'm still trying to remember and I think that main problem is that I'm not able to do turn on all lights without this.

No promises, but I'll try to take a look into this.

mh-superbox commented 8 months ago

I'm busy with another project at the moment but I can look at this issue as soon as I have time again.

If you have time, the issue #122 would be better for you, I can't do it alone because I don't have the right hardware.