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:
@@ -55,7 +55,7 @@ function StepSlider({ steps, value, onChange, label }) {
|
||||
)
|
||||
}
|
||||
|
||||
export default function EditClockSettingsModal({ open, onClose, onSaved, attr, sub, id }) {
|
||||
export default function EditClockSettingsModal({ open, onClose, onSaved, attr, sub, id, sendMqttCommand }) {
|
||||
const clock = attr?.clockSettings || {}
|
||||
const maxOutputs = sub?.maxOutputs || 8
|
||||
const bellOutputsUsed = (attr?.bellOutputs || []).filter(o => o > 0)
|
||||
@@ -85,6 +85,16 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
|
||||
setSaving(true)
|
||||
setError('')
|
||||
try {
|
||||
// Push to the device first — clock.set_config batches enable/outputs/timings
|
||||
// into one round trip. Firestore is only written once the device confirms.
|
||||
await sendMqttCommand('clock.set_config', {
|
||||
enabled: hasClock,
|
||||
c1: out1,
|
||||
c2: out2,
|
||||
pulse_duration: runPulse,
|
||||
pause_duration: pauseMs,
|
||||
})
|
||||
|
||||
await api.put(`/devices/${id}`, {
|
||||
device_attributes: {
|
||||
hasClock,
|
||||
@@ -98,6 +108,7 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
|
||||
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