Skip to content

Commit 97dc18b

Browse files
seambotrazor-x
andauthored
feat: Improve device error and warning types (#1564)
Co-authored-by: Evan Sosenko <[email protected]>
1 parent 362b130 commit 97dc18b

File tree

4 files changed

+1555
-1206
lines changed

4 files changed

+1555
-1206
lines changed

src/lib/seam/connect/models/access-codes/managed-access-code.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { z } from 'zod'
22

3-
import { connected_account_error } from '../connected-accounts/index.js'
4-
import { device_error } from '../devices/index.js'
3+
import { device_and_connected_account_error_options } from '../devices/index.js'
54

65
const common_access_code_error = z.object({
76
message: z.string(),
@@ -371,8 +370,7 @@ export const access_code = z.object({
371370
.array(
372371
z.discriminatedUnion('error_code', [
373372
...access_code_error.options,
374-
...device_error.options,
375-
...connected_account_error.options,
373+
...device_and_connected_account_error_options,
376374
]),
377375
)
378376
.describe(

src/lib/seam/connect/models/devices/device.ts

+103-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type BatteryStatus = z.infer<typeof battery_status>
2424
const common_device_error = z.object({
2525
message: z.string(),
2626
is_device_error: z.literal(true),
27+
created_at: z.string().datetime(),
2728
})
2829

2930
const error_code_description =
@@ -55,6 +56,16 @@ const device_disconnected = common_device_error
5556
})
5657
.describe('Device is disconnected')
5758

59+
const account_disconnected = common_device_error
60+
.extend({
61+
error_code: z
62+
.literal('account_disconnected')
63+
.describe(error_code_description),
64+
is_connected_account_error: z.literal(true),
65+
is_device_error: z.literal(false),
66+
})
67+
.describe('Account is disconnected')
68+
5869
const empty_backup_access_code_pool = common_device_error
5970
.extend({
6071
error_code: z
@@ -79,11 +90,13 @@ const august_lock_missing_bridge = common_device_error
7990
})
8091
.describe('Lock is not connected to the Seam Bridge.')
8192

82-
const salto_site_user_limit_reached = common_device_error
93+
const salto_ks_subscription_limit_exceeded = common_device_error
8394
.extend({
8495
error_code: z
85-
.literal('salto_site_user_limit_reached')
96+
.literal('salto_ks_subscription_limit_exceeded')
8697
.describe(error_code_description),
98+
is_connected_account_error: z.literal(true),
99+
is_device_error: z.literal(false),
87100
})
88101
.describe('Salto site user limit reached.')
89102

@@ -121,14 +134,15 @@ const subscription_required = common_device_error
121134

122135
export const device_error = z
123136
.discriminatedUnion('error_code', [
137+
account_disconnected,
138+
salto_ks_subscription_limit_exceeded,
124139
device_offline,
125140
device_removed,
126141
hub_disconnected,
127142
device_disconnected,
128143
empty_backup_access_code_pool,
129144
august_lock_not_authorized,
130145
august_lock_missing_bridge,
131-
salto_site_user_limit_reached,
132146
ttlock_lock_not_paired_to_gateway,
133147
missing_device_credentials,
134148
auxiliary_heat_running,
@@ -138,11 +152,36 @@ export const device_error = z
138152

139153
export type DeviceError = z.infer<typeof device_error>
140154

155+
const device_error_map = z.object({
156+
device_offline: device_offline.optional().nullable(),
157+
device_removed: device_removed.optional().nullable(),
158+
hub_disconnected: hub_disconnected.optional().nullable(),
159+
device_disconnected: device_disconnected.optional().nullable(),
160+
account_disconnected: account_disconnected.optional().nullable(),
161+
empty_backup_access_code_pool: empty_backup_access_code_pool
162+
.optional()
163+
.nullable(),
164+
august_lock_not_authorized: august_lock_not_authorized.optional().nullable(),
165+
august_lock_missing_bridge: august_lock_missing_bridge.optional().nullable(),
166+
salto_ks_subscription_limit_exceeded: salto_ks_subscription_limit_exceeded
167+
.optional()
168+
.nullable(),
169+
ttlock_lock_not_paired_to_gateway: ttlock_lock_not_paired_to_gateway
170+
.optional()
171+
.nullable(),
172+
missing_device_credentials: missing_device_credentials.optional().nullable(),
173+
auxiliary_heat_running: auxiliary_heat_running.optional().nullable(),
174+
subscription_required: subscription_required.optional().nullable(),
175+
})
176+
177+
export type DeviceErrorMap = z.infer<typeof device_error_map>
178+
141179
const warning_code_description =
142180
'Unique identifier of the type of warning. Enables quick recognition and categorization of the issue.'
143181

144182
const common_device_warning = z.object({
145183
message: z.string(),
184+
created_at: z.string().datetime(),
146185
})
147186

148187
const partial_backup_access_code_pool = common_device_warning
@@ -297,6 +336,47 @@ const device_warning = z.discriminatedUnion('warning_code', [
297336

298337
export type DeviceWarning = z.infer<typeof device_warning>
299338

339+
export const device_warning_map = z.object({
340+
partial_backup_access_code_pool: partial_backup_access_code_pool
341+
.optional()
342+
.nullable(),
343+
many_active_backup_codes: many_active_backup_codes.optional().nullable(),
344+
salto_unknown_device_type: salto_unknown_device_type.optional().nullable(),
345+
wyze_device_missing_gateway: wyze_device_missing_gateway
346+
.optional()
347+
.nullable(),
348+
functional_offline_device: functional_offline_device.optional().nullable(),
349+
third_party_integration_detected: third_party_integration_detected
350+
.optional()
351+
.nullable(),
352+
nest_thermostat_in_manual_eco_mode: nest_thermostat_in_manual_eco_mode
353+
.optional()
354+
.nullable(),
355+
ttlock_lock_gateway_unlocking_not_enabled:
356+
ttlock_lock_gateway_unlocking_not_enabled.optional().nullable(),
357+
ttlock_weak_gateway_signal: ttlock_weak_gateway_signal.optional().nullable(),
358+
temperature_threshold_exceeded: temperature_threshold_exceeded
359+
.optional()
360+
.nullable(),
361+
device_communication_degraded: device_communication_degraded
362+
.optional()
363+
.nullable(),
364+
scheduled_maintenance_window: scheduled_maintenance_window
365+
.optional()
366+
.nullable(),
367+
device_has_flaky_connection: device_has_flaky_connection
368+
.extend({
369+
_event_id: z.string().uuid().optional(),
370+
})
371+
.optional()
372+
.nullable(),
373+
salto_office_mode: salto_office_mode.optional().nullable(),
374+
salto_privacy_mode: salto_privacy_mode.optional().nullable(),
375+
unknown_issue_with_phone: unknown_issue_with_phone.optional().nullable(),
376+
})
377+
378+
export type DeviceWarningMap = z.infer<typeof device_warning_map>
379+
300380
export const common_device_properties = z.object({
301381
online: z.boolean().describe('Indicates whether the device is online.'),
302382
name: z.string().describe(`
@@ -440,6 +520,18 @@ export const common_device_properties = z.object({
440520
.optional(),
441521
})
442522

523+
export const device_and_connected_account_error_options = [
524+
...device_error.options,
525+
...connected_account_error.options.filter(
526+
(_connected_account_error) =>
527+
!device_error.options.some(
528+
(_device_error) =>
529+
_device_error.shape.error_code.value ===
530+
_connected_account_error.shape.error_code.value,
531+
),
532+
),
533+
]
534+
443535
export const device = z
444536
.object({
445537
device_id: z.string().uuid().describe('Unique identifier for the device.'),
@@ -495,7 +587,14 @@ export const device = z
495587
.array(
496588
z.discriminatedUnion('error_code', [
497589
...device_error.options,
498-
...connected_account_error.options,
590+
...connected_account_error.options.filter(
591+
(_connected_account_error) =>
592+
!device_error.options.some(
593+
(_device_error) =>
594+
_device_error.shape.error_code.value ===
595+
_connected_account_error.shape.error_code.value,
596+
),
597+
),
499598
]),
500599
)
501600
.describe(

0 commit comments

Comments
 (0)