diff --git a/homeassistant/components/unifi/switch.py b/homeassistant/components/unifi/switch.py index 87c9b9f4f4f..846c6d12234 100644 --- a/homeassistant/components/unifi/switch.py +++ b/homeassistant/components/unifi/switch.py @@ -131,7 +131,9 @@ async def async_poe_port_control_fn( """Control poe state.""" mac, _, index = obj_id.partition("_") device = api.devices[mac] - state = "auto" if target else "off" + port = api.ports[obj_id] + on_state = "auto" if port.raw["poe_caps"] != 8 else "passthrough" + state = on_state if target else "off" await api.request(DeviceSetPoePortModeRequest.create(device, int(index), state)) diff --git a/tests/components/unifi/test_switch.py b/tests/components/unifi/test_switch.py index 6ea52c95a9f..6b7ee2cd0a7 100644 --- a/tests/components/unifi/test_switch.py +++ b/tests/components/unifi/test_switch.py @@ -138,6 +138,7 @@ DEVICE_1 = { "media": "GE", "name": "Port 1", "port_idx": 1, + "poe_caps": 7, "poe_class": "Class 4", "poe_enable": True, "poe_mode": "auto", @@ -151,6 +152,7 @@ DEVICE_1 = { "media": "GE", "name": "Port 2", "port_idx": 2, + "poe_caps": 7, "poe_class": "Class 4", "poe_enable": True, "poe_mode": "auto", @@ -164,6 +166,7 @@ DEVICE_1 = { "media": "GE", "name": "Port 3", "port_idx": 3, + "poe_caps": 7, "poe_class": "Unknown", "poe_enable": False, "poe_mode": "off", @@ -177,6 +180,7 @@ DEVICE_1 = { "media": "GE", "name": "Port 4", "port_idx": 4, + "poe_caps": 7, "poe_class": "Unknown", "poe_enable": False, "poe_mode": "auto",