Skip to content

Commit 945e1e2

Browse files
committed
add update call
1 parent fb52e91 commit 945e1e2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/lib/seam/components/DeviceDetails/DeviceDetails.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import {
23
type CommonProps,
34
withRequiredCommonProps,
@@ -9,19 +10,18 @@ import { useDevice } from 'lib/seam/devices/use-device.js'
910
import { isLockDevice } from 'lib/seam/locks/lock-device.js'
1011
import { isNoiseSensorDevice } from 'lib/seam/noise-sensors/noise-sensor-device.js'
1112
import { isThermostatDevice } from 'lib/seam/thermostats/thermostat-device.js'
13+
import { useSeamClient } from 'lib/seam/use-seam-client.js'
1214
import { useComponentTelemetry } from 'lib/telemetry/index.js'
1315

1416
export interface DeviceDetailsProps extends CommonProps {
1517
deviceId: string
1618
}
1719

1820
export const NestedDeviceDetails = withRequiredCommonProps(DeviceDetails)
19-
2021
export interface NestedSpecificDeviceDetailsProps
2122
extends Required<Omit<CommonProps, 'onBack' | 'className'>> {
2223
onBack: (() => void) | undefined
2324
className: string | undefined
24-
onEditName?: (newName: string) => void
2525
}
2626

2727
export function DeviceDetails({
@@ -39,10 +39,24 @@ export function DeviceDetails({
3939
}: DeviceDetailsProps): JSX.Element | null {
4040
useComponentTelemetry('DeviceDetails')
4141

42-
const { device } = useDevice({
42+
const { client } = useSeamClient();
43+
const { device, refetch: refetchDevice } = useDevice({
4344
device_id: deviceId,
4445
})
4546

47+
48+
const updateDeviceName = async (newName: string): Promise<void> => {
49+
if (client == null) return;
50+
51+
client.devices.update({
52+
device_id: deviceId,
53+
name: newName,
54+
})
55+
.then(async () => await refetchDevice())
56+
.catch((error) => { console.error(error); })
57+
58+
}
59+
4660
if (device == null) {
4761
return null
4862
}
@@ -64,7 +78,7 @@ export function DeviceDetails({
6478
return (
6579
<LockDeviceDetails
6680
device={device}
67-
onEditName={props.onEditName}
81+
onEditName={updateDeviceName}
6882
{...props}
6983
/>
7084
)
@@ -74,7 +88,7 @@ export function DeviceDetails({
7488
return (
7589
<ThermostatDeviceDetails
7690
device={device}
77-
onEditName={props.onEditName}
91+
onEditName={updateDeviceName}
7892
{...props}
7993
/>
8094
)
@@ -84,7 +98,7 @@ export function DeviceDetails({
8498
return (
8599
<NoiseSensorDeviceDetails
86100
device={device}
87-
onEditName={props.onEditName}
101+
onEditName={updateDeviceName}
88102
{...props}
89103
/>
90104
)

src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ThermostatCard } from 'lib/ui/thermostat/ThermostatCard.js'
2929
interface ThermostatDeviceDetailsProps
3030
extends NestedSpecificDeviceDetailsProps {
3131
device: ThermostatDevice
32+
onEditName?: (newName: string) => void
3233
}
3334

3435
export function ThermostatDeviceDetails({
@@ -37,6 +38,7 @@ export function ThermostatDeviceDetails({
3738
disableConnectedAccountInformation,
3839
onBack,
3940
className,
41+
onEditName
4042
}: ThermostatDeviceDetailsProps): JSX.Element | null {
4143
if (device == null) {
4244
return null
@@ -47,7 +49,7 @@ export function ThermostatDeviceDetails({
4749
<ContentHeader title={t.thermostat} onBack={onBack} />
4850

4951
<div className='seam-body'>
50-
<ThermostatCard device={device} />
52+
<ThermostatCard device={device} onEditName={onEditName} />
5153

5254
<div className='seam-thermostat-device-details'>
5355
<DetailSectionGroup>
@@ -233,7 +235,7 @@ function ClimateSettingRow({
233235
}
234236
}
235237

236-
return () => {}
238+
return () => { }
237239
}, [isHeatCoolSuccess, isHeatSuccess, isCoolSuccess, isSetOffSuccess])
238240

239241
return (
@@ -273,7 +275,7 @@ function ClimateSettingRow({
273275
delta={
274276
Number(
275277
'min_heating_cooling_delta_fahrenheit' in device.properties &&
276-
device.properties.min_heating_cooling_delta_fahrenheit
278+
device.properties.min_heating_cooling_delta_fahrenheit
277279
) ?? 0
278280
}
279281
/>

0 commit comments

Comments
 (0)