@@ -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