Skip to content

Commit f098b98

Browse files
authored
Prevent crash on creating automation from a server controlled iOS Action (#2590)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> When user tap on "Create automation" inside the action configuration screen the app was crashing because it was trying to save the action which was controlled server-side (created in yaml). This was fixed in this PR ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent 67a637b commit f098b98

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Sources/App/Settings/ActionConfigurator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
305305
private func saveAndAutomate() {
306306
if form.validate().count == 0 {
307307
Current.Log.verbose("Category form is valid, calling dismiss callback!")
308-
shouldSave = true
308+
if !action.isServerControlled {
309+
shouldSave = true
310+
}
309311
shouldOpenAutomationEditor = true
310312
onDismissCallback?(self)
311313
}

Sources/App/Settings/SettingsDetailViewController.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,17 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
716716
_ = vc.navigationController?.popViewController(animated: true)
717717

718718
if let vc = vc as? ActionConfigurator {
719+
defer {
720+
if vc.shouldOpenAutomationEditor {
721+
vc.navigationController?.dismiss(animated: true, completion: {
722+
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise)
723+
.done { controller in
724+
controller.openActionAutomationEditor(actionId: vc.action.ID)
725+
}
726+
})
727+
}
728+
}
729+
719730
if vc.shouldSave == false {
720731
Current.Log.verbose("Not saving action to DB and returning early!")
721732
return
@@ -734,15 +745,6 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
734745
}.done {
735746
self?.updatePositions()
736747
}.cauterize()
737-
738-
if vc.shouldOpenAutomationEditor {
739-
vc.navigationController?.dismiss(animated: true, completion: {
740-
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise)
741-
.done { controller in
742-
controller.openActionAutomationEditor(actionId: vc.action.ID)
743-
}
744-
})
745-
}
746748
}
747749
})
748750
}

0 commit comments

Comments
 (0)