ckarrie / ha-netgear-plus

HomeAssistant Netgear Switch Integration
Apache License 2.0
21 stars 10 forks source link

Ability to turn of LEDs on switch through home assistant #39

Open AcidWizard opened 5 days ago

AcidWizard commented 5 days ago

Checklist

Is your feature request related to a problem? Please describe.

I own a Netgear GS308EPP and I have the LEDs disabled at night as my SO is very sensitive to light when sleeping. Right now i have to do this manually through the switch GUI but it seems possible through this integration. I do have some programming experience but no experience with home assistant so I am not sure how to add this functionality to your integration.

Describe the solution you'd like

Have a switch in Home Assistant that enables or disables the LED's so this can be automated.

Describe alternatives you've considered

Making a switch/automation/script in homeassistant to manually call the port_led.cgi endpoint, but i have not gotten this to work.

Additional context

I noticed in the network tab on my browser that the page port_led.cgi was called with a hash(I assume the hashed password) and an option named portled. This option is set to 2 for turning the LED's off and set to 0 to turn the LED's on.

AcidWizard commented 5 days ago

I think the switch_leds function should probably look like this:

def switch_leds(self, state: str) -> bool:
    """Switch leds on or off."""
    if state not in SWITCH_STATES:
        return False
        for template in self.switch_model.LED_CONFIG_TEMPLATES:
            url = template["url"].format(ip=self.host)
            data = {
                "hash": self._client_hash,
                "portled": 0 if state == "on" else 2,
            }
            resp = self._request("post", url, data=data)
            if resp.status_code == requests.codes.ok:
                return True
    return False

Where LED_CONFIG_TEMPLATES is a member of the GS308EPP and contains:

LED_CONFIG_TEMPLATES: ClassVar = [
        {"method": "get", "url": "http://{ip}/port_led.cgi"}
]

But I am not sure how to implement the switch in homeassistant itself

foxey commented 4 days ago

Nice! The PoE power switch has some side effects. Does the LED switching form have additional fields as well?

AcidWizard commented 4 days ago

No, its just an ON/OFF switch which you press apply on that disables the LEDs on the RJ45 ports, the power and POE max LED stay on. The request just has the hash and portled values.