Skip to content

Commit 8afc6da

Browse files
committed
Increment version to 3.1.1 in manifest.json and update device payload handling in network.py to send only essential fields, preventing InvalidPayload errors on older UniFi Network versions.
1 parent b6343a0 commit 8afc6da

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

custom_components/unifi_network_rules/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"aiounifi>=82.0.0",
1616
"orjson>=3.8.0"
1717
],
18-
"version": "3.1.0"
18+
"version": "3.1.1"
1919
}

custom_components/unifi_network_rules/udm/network.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ async def set_device_led(self, device: Device, enable: bool = True) -> bool:
144144
like brightness and color control, a Light entity would be more appropriate.
145145
146146
Implementation:
147-
Uses the pattern of getting full device payload, modifying only the LED field,
148-
and PUTting the entire payload back to the device-specific endpoint.
147+
Sends only essential device fields to avoid InvalidPayload errors on older
148+
UniFi Network versions that reject read-only fields in update requests.
149149
"""
150150
try:
151151
device_id = device.id
@@ -155,11 +155,19 @@ async def set_device_led(self, device: Device, enable: bool = True) -> bool:
155155
device_raw = getattr(device, 'raw', {}) if hasattr(device, 'raw') else {}
156156
device_mac = device_raw.get('mac', device_raw.get('serial', 'unknown'))
157157

158-
# Get the current device configuration (full payload)
159-
device_payload = device.raw.copy() if hasattr(device, 'raw') and device.raw else {}
158+
# Create minimal payload with only essential fields to avoid InvalidPayload errors
159+
# Many fields in the full device payload are read-only and cause API errors
160+
device_payload = {
161+
'_id': device_id,
162+
'led_override': status
163+
}
160164

161-
# Modify only the LED override field
162-
device_payload['led_override'] = status
165+
# Include optional LED fields if they exist in the original data
166+
# to maintain any existing LED configuration
167+
if 'led_override_color' in device_raw:
168+
device_payload['led_override_color'] = device_raw['led_override_color']
169+
if 'led_override_color_brightness' in device_raw:
170+
device_payload['led_override_color_brightness'] = device_raw['led_override_color_brightness']
163171

164172
# Use the legacy API endpoint for device updates (not v2)
165173
# Path format: /rest/device/{device_id}

0 commit comments

Comments
 (0)