Skip to content

Commit

Permalink
Prevent crash on creating automation from a server controlled iOS Act…
Browse files Browse the repository at this point in the history
…ion (#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. -->
  • Loading branch information
bgoncal authored Feb 22, 2024
1 parent 67a637b commit f098b98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Sources/App/Settings/ActionConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
private func saveAndAutomate() {
if form.validate().count == 0 {
Current.Log.verbose("Category form is valid, calling dismiss callback!")
shouldSave = true
if !action.isServerControlled {
shouldSave = true
}
shouldOpenAutomationEditor = true
onDismissCallback?(self)
}
Expand Down
20 changes: 11 additions & 9 deletions Sources/App/Settings/SettingsDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,17 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
_ = vc.navigationController?.popViewController(animated: true)

if let vc = vc as? ActionConfigurator {
defer {
if vc.shouldOpenAutomationEditor {
vc.navigationController?.dismiss(animated: true, completion: {
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise)
.done { controller in
controller.openActionAutomationEditor(actionId: vc.action.ID)
}
})
}
}

if vc.shouldSave == false {
Current.Log.verbose("Not saving action to DB and returning early!")
return
Expand All @@ -734,15 +745,6 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
}.done {
self?.updatePositions()
}.cauterize()

if vc.shouldOpenAutomationEditor {
vc.navigationController?.dismiss(animated: true, completion: {
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise)
.done { controller in
controller.openActionAutomationEditor(actionId: vc.action.ID)
}
})
}
}
})
}
Expand Down

0 comments on commit f098b98

Please sign in to comment.