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

Add several display sensors around various screen states #4634

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dshokouhi
Copy link
Member

@dshokouhi dshokouhi commented Sep 13, 2024

Summary

Fixes: #2440 by adding 3 different sensors to capture the various states.

  • Orientation sensor - Displays orientation typically portrait vs landscape
  • Rotation sensor - Displays device rotation degree angle based on the natural orientation (i.e. a phone will be portrait 0 while a tablet will be landscape 0)
  • Is face down or up - sensor if screen is facing down at the ground, up at the air or unknown

3 different sensors because the states can all be independent of each other.

Originally I tried to be fancy with reverse portrait states however I realized the angles are dependent on the device in question and theres too much for account for when you consider all the different types of screens like on a watch, car etc...

The intent that is added only fires while the screen is on and if the screen has to redraw teh UI so battery impact is very minimal here. The face down sensor behaves just like the other hardware sensors, only getting data for a second to determine if the screen is facing the ground or not. The sensor provides raw accelerometer data to potentially add more states

Screenshots

image

Link to pull request in Documentation repository

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

Any other notes

Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

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

Haven't tested this yet, but how do the values hold up over time when they are updated in the background?

Is it a good idea to ask the users of the original request to test whether it solves their issue?

@dshokouhi
Copy link
Member Author

Placing in draft while working out some more specifics in the PR, this also needs testing on other devices as mentioned and also by end users who requested the sensor(s)

@dshokouhi dshokouhi marked this pull request as draft September 13, 2024 17:51
@dshokouhi
Copy link
Member Author

Haven't tested this yet, but how do the values hold up over time when they are updated in the background?

in my extensive testing they work well but like other sensors require the app to run in the background to get timely updates

this still needs testing especially from a foldable device

@dshokouhi
Copy link
Member Author

Testing on a foldable works as expected! All states update as we expect. Marking as ready for review, have not heard back from end user but I dont think it should hold this up.

@dshokouhi dshokouhi marked this pull request as ready for review September 16, 2024 17:15
Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

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

Positively surprised by how well the face down sensor is working (even if it did get stuck once)!

}

val icon = when (orientation) {
"portrait" -> "mdi:phone-rotate-portrait"
Copy link
Member

Choose a reason for hiding this comment

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

This is the icon to rotate from landscape to portrait, not sure about the fit 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yes the icons were not easy to pick, originally I had crop-portrait but this looked more fun lol

Copy link
Member

Choose a reason for hiding this comment

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

When quickly looking at it the icons seem identical but I recognize how hard it is. I was thinking about tablet for landscape, cellphone for portrait for a while but the screen aspect ratios don't match unfortunately.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea this one wasnt easy based on the current available options lol

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe this could be good to leave as is in case another contributor has a better idea? Picking icons and naming things are usually the most thought driven part of PRs like this :)

@dshokouhi
Copy link
Member Author

added possible states to rotation sensor based on user feedback to help make it more clear

@dshokouhi
Copy link
Member Author

I have updated the face down sensor logic ad name, I am honestly not sure what to name or even if it should belong under the display sensors. I originally had it under display sensors because the state is relative to the screen. I am not sure if "position" is an appropriate sensor name but I do see value in having various states like up or down to determine the display position. I opted to add attributes as well in case we find additional states to use. In that case the current name makes no sense. I am also ok with removing for now but the coolness factor of the data is holding me back 🤓

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.

Add Orientation Sensor support
2 participants