Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle scenes/actions for watchOS App all at once #2437

Merged
merged 7 commits into from
Nov 8, 2023

Conversation

bgoncal
Copy link
Member

@bgoncal bgoncal commented Nov 1, 2023

Summary

When you open your watchOS App for the first time you may encounter several scenes already active to be used in the watch App (specially if you have Philips Hue in HA), this change allows you to unselect all scenes at once (hide from watch app) if you want.

Screenshots

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-11-01.at.13.56.46.mp4

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

@bgoncal bgoncal requested a review from zacwest November 1, 2023 13:01
@bgoncal bgoncal self-assigned this Nov 1, 2023
@bgoncal bgoncal changed the title Toggle actions Toggle scenes/actions for watchOS App all at once Nov 1, 2023
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #2437 (aeba728) into master (28dc963) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2437      +/-   ##
==========================================
- Coverage   28.07%   28.03%   -0.05%     
==========================================
  Files         273      273              
  Lines       30209    30232      +23     
==========================================
- Hits         8481     8475       -6     
- Misses      21728    21757      +29     
Files Coverage Δ
...es/App/Settings/SettingsDetailViewController.swift 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

@zacwest
Copy link
Member

zacwest commented Nov 1, 2023

The real crux of the issue is the startup routine for HA causes the entire scene domain to have nothing in it, which makes the app remove all its local copies. Once it later populates the scenes, it recreates them and loses the disabled state. A good fix for this probably would involve not listening to state changes until core finishes loading all the way.

I think some integrations may also work by deleting all then restoring them, so moving enabled state out of Realm might also be required.

Copy link
Member

@zacwest zacwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good problem to tackle

Sources/App/Settings/SettingsDetailViewController.swift Outdated Show resolved Hide resolved
Sources/App/Settings/SettingsDetailViewController.swift Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft November 1, 2023 14:17
@home-assistant
Copy link

home-assistant bot commented Nov 1, 2023

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@bgoncal
Copy link
Member Author

bgoncal commented Nov 2, 2023

The real crux of the issue is the startup routine for HA causes the entire scene domain to have nothing in it, which makes the app remove all its local copies. Once it later populates the scenes, it recreates them and loses the disabled state. A good fix for this probably would involve not listening to state changes until core finishes loading all the way.

I think some integrations may also work by deleting all then restoring them, so moving enabled state out of Realm might also be required.

Indeed some clean up needs to be done in the startup flow, I'll put it on my to-do list to look into it since it may require more time for me that's not familiar with it yet.
For now, I believe this "Select all" toggle is a quick win anyway, what do you think?

@bgoncal bgoncal marked this pull request as ready for review November 2, 2023 08:25
@home-assistant home-assistant bot requested a review from zacwest November 2, 2023 08:25
@@ -454,7 +453,26 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
$0.disabled = true
},
], getter: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need a [weak self] here too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore after my last commit.

@@ -454,7 +453,26 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType
$0.disabled = true
},
], getter: {
Self.getSceneRows($0)
var baseRows: [BaseRow] = []
if $0 == scenes.first {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be better to put a new section at the top for this, or a new RealmSection watching it. this is sort of side-effect-y -- this 'value' needs to update live with contents other than the first one coming in/out, too, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, I forgot to reflect the state on manually changing the scene toggles. It's done now in my latest commit.

Copy link
Member Author

@bgoncal bgoncal Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulator Screen Recording - iPhone 15 Pro - 2023-11-06 at 09 38 51

@home-assistant home-assistant bot marked this pull request as draft November 2, 2023 19:23
@bgoncal bgoncal marked this pull request as ready for review November 6, 2023 08:42
@home-assistant home-assistant bot requested a review from zacwest November 6, 2023 08:42
Copy link
Member

@zacwest zacwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this path doesn't lead anywhere, this version is fine, but i suspect you can change the Eureka model instead

toggleAllSwitch.title = L10n.SettingsDetails.Actions.Scenes.selectAll

scenesUpdateObserver = scenes.observe { _ in
// Access UISwitch directly to set state to avoid triggering "on value change"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you change the model instead, and that triggers a cell update?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any changes on scenes model should result in this block of code being executed and updating the "select all" toggle state, is this what you mean or did I misunderstand?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't put this in one of the model update blocks. Create the model, set up this observer to edit the model, and set the callbacks on the model for when the user toggles it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Select all" should be part of the model, it's just a visual representation that reacts according to the group of scenes state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR based on our talk in discord, also I moved the cell a little bit:
Simulator Screenshot - iPhone 15 Pro - 2023-11-07 at 16 49 07

@bgoncal bgoncal enabled auto-merge (squash) November 8, 2023 08:46
@bgoncal bgoncal merged commit 1df0738 into home-assistant:master Nov 8, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants