feat(devices): push General/Clock/Bells/Alerts config live over MQTT
Adopts useDeviceCommand across DeviceDetail and its tabs so config changes (log levels, clock settings, bell outputs, alert thresholds, backlight, attributes) are sent to the device immediately via control commands and only persisted to Firestore once the device acks success, instead of writing Firestore first and hoping the device eventually picks it up. - GeneralTab: log-level sliders now call log.set_serial/sd/mqtt directly and revert on failure; a background log.get_config + network.info pull reconciles Firestore against the device's actual state once per mount - ClockTab, BellsTab, ControlTab, and the Edit* modals: same live-command-then-persist pattern - EditLoggingModal is removed — its job (log level editing) moved inline into GeneralTab's sliders, so a modal round-trip is no longer needed - DeviceDetail wires the shared useDeviceCommand connection through to each tab and adds a Health tab entry Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ function timeToIso(hhmm) {
|
||||
|
||||
const toBool = (v) => v === 'true' || v === true
|
||||
|
||||
export default function EditBacklightModal({ open, onClose, onSaved, attr, clock, sub, id }) {
|
||||
export default function EditBacklightModal({ open, onClose, onSaved, attr, clock, sub, id, sendMqttCommand }) {
|
||||
const maxOutputs = sub?.maxOutputs || 8
|
||||
const bellOutputsUsed = (attr?.bellOutputs || []).filter((o) => o > 0)
|
||||
const clockOutputsUsed = (clock?.clockOutputs || []).filter((o) => o > 0)
|
||||
@@ -47,20 +47,30 @@ export default function EditBacklightModal({ open, onClose, onSaved, attr, clock
|
||||
setSaving(true)
|
||||
setError('')
|
||||
try {
|
||||
const enabled = toBool(isOn)
|
||||
// Push to the device first — only write Firestore once it confirms.
|
||||
await sendMqttCommand('clock.set_backlight', {
|
||||
backlight: enabled,
|
||||
backlight_output: Number(output),
|
||||
backlight_on: enabled ? onTime : undefined,
|
||||
backlight_off: enabled ? offTime : undefined,
|
||||
})
|
||||
|
||||
await api.put(`/devices/${id}`, {
|
||||
device_attributes: {
|
||||
clockSettings: {
|
||||
...clock,
|
||||
isBacklightAutomationOn: toBool(isOn),
|
||||
isBacklightAutomationOn: enabled,
|
||||
backlightOutput: Number(output),
|
||||
backlightTurnOnTime: toBool(isOn) && onTime ? timeToIso(onTime) : '',
|
||||
backlightTurnOffTime: toBool(isOn) && offTime ? timeToIso(offTime) : '',
|
||||
backlightTurnOnTime: enabled && onTime ? timeToIso(onTime) : '',
|
||||
backlightTurnOffTime: enabled && offTime ? timeToIso(offTime) : '',
|
||||
},
|
||||
},
|
||||
})
|
||||
await onSaved()
|
||||
onClose()
|
||||
} catch (err) {
|
||||
// sendMqttCommand already surfaced a failure toast if the device rejected it.
|
||||
setError(err.message || 'Failed to save.')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
|
||||
Reference in New Issue
Block a user