Skip to content

Commit b04fc72

Browse files
razor-xmikewuuseambot
authored
fix: Filter resourceSamples on endpoints like on route (#711)
* fix: Filter resourceSamples on endpoints like on route * Remove strict check * fix: show thermostat sample for /thermostats/list (#766) * include parent metadata * ci: Generate docs * update to only select parent metadata * ci: Generate docs * fallback endpoint sample * ci: Generate docs --------- Co-authored-by: Seam Bot <[email protected]> --------- Co-authored-by: Mike Wu <[email protected]> Co-authored-by: Seam Bot <[email protected]>
1 parent 0cdbea3 commit b04fc72

File tree

4 files changed

+252
-98
lines changed

4 files changed

+252
-98
lines changed

codegen/lib/layout/api-endpoint.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
mapResourceSample,
2121
normalizePropertyFormatForDocs,
2222
type ResourceSampleContext,
23+
resourceSampleFilter,
2324
} from './api-route.js'
2425

2526
const supportedSdks: SdkName[] = [
@@ -209,6 +210,7 @@ export function setEndpointLayoutContext(
209210
endpoint,
210211
resources,
211212
actionAttempts,
213+
pathMetadata,
212214
).map(mapResourceSample)
213215

214216
const [primaryCodeSample, ...additionalCodeSamples] = endpoint.codeSamples
@@ -265,6 +267,7 @@ const getResourceSamples = (
265267
endpoint: Endpoint,
266268
resources: Resource[],
267269
actionAttempts: ActionAttempt[],
270+
pathMetadata: PathMetadata,
268271
): ResourceSample[] => {
269272
const { response } = endpoint
270273

@@ -288,7 +291,25 @@ const getResourceSamples = (
288291

289292
if (resource == null) return []
290293

291-
const sample = resource.resourceSamples[0]
294+
const endpointMetadata = pathMetadata[resource.routePath]
295+
const endpointSample = resource.resourceSamples.filter(
296+
resourceSampleFilter({
297+
include: endpointMetadata?.include_groups,
298+
exclude: endpointMetadata?.exclude_groups,
299+
}),
300+
)[0]
301+
302+
const parentMetadata =
303+
endpoint.parentPath != null ? pathMetadata[endpoint.parentPath] : undefined
304+
const parentSample = resource.resourceSamples.filter(
305+
resourceSampleFilter({
306+
include: parentMetadata?.include_groups,
307+
exclude: parentMetadata?.exclude_groups,
308+
}),
309+
)[0]
310+
311+
const sample = parentSample ?? endpointSample
312+
292313
if (sample == null) return []
293314

294315
return [

codegen/lib/layout/api-route.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ export const setApiRouteLayoutContext = (
194194
({ isUndocumented }) => !isUndocumented,
195195
),
196196
legacyProperty.propertyGroups,
197-
{
198-
include: metadata.include_groups,
199-
exclude: metadata.exclude_groups,
200-
},
197+
groupOptions,
201198
)
202199
: null
203200

@@ -212,24 +209,31 @@ export const setApiRouteLayoutContext = (
212209
events: eventsByRoutePath.get(resource.routePath) ?? [],
213210
endpoints: file.endpoints,
214211
resourceSamples: resource.resourceSamples
215-
.filter(({ title }) => {
216-
if (groupOptions.include != null) {
217-
return groupOptions.include.some((x) =>
218-
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
219-
)
220-
}
221-
if (groupOptions.exclude != null) {
222-
return !groupOptions.exclude.some((x) =>
223-
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
224-
)
225-
}
226-
return true
227-
})
212+
.filter(resourceSampleFilter(groupOptions))
228213
.map(mapResourceSample),
229214
})
230215
}
231216
}
232217

218+
export const resourceSampleFilter =
219+
(groupOptions: {
220+
include: string[] | undefined
221+
exclude: string[] | undefined
222+
}) =>
223+
({ title }: ResourceSample): boolean => {
224+
if (groupOptions.include != null) {
225+
return groupOptions.include.some((x) =>
226+
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
227+
)
228+
}
229+
if (groupOptions.exclude != null) {
230+
return !groupOptions.exclude.some((x) =>
231+
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
232+
)
233+
}
234+
return true
235+
}
236+
233237
const groupVariants = (
234238
property: Property | null,
235239
{

docs/api/noise_sensors/list.md

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -712,55 +712,74 @@ Array of [devices](./../devices)
712712

713713
```json
714714
{
715-
"can_program_online_access_codes": true,
716-
"can_remotely_lock": true,
717-
"can_remotely_unlock": true,
718-
"capabilities_supported": ["access_code", "lock"],
719-
"connected_account_id": "8e3a4f1b-2c7d-4a9e-8b5f-3d2c1a0b9e8f",
720-
"created_at": "2025-03-27T02:08:16.418Z",
715+
"capabilities_supported": ["noise_detection"],
716+
"connected_account_id": "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d",
717+
"created_at": "2025-05-16T16:54:17.946049Z",
721718
"custom_metadata": { "id": "internalId1" },
722-
"device_id": "a69569e1-133b-4a9d-b883-018641bfe543",
723-
"device_type": "schlage_lock",
724-
"display_name": "FRONT DOOR",
719+
"device_id": "f1e2d3c4-b5a6-4d7c-8e9f-0a1b2c3d4e5f",
720+
"device_type": "minut_sensor",
721+
"display_name": "Living Room",
725722
"errors": [],
726723
"is_managed": true,
727-
"location": { "location_name": "Front Door", "timezone": "America/New_York" },
728-
"nickname": "Front Door",
724+
"location": {
725+
"location_name": "Jane's Test Home",
726+
"timezone": "America/Los_Angeles"
727+
},
728+
"nickname": "Living Room",
729729
"properties": {
730-
"appearance": { "name": "FRONT DOOR" },
731-
"battery": { "level": 0.48, "status": "good" },
732-
"battery_level": 0.48,
733-
"code_constraints": [{ "constraint_type": "name_length", "max_length": 9 }],
734-
"has_native_entry_events": true,
735-
"image_alt_text": "Schlage Sense Smart Deadbolt with Camelot Trim, Front",
736-
"image_url": "https://connect.getseam.com/_next/image?url=https://connect.getseam.com/assets/images/devices/schlage_sense-smart-deadbolt-with-camelot-trim_front.png&q=75&w=128",
737-
"locked": false,
738-
"manufacturer": "schlage",
739-
"model": {
740-
"accessory_keypad_supported": false,
741-
"can_connect_accessory_keypad": false,
742-
"display_name": "Encode",
743-
"has_built_in_keypad": true,
744-
"manufacturer_display_name": "Schlage",
745-
"offline_access_codes_supported": false,
746-
"online_access_codes_supported": true
730+
"appearance": { "name": "Living Room" },
731+
"battery": { "level": 1, "status": "full" },
732+
"battery_level": 1,
733+
"currently_triggering_noise_threshold_ids": [],
734+
"image_alt_text": "Minut Sensor",
735+
"image_url": "https://connect.getseam.com/_next/image?url=https://connect.getseam.com/assets/images/devices/minut_gen-3_front.png&q=75&w=128",
736+
"manufacturer": "minut",
737+
"minut_metadata": {
738+
"device_id": "770cd3153deca3dee0fe0614",
739+
"device_location": { "latitude": 0, "longitude": 0 },
740+
"device_name": "Living Room",
741+
"home_address": {
742+
"city": "San Francisco",
743+
"country": "US",
744+
"notes": "string",
745+
"post_code": "44210",
746+
"region": "San Francisco County",
747+
"street_name1": "2258 24th Street",
748+
"street_name2": ""
749+
},
750+
"home_id": "2978b6d5dba395ec08300e46",
751+
"home_location": { "latitude": 0, "longitude": 0 },
752+
"home_name": "Jane's Test Home",
753+
"latest_sensor_values": {
754+
"accelerometer_z": {
755+
"time": "2025-06-16T16:54:17.946049Z",
756+
"value": -1.00390625
757+
},
758+
"humidity": {
759+
"time": "2025-06-16T16:54:17.946049Z",
760+
"value": 31.110000610351562
761+
},
762+
"pressure": { "time": "2025-06-16T16:54:17.946049Z", "value": 101923 },
763+
"sound": {
764+
"time": "2025-06-16T16:54:17.946049Z",
765+
"value": 47.7117919921875
766+
},
767+
"temperature": {
768+
"time": "2025-06-16T16:54:17.946049Z",
769+
"value": 21.270000457763672
770+
}
771+
}
747772
},
748-
"name": "FRONT DOOR",
749-
"offline_access_codes_enabled": false,
750-
"online": true,
751-
"online_access_codes_enabled": true,
752-
"schlage_metadata": {
753-
"device_id": "a69569e1-133b-4a9d-b883-018641bfe543",
754-
"device_name": "FRONT DOOR",
755-
"model": "Encode"
773+
"model": {
774+
"display_name": "Noise Sensor",
775+
"manufacturer_display_name": "Minut"
756776
},
757-
"serial_number": "34000000000531e0",
758-
"supported_code_lengths": [4, 5, 6, 7, 8],
759-
"supports_backup_access_code_pool": true,
760-
"supports_offline_access_codes": false
777+
"name": "Living Room",
778+
"noise_level_decibels": 47.7117919921875,
779+
"online": true
761780
},
762781
"warnings": [],
763-
"workspace_id": "5d7f2e1a-9c8b-4f3e-8d2c-1a0b9e8f7c6d"
782+
"workspace_id": "1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d"
764783
}
765784
```
766785
{% endtab %}

0 commit comments

Comments
 (0)