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 Apple Watch battery sensor #2897

Merged
merged 4 commits into from
Aug 2, 2024
Merged

Add Apple Watch battery sensor #2897

merged 4 commits into from
Aug 2, 2024

Conversation

bgoncal
Copy link
Member

@bgoncal bgoncal commented Aug 1, 2024

Summary

Screenshots

Link to pull request in Documentation repository

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

Any other notes

@bgoncal bgoncal added sensor watch The Apple Watch app and complications labels Aug 1, 2024
@bgoncal bgoncal requested a review from a team August 1, 2024 14:21
@bgoncal bgoncal self-assigned this Aug 1, 2024
Copy link

emerge-tools bot commented Aug 2, 2024

📸 Snapshot Test

No snapshots generated

Name Version Added Removed Modified Unchanged Errored Approval
Home Assistant
io.robbie.HomeAssistant
2024.8 (2024.3643) 0 0 0 0 0 N/A

🛸 Powered by Emerge Tools

@bgoncal bgoncal merged commit 4fa6de6 into master Aug 2, 2024
5 checks passed
@bgoncal bgoncal deleted the watch-battery-sensor branch August 2, 2024 09:32
@TomBrien
Copy link
Member

TomBrien commented Aug 3, 2024

This seems to be rounding to nearest 5 %. Is that expected?

@bgoncal
Copy link
Member Author

bgoncal commented Aug 3, 2024

This seems to be rounding to nearest 5 %. Is that expected?

It looks like the API returns changes every 5% change indeed.
(Unless I rounded it somehow and didn't notice, but that's the values that the API were outputting for me while debugging too)

@bgoncal
Copy link
Member Author

bgoncal commented Aug 4, 2024

@TomBrien I just noticed that iPhone battery behaves the same

@TomBrien
Copy link
Member

TomBrien commented Aug 4, 2024

Oh so it does. Never noticed that...

bgoncal added a commit that referenced this pull request Aug 28, 2024
<!-- 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 -->

Following the thread at
#1764 (reply in thread)
, this is my novice attempt at adding
https://developer.apple.com/documentation/watchkit/wkinterfacedevicebatterystate
or the Watch Battery State, using #2897 as a reference.

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

I don't know how to take a screenshot of the sensor reporting through
the simulator, I can add them if pointed in the right direction.

## 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# 

> _I will look into this. I will look for the corresponding watch
battery change docs if they exist and extend them._

## 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. -->

This is a rough pass. I used #2897 as a launching point - I read it
carefully as this is my first ever code contribution for Swift / iOS,
WatchOS project but I think I had enough heuristics to manage to
_possibly_ get it in the vicinity of it being correct.

I also used `Sources/Shared/API/Webhook/Sensors/BatterySensor.swift` for
including an additional `Battery State` sensor, while exposing both
sensors similarly in name like it's another device.

I think it could still be improved by using
`Sources/Shared/API/Webhook/Sensors/BatterySensor.swift` as a reference.
I tried to change as little as possible.

I wasn't sure if I needed to add anything to
`Sources/App/WatchCommunicatorService.swift`, considering the commit in
#2897,
f961d68#diff-daa127042af3bc5719e4eb4e02e3c50bfcef50084f554e53475f4a4238fdd096


- I will lean heavily on comments and will iterate where requested, if
the changes aren't edited directly by the maintainers. @bgoncal
- I **do** think I ran the Unit Tests correctly and added to the one
that was also changed in #2897

---------

Co-authored-by: Bruno Pantaleão Gonçalves <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed sensor watch The Apple Watch app and complications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants