Skip to content

Commit 916a41c

Browse files
Addressing review feedback and cleaning up VideoSensorParams processing logic
1 parent 3192639 commit 916a41c

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ end
113113
function CameraAttributeHandlers.rate_distortion_trade_off_points_handler(driver, device, ib, response)
114114
if not ib.data.elements then return end
115115
local resolutions = {}
116-
local max_encoded_pixel_rate = device:get_field(camera_fields.MAX_ENCODED_PIXEL_RATE)
117-
local max_fps = device:get_field(camera_fields.MAX_FRAMES_PER_SECOND)
118-
local emit_capability = max_encoded_pixel_rate ~= nil and max_fps ~= nil and device:get_field(camera_fields.MIN_RESOLUTION) and device:get_field(camera_fields.MAX_RESOLUTION)
119116
for _, v in ipairs(ib.data.elements) do
120117
local rate_distortion_trade_off_points = v.elements
121118
local width = rate_distortion_trade_off_points.resolution.elements.width.value
@@ -126,60 +123,47 @@ function CameraAttributeHandlers.rate_distortion_trade_off_points_handler(driver
126123
})
127124
end
128125
device:set_field(camera_fields.SUPPORTED_RESOLUTIONS, resolutions)
129-
if emit_capability then
126+
local max_encoded_pixel_rate = device:get_field(camera_fields.MAX_ENCODED_PIXEL_RATE)
127+
local max_fps = device:get_field(camera_fields.MAX_FRAMES_PER_SECOND)
128+
if max_encoded_pixel_rate and max_fps and device:get_field(camera_fields.MAX_RESOLUTION) and device:get_field(camera_fields.MIN_RESOLUTION) then
130129
local supported_resolutions = camera_utils.build_supported_resolutions(device, max_encoded_pixel_rate, max_fps)
131130
device:emit_event_for_endpoint(ib, capabilities.videoStreamSettings.supportedResolutions(supported_resolutions))
132131
end
133132
end
134133

135134
function CameraAttributeHandlers.max_encoded_pixel_rate_handler(driver, device, ib, response)
136-
local resolutions = device:get_field(camera_fields.SUPPORTED_RESOLUTIONS)
137-
local max_fps = device:get_field(camera_fields.MAX_FRAMES_PER_SECOND)
138-
local emit_capability = resolutions ~= nil and max_fps ~= nil and device:get_field(camera_fields.MIN_RESOLUTION) and device:get_field(camera_fields.MAX_RESOLUTION)
139135
device:set_field(camera_fields.MAX_ENCODED_PIXEL_RATE, ib.data.value)
140-
if emit_capability then
136+
local max_fps = device:get_field(camera_fields.MAX_FRAMES_PER_SECOND)
137+
if max_fps and device:get_field(camera_fields.SUPPORTED_RESOLUTIONS) and device:get_field(camera_fields.MAX_RESOLUTION) and device:get_field(camera_fields.MIN_RESOLUTION) then
141138
local supported_resolutions = camera_utils.build_supported_resolutions(device, ib.data.value, max_fps)
142139
device:emit_event_for_endpoint(ib, capabilities.videoStreamSettings.supportedResolutions(supported_resolutions))
143140
end
144141
end
145142

146143
function CameraAttributeHandlers.video_sensor_parameters_handler(driver, device, ib, response)
147144
if not ib.data.elements then return end
148-
local resolutions = device:get_field(camera_fields.SUPPORTED_RESOLUTIONS)
145+
local sensor_width = ib.data.elements.sensor_width.value
146+
local sensor_height = ib.data.elements.sensor_height.value
147+
local max_fps = ib.data.elements.max_fps.value
148+
device:set_field(camera_fields.MAX_RESOLUTION, {
149+
width = sensor_width,
150+
height = sensor_height
151+
})
152+
device:set_field(camera_fields.MAX_FRAMES_PER_SECOND, max_fps)
153+
device:emit_event_for_endpoint(ib, capabilities.cameraViewportSettings.videoSensorParameters({
154+
width = sensor_width,
155+
height = sensor_height,
156+
maxFPS = max_fps
157+
}))
149158
local max_encoded_pixel_rate = device:get_field(camera_fields.MAX_ENCODED_PIXEL_RATE)
150-
local emit_capability = resolutions ~= nil and max_encoded_pixel_rate ~= nil and device:get_field(camera_fields.MIN_RESOLUTION)
151-
local sensor_width, sensor_height, max_fps
152-
for _, v in pairs(ib.data.elements) do
153-
if v.field_id == 0 then
154-
sensor_width = v.value
155-
elseif v.field_id == 1 then
156-
sensor_height = v.value
157-
elseif v.field_id == 2 then
158-
max_fps = v.value
159-
end
160-
end
161-
162-
if max_fps then
163-
if sensor_width and sensor_height then
164-
device:emit_event_for_endpoint(ib, capabilities.cameraViewportSettings.videoSensorParameters({
165-
width = sensor_width,
166-
height = sensor_height,
167-
maxFPS = max_fps
168-
}))
169-
device:set_field(camera_fields.MAX_RESOLUTION, {
170-
width = sensor_width,
171-
height = sensor_height
172-
})
173-
end
174-
device:set_field(camera_fields.MAX_FRAMES_PER_SECOND, max_fps)
175-
if emit_capability then
176-
local supported_resolutions = camera_utils.build_supported_resolutions(device, max_encoded_pixel_rate, max_fps)
177-
device:emit_event_for_endpoint(ib, capabilities.videoStreamSettings.supportedResolutions(supported_resolutions))
178-
end
159+
if max_encoded_pixel_rate and max_fps and device:get_field(camera_fields.SUPPORTED_RESOLUTIONS) and device:get_field(camera_fields.MIN_RESOLUTION) then
160+
local supported_resolutions = camera_utils.build_supported_resolutions(device, max_encoded_pixel_rate, max_fps)
161+
device:emit_event_for_endpoint(ib, capabilities.videoStreamSettings.supportedResolutions(supported_resolutions))
179162
end
180163
end
181164

182165
function CameraAttributeHandlers.min_viewport_handler(driver, device, ib, response)
166+
if not ib.data.elements then return end
183167
device:emit_event_for_endpoint(ib, capabilities.cameraViewportSettings.minViewportResolution({
184168
width = ib.data.elements.width.value,
185169
height = ib.data.elements.height.value
@@ -188,11 +172,9 @@ function CameraAttributeHandlers.min_viewport_handler(driver, device, ib, respon
188172
width = ib.data.elements.width.value,
189173
height = ib.data.elements.height.value
190174
})
191-
local resolutions = device:get_field(camera_fields.SUPPORTED_RESOLUTIONS)
192175
local max_encoded_pixel_rate = device:get_field(camera_fields.MAX_ENCODED_PIXEL_RATE)
193176
local max_fps = device:get_field(camera_fields.MAX_FRAMES_PER_SECOND)
194-
local emit_capability = resolutions ~= nil and max_encoded_pixel_rate ~= nil and max_fps ~= nil and device:get_field(camera_fields.MAX_RESOLUTION)
195-
if emit_capability then
177+
if max_encoded_pixel_rate and max_fps and device:get_field(camera_fields.SUPPORTED_RESOLUTIONS) and device:get_field(camera_fields.MAX_RESOLUTION) then
196178
local supported_resolutions = camera_utils.build_supported_resolutions(device, max_encoded_pixel_rate, max_fps)
197179
device:emit_event_for_endpoint(ib, capabilities.videoStreamSettings.supportedResolutions(supported_resolutions))
198180
end

0 commit comments

Comments
 (0)