@seamapi/react 4.12.1 → 4.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -17
- package/dist/elements.js +9445 -9053
- package/dist/elements.js.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.css.map +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.min.css.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/seam/SeamProvider.d.ts +1 -1
- package/lib/seam/SeamProvider.js +1 -1
- package/lib/seam/SeamProvider.js.map +1 -1
- package/lib/seam/access-codes/use-access-code.js +1 -1
- package/lib/seam/access-codes/use-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-access-codes.js +1 -1
- package/lib/seam/access-codes/use-access-codes.js.map +1 -1
- package/lib/seam/access-codes/use-create-access-code.d.ts +1 -1
- package/lib/seam/access-codes/use-create-access-code.js +1 -1
- package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-delete-access-code.js +1 -1
- package/lib/seam/access-codes/use-delete-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-generate-access-code-code.js +1 -1
- package/lib/seam/access-codes/use-generate-access-code-code.js.map +1 -1
- package/lib/seam/access-codes/use-update-access-code.js +1 -1
- package/lib/seam/access-codes/use-update-access-code.js.map +1 -1
- package/lib/seam/client-sessions/use-client-session.js +1 -1
- package/lib/seam/client-sessions/use-client-session.js.map +1 -1
- package/lib/seam/components/DeviceDetails/LockDeviceDetails.js +2 -23
- package/lib/seam/components/DeviceDetails/LockDeviceDetails.js.map +1 -1
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.d.ts +11 -0
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js +68 -0
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js.map +1 -0
- package/lib/seam/components/SupportedDeviceTable/use-device-model.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-model.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-models.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-models.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js.map +1 -1
- package/lib/seam/connect-webviews/use-create-connect-webview.js +1 -1
- package/lib/seam/connect-webviews/use-create-connect-webview.js.map +1 -1
- package/lib/seam/connected-accounts/use-connected-account.js +1 -1
- package/lib/seam/connected-accounts/use-connected-account.js.map +1 -1
- package/lib/seam/devices/use-device-providers.js +1 -1
- package/lib/seam/devices/use-device-providers.js.map +1 -1
- package/lib/seam/devices/use-device.js +1 -1
- package/lib/seam/devices/use-device.js.map +1 -1
- package/lib/seam/devices/use-devices.js +1 -1
- package/lib/seam/devices/use-devices.js.map +1 -1
- package/lib/seam/devices/use-update-device-name.js +1 -1
- package/lib/seam/devices/use-update-device-name.js.map +1 -1
- package/lib/seam/events/use-events.js +1 -1
- package/lib/seam/events/use-events.js.map +1 -1
- package/lib/seam/index.d.ts +0 -6
- package/lib/seam/index.js +0 -6
- package/lib/seam/index.js.map +1 -1
- package/lib/seam/locks/use-lock-door.d.ts +17 -0
- package/lib/seam/locks/use-lock-door.js +60 -0
- package/lib/seam/locks/use-lock-door.js.map +1 -0
- package/lib/seam/locks/use-toggle-lock.js +1 -1
- package/lib/seam/locks/use-toggle-lock.js.map +1 -1
- package/lib/seam/locks/use-unlock-door.d.ts +17 -0
- package/lib/seam/locks/use-unlock-door.js +60 -0
- package/lib/seam/locks/use-unlock-door.js.map +1 -0
- package/lib/seam/noise-sensors/use-noise-thresholds.js +1 -1
- package/lib/seam/noise-sensors/use-noise-thresholds.js.map +1 -1
- package/lib/seam/thermostats/use-cool-thermostat.js +1 -1
- package/lib/seam/thermostats/use-cool-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-create-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-create-thermostat-climate-preset.js.map +1 -1
- package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js.map +1 -1
- package/lib/seam/thermostats/use-heat-cool-thermostat.js +1 -1
- package/lib/seam/thermostats/use-heat-cool-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-heat-thermostat.js +1 -1
- package/lib/seam/thermostats/use-heat-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-set-thermostat-fan-mode.js +1 -1
- package/lib/seam/thermostats/use-set-thermostat-fan-mode.js.map +1 -1
- package/lib/seam/thermostats/use-set-thermostat-off.js +1 -1
- package/lib/seam/thermostats/use-set-thermostat-off.js.map +1 -1
- package/lib/seam/thermostats/use-update-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-update-thermostat-climate-preset.js.map +1 -1
- package/lib/telemetry/hooks.js +1 -1
- package/lib/telemetry/hooks.js.map +1 -1
- package/lib/ui/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -0
- package/src/lib/index.ts +0 -1
- package/src/lib/seam/SeamProvider.tsx +4 -4
- package/src/lib/seam/access-codes/use-access-code.ts +1 -1
- package/src/lib/seam/access-codes/use-access-codes.ts +1 -1
- package/src/lib/seam/access-codes/use-create-access-code.ts +2 -3
- package/src/lib/seam/access-codes/use-delete-access-code.ts +1 -2
- package/src/lib/seam/access-codes/use-generate-access-code-code.ts +1 -2
- package/src/lib/seam/access-codes/use-update-access-code.ts +1 -2
- package/src/lib/seam/client-sessions/use-client-session.ts +1 -1
- package/src/lib/seam/components/DeviceDetails/LockDeviceDetails.tsx +7 -43
- package/src/lib/seam/components/DeviceDetails/LockDeviceLockButtons.tsx +137 -0
- package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +1 -1
- package/src/lib/seam/connect-webviews/use-create-connect-webview.ts +1 -1
- package/src/lib/seam/connected-accounts/use-connected-account.ts +1 -1
- package/src/lib/seam/devices/use-device-providers.ts +1 -1
- package/src/lib/seam/devices/use-device.ts +1 -1
- package/src/lib/seam/devices/use-devices.ts +1 -1
- package/src/lib/seam/devices/use-update-device-name.ts +1 -2
- package/src/lib/seam/events/use-events.ts +1 -1
- package/src/lib/seam/index.ts +0 -6
- package/src/lib/seam/locks/use-lock-door.ts +101 -0
- package/src/lib/seam/locks/use-toggle-lock.ts +1 -2
- package/src/lib/seam/locks/use-unlock-door.ts +104 -0
- package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +1 -1
- package/src/lib/seam/thermostats/use-cool-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-create-thermostat-climate-preset.ts +1 -1
- package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +1 -1
- package/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-heat-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-set-thermostat-fan-mode.ts +1 -2
- package/src/lib/seam/thermostats/use-set-thermostat-off.ts +1 -2
- package/src/lib/seam/thermostats/use-update-thermostat-climate-preset.ts +1 -1
- package/src/lib/telemetry/hooks.ts +1 -1
- package/src/lib/version.ts +1 -1
- package/src/styles/_device-details.scss +1 -0
- package/lib/seam/SeamQueryProvider.d.ts +0 -40
- package/lib/seam/SeamQueryProvider.js +0 -180
- package/lib/seam/SeamQueryProvider.js.map +0 -1
- package/lib/seam/use-seam-client.d.ts +0 -14
- package/lib/seam/use-seam-client.js +0 -134
- package/lib/seam/use-seam-client.js.map +0 -1
- package/lib/seam/use-seam-infinite-query.d.ts +0 -15
- package/lib/seam/use-seam-infinite-query.js +0 -47
- package/lib/seam/use-seam-infinite-query.js.map +0 -1
- package/lib/seam/use-seam-mutation-without-workspace.d.ts +0 -9
- package/lib/seam/use-seam-mutation-without-workspace.js +0 -17
- package/lib/seam/use-seam-mutation-without-workspace.js.map +0 -1
- package/lib/seam/use-seam-mutation.d.ts +0 -10
- package/lib/seam/use-seam-mutation.js +0 -17
- package/lib/seam/use-seam-mutation.js.map +0 -1
- package/lib/seam/use-seam-query-without-workspace.d.ts +0 -11
- package/lib/seam/use-seam-query-without-workspace.js +0 -25
- package/lib/seam/use-seam-query-without-workspace.js.map +0 -1
- package/lib/seam/use-seam-query.d.ts +0 -12
- package/lib/seam/use-seam-query.js +0 -25
- package/lib/seam/use-seam-query.js.map +0 -1
- package/src/lib/seam/SeamQueryProvider.tsx +0 -356
- package/src/lib/seam/use-seam-client.ts +0 -225
- package/src/lib/seam/use-seam-infinite-query.ts +0 -103
- package/src/lib/seam/use-seam-mutation-without-workspace.ts +0 -56
- package/src/lib/seam/use-seam-mutation.ts +0 -64
- package/src/lib/seam/use-seam-query-without-workspace.ts +0 -59
- package/src/lib/seam/use-seam-query.ts +0 -66
|
@@ -7,11 +7,10 @@ import { NestedAccessCodeTable } from 'lib/seam/components/AccessCodeTable/Acces
|
|
|
7
7
|
import type { NestedSpecificDeviceDetailsProps } from 'lib/seam/components/DeviceDetails/DeviceDetails.js'
|
|
8
8
|
import { DeviceInfo } from 'lib/seam/components/DeviceDetails/DeviceInfo.js'
|
|
9
9
|
import { DeviceModel } from 'lib/seam/components/DeviceDetails/DeviceModel.js'
|
|
10
|
+
import { LockDeviceLockButtons } from 'lib/seam/components/DeviceDetails/LockDeviceLockButtons.js'
|
|
10
11
|
import { deviceErrorFilter, deviceWarningFilter } from 'lib/seam/filters.js'
|
|
11
12
|
import type { LockDevice } from 'lib/seam/locks/lock-device.js'
|
|
12
|
-
import { useToggleLock } from 'lib/seam/locks/use-toggle-lock.js'
|
|
13
13
|
import { Alerts } from 'lib/ui/Alert/Alerts.js'
|
|
14
|
-
import { Button } from 'lib/ui/Button.js'
|
|
15
14
|
import { BatteryStatusIndicator } from 'lib/ui/device/BatteryStatusIndicator.js'
|
|
16
15
|
import { DeviceImage } from 'lib/ui/device/DeviceImage.js'
|
|
17
16
|
import { EditableDeviceName } from 'lib/ui/device/EditableDeviceName.js'
|
|
@@ -48,20 +47,6 @@ export function LockDeviceDetails({
|
|
|
48
47
|
const [snackbarVariant, setSnackbarVariant] =
|
|
49
48
|
useState<SnackbarVariant>('success')
|
|
50
49
|
|
|
51
|
-
const toggleLock = useToggleLock({
|
|
52
|
-
onSuccess: () => {
|
|
53
|
-
setSnackbarVisible(true)
|
|
54
|
-
setSnackbarVariant('success')
|
|
55
|
-
},
|
|
56
|
-
onError: () => {
|
|
57
|
-
setSnackbarVisible(true)
|
|
58
|
-
setSnackbarVariant('error')
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const lockStatus = device.properties.locked ? t.locked : t.unlocked
|
|
63
|
-
const toggleLockLabel = device.properties.locked ? t.unlock : t.lock
|
|
64
|
-
|
|
65
50
|
const accessCodeCount = accessCodes?.length
|
|
66
51
|
|
|
67
52
|
if (accessCodes == null) {
|
|
@@ -163,28 +148,12 @@ export function LockDeviceDetails({
|
|
|
163
148
|
</div>
|
|
164
149
|
|
|
165
150
|
<div className='seam-box'>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<div className='seam-right'>
|
|
173
|
-
{!disableLockUnlock &&
|
|
174
|
-
device.capabilities_supported.includes('lock') && (
|
|
175
|
-
<Button
|
|
176
|
-
size='small'
|
|
177
|
-
onClick={() => {
|
|
178
|
-
toggleLock.mutate(device)
|
|
179
|
-
}}
|
|
180
|
-
>
|
|
181
|
-
{toggleLockLabel}
|
|
182
|
-
</Button>
|
|
183
|
-
)}
|
|
184
|
-
</div>
|
|
185
|
-
</div>
|
|
186
|
-
)}
|
|
187
|
-
|
|
151
|
+
<LockDeviceLockButtons
|
|
152
|
+
setSnackbarVisible={setSnackbarVisible}
|
|
153
|
+
setSnackbarVariant={setSnackbarVariant}
|
|
154
|
+
device={device}
|
|
155
|
+
disableLockUnlock={disableLockUnlock}
|
|
156
|
+
/>
|
|
188
157
|
<AccessCodeLength
|
|
189
158
|
supportedCodeLengths={
|
|
190
159
|
device.properties?.supported_code_lengths ?? []
|
|
@@ -230,14 +199,9 @@ function AccessCodeLength(props: {
|
|
|
230
199
|
|
|
231
200
|
const t = {
|
|
232
201
|
device: 'Device',
|
|
233
|
-
unlock: 'Unlock',
|
|
234
|
-
lock: 'Lock',
|
|
235
|
-
locked: 'Locked',
|
|
236
|
-
unlocked: 'Unlocked',
|
|
237
202
|
accessCodes: 'access codes',
|
|
238
203
|
codeLength: 'Code length',
|
|
239
204
|
digits: 'digits',
|
|
240
|
-
lockStatus: 'Lock status',
|
|
241
205
|
status: 'Status',
|
|
242
206
|
power: 'Power',
|
|
243
207
|
successfullyUpdated: 'Lock status has been successfully updated',
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { LockDevice } from 'lib/seam/locks/lock-device.js'
|
|
2
|
+
import { useLock } from 'lib/seam/locks/use-lock-door.js'
|
|
3
|
+
import { useToggleLock } from 'lib/seam/locks/use-toggle-lock.js'
|
|
4
|
+
import { useUnlock } from 'lib/seam/locks/use-unlock-door.js'
|
|
5
|
+
import { Button } from 'lib/ui/Button.js'
|
|
6
|
+
import type { SnackbarVariant } from 'lib/ui/Snackbar/Snackbar.js'
|
|
7
|
+
|
|
8
|
+
interface LockDeviceLockButtonsProps {
|
|
9
|
+
device: LockDevice
|
|
10
|
+
disableLockUnlock: boolean
|
|
11
|
+
setSnackbarVisible: (visible: boolean) => void
|
|
12
|
+
setSnackbarVariant: (variant: SnackbarVariant) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function LockDeviceLockButtons({
|
|
16
|
+
device,
|
|
17
|
+
setSnackbarVariant,
|
|
18
|
+
setSnackbarVisible,
|
|
19
|
+
disableLockUnlock,
|
|
20
|
+
}: LockDeviceLockButtonsProps): JSX.Element | null {
|
|
21
|
+
const lockStatus = device.properties.locked ? t.locked : t.unlocked
|
|
22
|
+
const toggleLockLabel = device.properties.locked ? t.unlock : t.lock
|
|
23
|
+
|
|
24
|
+
const toggleLock = useToggleLock({
|
|
25
|
+
onSuccess: () => {
|
|
26
|
+
setSnackbarVisible(true)
|
|
27
|
+
setSnackbarVariant('success')
|
|
28
|
+
},
|
|
29
|
+
onError: () => {
|
|
30
|
+
setSnackbarVisible(true)
|
|
31
|
+
setSnackbarVariant('error')
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const lock = useLock({
|
|
36
|
+
onSuccess: () => {
|
|
37
|
+
setSnackbarVisible(true)
|
|
38
|
+
setSnackbarVariant('success')
|
|
39
|
+
},
|
|
40
|
+
onError: () => {
|
|
41
|
+
setSnackbarVisible(true)
|
|
42
|
+
setSnackbarVariant('error')
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const unlock = useUnlock({
|
|
47
|
+
onSuccess: () => {
|
|
48
|
+
setSnackbarVisible(true)
|
|
49
|
+
setSnackbarVariant('success')
|
|
50
|
+
},
|
|
51
|
+
onError: () => {
|
|
52
|
+
setSnackbarVisible(true)
|
|
53
|
+
setSnackbarVariant('error')
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
if (disableLockUnlock) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
device.can_remotely_lock === true &&
|
|
63
|
+
device.can_remotely_unlock === true
|
|
64
|
+
) {
|
|
65
|
+
return (
|
|
66
|
+
<div className='seam-content seam-lock-status'>
|
|
67
|
+
<div>
|
|
68
|
+
<span className='seam-label'>{t.lockStatus}</span>
|
|
69
|
+
<span className='seam-value'>{lockStatus}</span>
|
|
70
|
+
</div>
|
|
71
|
+
<div className='seam-right'>
|
|
72
|
+
<Button
|
|
73
|
+
size='small'
|
|
74
|
+
onClick={() => {
|
|
75
|
+
toggleLock.mutate(device)
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{toggleLockLabel}
|
|
79
|
+
</Button>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (device.can_remotely_lock === true) {
|
|
86
|
+
return (
|
|
87
|
+
<div className='seam-content seam-lock-status'>
|
|
88
|
+
<div>
|
|
89
|
+
<span className='seam-label'>{t.lockStatus}</span>
|
|
90
|
+
<span className='seam-value'>{lockStatus}</span>
|
|
91
|
+
</div>
|
|
92
|
+
<div className='seam-right'>
|
|
93
|
+
<Button
|
|
94
|
+
size='small'
|
|
95
|
+
onClick={() => {
|
|
96
|
+
lock.mutate(device)
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{t.lock}
|
|
100
|
+
</Button>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (device.can_remotely_unlock === true) {
|
|
107
|
+
return (
|
|
108
|
+
<div className='seam-content seam-lock-status'>
|
|
109
|
+
<div>
|
|
110
|
+
<span className='seam-label'>{t.lockStatus}</span>
|
|
111
|
+
<span className='seam-value'>{lockStatus}</span>
|
|
112
|
+
</div>
|
|
113
|
+
<div className='seam-right'>
|
|
114
|
+
<Button
|
|
115
|
+
size='small'
|
|
116
|
+
onClick={() => {
|
|
117
|
+
unlock.mutate(device)
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{t.unlock}
|
|
121
|
+
</Button>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return null
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const t = {
|
|
131
|
+
unlock: 'Unlock',
|
|
132
|
+
lock: 'Lock',
|
|
133
|
+
locked: 'Locked',
|
|
134
|
+
unlocked: 'Unlocked',
|
|
135
|
+
lockStatus: 'Lock status',
|
|
136
|
+
statusUnknown: 'Unknown',
|
|
137
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type {
|
|
3
4
|
DeviceModel,
|
|
4
5
|
RouteRequestParams,
|
|
@@ -6,7 +7,6 @@ import type {
|
|
|
6
7
|
} from '@seamapi/types/devicedb'
|
|
7
8
|
import { useQuery } from '@tanstack/react-query'
|
|
8
9
|
|
|
9
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
10
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseDeviceModelParams = DeviceModelsGetParams
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type {
|
|
3
4
|
DeviceModel,
|
|
4
5
|
RouteRequestParams,
|
|
@@ -6,7 +7,6 @@ import type {
|
|
|
6
7
|
} from '@seamapi/types/devicedb'
|
|
7
8
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
8
9
|
|
|
9
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
10
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseDeviceModelsParams = DeviceModelsListParams
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type {
|
|
3
4
|
Manufacturer,
|
|
4
5
|
RouteRequestParams,
|
|
@@ -6,7 +7,6 @@ import type {
|
|
|
6
7
|
} from '@seamapi/types/devicedb'
|
|
7
8
|
import { useQuery } from '@tanstack/react-query'
|
|
8
9
|
|
|
9
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
10
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseManufacturerParams = ManufacturersGetParams
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type {
|
|
3
4
|
Manufacturer,
|
|
4
5
|
RouteRequestParams,
|
|
@@ -6,7 +7,6 @@ import type {
|
|
|
6
7
|
} from '@seamapi/types/devicedb'
|
|
7
8
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
8
9
|
|
|
9
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
10
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseManufacturersParams = ManufacturersListParams
|
|
@@ -2,11 +2,11 @@ import type {
|
|
|
2
2
|
ConnectWebviewsCreateBody,
|
|
3
3
|
SeamHttpApiError,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import type { ConnectWebview } from '@seamapi/types/connect'
|
|
6
7
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query'
|
|
7
8
|
|
|
8
9
|
import { useClientSession } from 'lib/seam/client-sessions/use-client-session.js'
|
|
9
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
10
|
|
|
11
11
|
export interface UseCreateConnectWebviewParams {
|
|
12
12
|
willNavigateToWebview?: boolean
|
|
@@ -2,10 +2,10 @@ import type {
|
|
|
2
2
|
ConnectedAccountsGetParams,
|
|
3
3
|
SeamHttpApiError,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import type { ConnectedAccount } from '@seamapi/types/connect'
|
|
6
7
|
import { useQuery } from '@tanstack/react-query'
|
|
7
8
|
|
|
8
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
9
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseConnectedAccountParams = ConnectedAccountsGetParams
|
|
@@ -2,10 +2,10 @@ import type {
|
|
|
2
2
|
DevicesListDeviceProvidersParams,
|
|
3
3
|
SeamHttpApiError,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import type { DeviceProvider } from '@seamapi/types/connect'
|
|
6
7
|
import { useQuery } from '@tanstack/react-query'
|
|
7
8
|
|
|
8
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
9
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseDeviceProvidersParams = DevicesListDeviceProvidersParams
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DevicesGetParams, SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type { Device } from '@seamapi/types/connect'
|
|
3
4
|
import { useQuery } from '@tanstack/react-query'
|
|
4
5
|
|
|
5
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
6
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseDeviceParams = DevicesGetParams
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DevicesListParams, SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type { Device } from '@seamapi/types/connect'
|
|
3
4
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
5
|
|
|
5
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
6
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseDevicesParams = DevicesListParams
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
DevicesUpdateBody,
|
|
4
4
|
SeamHttpApiError,
|
|
5
5
|
} from '@seamapi/http/connect'
|
|
6
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
6
7
|
import type { Device } from '@seamapi/types/connect'
|
|
7
8
|
import {
|
|
8
9
|
useMutation,
|
|
@@ -10,8 +11,6 @@ import {
|
|
|
10
11
|
useQueryClient,
|
|
11
12
|
} from '@tanstack/react-query'
|
|
12
13
|
|
|
13
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
14
|
-
|
|
15
14
|
export type UseUpdateDeviceNameParams = never
|
|
16
15
|
|
|
17
16
|
export type UseUpdateDeviceNameData = undefined
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { EventsListParams, SeamHttpApiError } from '@seamapi/http/connect'
|
|
2
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
2
3
|
import type { SeamEvent } from '@seamapi/types/connect'
|
|
3
4
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
5
|
|
|
5
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
6
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseEventsParams = EventsListParams
|
package/src/lib/seam/index.ts
CHANGED
|
@@ -11,10 +11,4 @@ export * from './devices/use-device.js'
|
|
|
11
11
|
export * from './devices/use-device-providers.js'
|
|
12
12
|
export * from './devices/use-devices.js'
|
|
13
13
|
export * from './SeamProvider.js'
|
|
14
|
-
export * from './use-seam-client.js'
|
|
15
|
-
export * from './use-seam-infinite-query.js'
|
|
16
|
-
export * from './use-seam-mutation.js'
|
|
17
|
-
export * from './use-seam-mutation-without-workspace.js'
|
|
18
|
-
export * from './use-seam-query.js'
|
|
19
14
|
export * from './use-seam-query-result.js'
|
|
20
|
-
export * from './use-seam-query-without-workspace.js'
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SeamActionAttemptFailedError,
|
|
3
|
+
SeamActionAttemptTimeoutError,
|
|
4
|
+
SeamHttpApiError,
|
|
5
|
+
} from '@seamapi/http/connect'
|
|
6
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
7
|
+
import type { ActionAttempt, Device } from '@seamapi/types/connect'
|
|
8
|
+
import {
|
|
9
|
+
useMutation,
|
|
10
|
+
type UseMutationResult,
|
|
11
|
+
useQueryClient,
|
|
12
|
+
} from '@tanstack/react-query'
|
|
13
|
+
|
|
14
|
+
export type UseLockData = undefined
|
|
15
|
+
|
|
16
|
+
export type UseLockMutationVariables = Pick<Device, 'device_id'> & {
|
|
17
|
+
properties: Required<Pick<Device['properties'], 'locked'>>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type LockActionAttempt = Extract<ActionAttempt, { action_type: 'LOCK_DOOR' }>
|
|
21
|
+
|
|
22
|
+
type MutationError =
|
|
23
|
+
| SeamHttpApiError
|
|
24
|
+
| SeamActionAttemptFailedError<LockActionAttempt>
|
|
25
|
+
| SeamActionAttemptTimeoutError<LockActionAttempt>
|
|
26
|
+
|
|
27
|
+
interface UseLockParams {
|
|
28
|
+
onError?: () => void
|
|
29
|
+
onSuccess?: () => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useLock(
|
|
33
|
+
params: UseLockParams = {}
|
|
34
|
+
): UseMutationResult<UseLockData, MutationError, UseLockMutationVariables> {
|
|
35
|
+
const { client } = useSeamClient()
|
|
36
|
+
const queryClient = useQueryClient()
|
|
37
|
+
|
|
38
|
+
return useMutation<UseLockData, MutationError, UseLockMutationVariables>({
|
|
39
|
+
mutationFn: async (variables) => {
|
|
40
|
+
const {
|
|
41
|
+
device_id: deviceId,
|
|
42
|
+
properties: { locked },
|
|
43
|
+
} = variables
|
|
44
|
+
if (client === null) throw new NullSeamClientError()
|
|
45
|
+
if (locked == null) return
|
|
46
|
+
await client.locks.lockDoor({ device_id: deviceId })
|
|
47
|
+
},
|
|
48
|
+
onMutate: (variables) => {
|
|
49
|
+
queryClient.setQueryData<Device[]>(['devices', 'list', {}], (devices) => {
|
|
50
|
+
if (devices == null) {
|
|
51
|
+
return devices
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return devices.map((device) => {
|
|
55
|
+
if (
|
|
56
|
+
device.device_id !== variables.device_id ||
|
|
57
|
+
device.properties.locked == null
|
|
58
|
+
) {
|
|
59
|
+
return device
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...device,
|
|
64
|
+
properties: {
|
|
65
|
+
...device.properties,
|
|
66
|
+
locked: !variables.properties.locked,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
queryClient.setQueryData<Device>(
|
|
73
|
+
['devices', 'get', { device_id: variables.device_id }],
|
|
74
|
+
(device) => {
|
|
75
|
+
if (device?.properties.locked == null) return device
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
...device,
|
|
79
|
+
properties: {
|
|
80
|
+
...device.properties,
|
|
81
|
+
locked: !variables.properties.locked,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
},
|
|
87
|
+
onError: async (_error, variables) => {
|
|
88
|
+
params.onError?.()
|
|
89
|
+
|
|
90
|
+
await queryClient.invalidateQueries({
|
|
91
|
+
queryKey: ['devices', 'list'],
|
|
92
|
+
})
|
|
93
|
+
await queryClient.invalidateQueries({
|
|
94
|
+
queryKey: ['devices', 'get', { device_id: variables.device_id }],
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
onSuccess() {
|
|
98
|
+
params.onSuccess?.()
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
}
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
SeamActionAttemptTimeoutError,
|
|
4
4
|
SeamHttpApiError,
|
|
5
5
|
} from '@seamapi/http/connect'
|
|
6
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
6
7
|
import type { ActionAttempt, Device } from '@seamapi/types/connect'
|
|
7
8
|
import {
|
|
8
9
|
useMutation,
|
|
@@ -10,8 +11,6 @@ import {
|
|
|
10
11
|
useQueryClient,
|
|
11
12
|
} from '@tanstack/react-query'
|
|
12
13
|
|
|
13
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
14
|
-
|
|
15
14
|
export type UseToggleLockData = undefined
|
|
16
15
|
|
|
17
16
|
export type UseToggleLockMutationVariables = Pick<Device, 'device_id'> & {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SeamActionAttemptFailedError,
|
|
3
|
+
SeamActionAttemptTimeoutError,
|
|
4
|
+
SeamHttpApiError,
|
|
5
|
+
} from '@seamapi/http/connect'
|
|
6
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
7
|
+
import type { ActionAttempt, Device } from '@seamapi/types/connect'
|
|
8
|
+
import {
|
|
9
|
+
useMutation,
|
|
10
|
+
type UseMutationResult,
|
|
11
|
+
useQueryClient,
|
|
12
|
+
} from '@tanstack/react-query'
|
|
13
|
+
|
|
14
|
+
export type UseUnlockData = undefined
|
|
15
|
+
|
|
16
|
+
export type UseUnlockMutationVariables = Pick<Device, 'device_id'> & {
|
|
17
|
+
properties: Required<Pick<Device['properties'], 'locked'>>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type UnlockActionAttempt = Extract<
|
|
21
|
+
ActionAttempt,
|
|
22
|
+
{ action_type: 'UNLOCK_DOOR' }
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
type MutationError =
|
|
26
|
+
| SeamHttpApiError
|
|
27
|
+
| SeamActionAttemptFailedError<UnlockActionAttempt>
|
|
28
|
+
| SeamActionAttemptTimeoutError<UnlockActionAttempt>
|
|
29
|
+
|
|
30
|
+
interface UseUnlockParams {
|
|
31
|
+
onError?: () => void
|
|
32
|
+
onSuccess?: () => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useUnlock(
|
|
36
|
+
params: UseUnlockParams = {}
|
|
37
|
+
): UseMutationResult<UseUnlockData, MutationError, UseUnlockMutationVariables> {
|
|
38
|
+
const { client } = useSeamClient()
|
|
39
|
+
const queryClient = useQueryClient()
|
|
40
|
+
|
|
41
|
+
return useMutation<UseUnlockData, MutationError, UseUnlockMutationVariables>({
|
|
42
|
+
mutationFn: async (variables) => {
|
|
43
|
+
const {
|
|
44
|
+
device_id: deviceId,
|
|
45
|
+
properties: { locked },
|
|
46
|
+
} = variables
|
|
47
|
+
if (client === null) throw new NullSeamClientError()
|
|
48
|
+
if (locked == null) return
|
|
49
|
+
await client.locks.unlockDoor({ device_id: deviceId })
|
|
50
|
+
},
|
|
51
|
+
onMutate: (variables) => {
|
|
52
|
+
queryClient.setQueryData<Device[]>(['devices', 'list', {}], (devices) => {
|
|
53
|
+
if (devices == null) {
|
|
54
|
+
return devices
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return devices.map((device) => {
|
|
58
|
+
if (
|
|
59
|
+
device.device_id !== variables.device_id ||
|
|
60
|
+
device.properties.locked == null
|
|
61
|
+
) {
|
|
62
|
+
return device
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
...device,
|
|
67
|
+
properties: {
|
|
68
|
+
...device.properties,
|
|
69
|
+
locked: !variables.properties.locked,
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
queryClient.setQueryData<Device>(
|
|
76
|
+
['devices', 'get', { device_id: variables.device_id }],
|
|
77
|
+
(device) => {
|
|
78
|
+
if (device?.properties.locked == null) return device
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
...device,
|
|
82
|
+
properties: {
|
|
83
|
+
...device.properties,
|
|
84
|
+
locked: !variables.properties.locked,
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
onError: async (_error, variables) => {
|
|
91
|
+
params.onError?.()
|
|
92
|
+
|
|
93
|
+
await queryClient.invalidateQueries({
|
|
94
|
+
queryKey: ['devices', 'list'],
|
|
95
|
+
})
|
|
96
|
+
await queryClient.invalidateQueries({
|
|
97
|
+
queryKey: ['devices', 'get', { device_id: variables.device_id }],
|
|
98
|
+
})
|
|
99
|
+
},
|
|
100
|
+
onSuccess() {
|
|
101
|
+
params.onSuccess?.()
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
}
|
|
@@ -2,10 +2,10 @@ import type {
|
|
|
2
2
|
NoiseSensorsNoiseThresholdsListParams,
|
|
3
3
|
SeamHttpApiError,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import type { NoiseThreshold } from '@seamapi/types/connect'
|
|
6
7
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
7
8
|
|
|
8
|
-
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
9
|
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseNoiseThresholdsParams = NoiseSensorsNoiseThresholdsListParams
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
SeamHttpApiError,
|
|
5
5
|
ThermostatsCoolBody,
|
|
6
6
|
} from '@seamapi/http/connect'
|
|
7
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
7
8
|
import type { ActionAttempt, Device } from '@seamapi/types/connect'
|
|
8
9
|
import {
|
|
9
10
|
useMutation,
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
getCoolingSetPointCelsius,
|
|
16
17
|
getCoolingSetPointFahrenheit,
|
|
17
18
|
} from 'lib/seam/thermostats/unit-conversion.js'
|
|
18
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
19
19
|
|
|
20
20
|
export type UseCoolThermostatParams = never
|
|
21
21
|
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
SeamHttpApiError,
|
|
3
3
|
ThermostatsCreateClimatePresetBody,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import {
|
|
6
7
|
useMutation,
|
|
7
8
|
type UseMutationResult,
|
|
@@ -13,7 +14,6 @@ import type {
|
|
|
13
14
|
ThermostatDevice,
|
|
14
15
|
} from 'lib/seam/thermostats/thermostat-device.js'
|
|
15
16
|
import { fahrenheitToCelsius } from 'lib/seam/thermostats/unit-conversion.js'
|
|
16
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
17
17
|
|
|
18
18
|
export type UseCreateThermostatClimatePresetParams = never
|
|
19
19
|
export type UseCreateThermostatClimatePresetData = undefined
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
SeamHttpApiError,
|
|
3
3
|
ThermostatsDeleteClimatePresetParams,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
|
+
import { NullSeamClientError, useSeamClient } from '@seamapi/react-query'
|
|
5
6
|
import {
|
|
6
7
|
useMutation,
|
|
7
8
|
type UseMutationResult,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
} from '@tanstack/react-query'
|
|
10
11
|
|
|
11
12
|
import type { ThermostatDevice } from 'lib/seam/thermostats/thermostat-device.js'
|
|
12
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
13
13
|
|
|
14
14
|
export type UseDeleteThermostatClimatePresetParams = never
|
|
15
15
|
|