Commit Graph

23 Commits

Author SHA1 Message Date
Zac West
86b0b0a409 Allow disabling individual sensors (#1484)
Fixes #358.

## Summary
Allows toggling on or off certain sensors. This does not currently delete the sensor but instead sets its state to 'unavailable'.

## Screenshots
### App
![Image](https://user-images.githubusercontent.com/74188/107861269-bd96e800-6df9-11eb-93c4-682eab17b157.png)
![Image 2](https://user-images.githubusercontent.com/74188/107861298-d8695c80-6df9-11eb-9496-dc89cdc892c0.png)

### Frontend
<img width="334" alt="entities" src="https://user-images.githubusercontent.com/74188/107861381-5c234900-6dfa-11eb-86c5-27b7f6ea2c2e.png">

## 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
- Sensors are still only showing up in the sensor list if they have been generated during the app lifecycle. So for example the Geocode sensor doesn't show up unless a location update happened, and motion sensors do not show up if motion permission is disabled.
- Avoids removing items from the cache when they aren't around anymore, or when we think they are stale.
2021-02-13 16:55:16 -08:00
Zac West
640cca884b Add SwiftFormat to project (#1463)
Adds new fastlane lanes:
- `fastlane lint` which checks the linters
- `fastlane autocorrect` which applies the linters which can autocorrect (Rubocop, SwiftFormat)

Adds a build step to the Codegen abstract target which runs SwiftFormat in lint mode, pointing out what it's going to change when run.

Applies SwiftFormat to nearly all code -- exempts a few externally-sourced files and generated code.
2021-02-05 22:06:25 -08:00
Zac West
adf0ad6bab Fix Graphic Bezel Circular Text & Graphic Rectangular Standard Body (#1457)
Fixes #1437.

## Summary
Fixes the optionality on the text providers in these two styles.

## Any other notes
Went through all of the complication definitions, again 😆, and these were incorrect optionality. It will be nice to move these to the watchOS 7 init methods which are less…problematic.

- Bezel Circular Text has its text provider optional, we do not need to force it.
- Rectangular Standard Body has 3 text providers: header, body1 and body2. Only header and body1 are required, body2 is optional.
2021-02-04 05:35:42 +00:00
Sam Hanley
8ef38821f0 Add FriendlyName to RLMZone update. Fixes #1432. (#1435) 2021-01-27 22:31:10 -08:00
Zac West
c6167742f2 Revert PromiseKit threading change (#1431)
- Reverts #1418 - there's enough logic that is relying on the single-threadedness of then/map-ing on a shared queue.
- Forces all `Current.api` access to be done not on a queue intentionally, to avoid thread jumping when we don't expect, which is the core crash that this was trying to fix.
2021-01-26 21:11:53 -08:00
Zac West
5b75b2ea4c Move API access into Environment (#1390)
Consolidates REST API access into one entry point, ish.
2021-01-21 20:45:42 -08:00
Zac West
f1b7a691e3 Only send up the values for changed sensors when they change (#1381)
Replace #1013.

## Summary
Keeps track of what sensors we've sent up during the session and only pushes up changes.

## Screenshots
Just tabbing around between apps on Mac:

```
14:49:15.876 [Info] [main] [HAAPI.swift:824] UpdateSensors(trigger:location:) > updating sensors ["frontmost_app"]
14:49:16.561 [Info] [main] [HAAPI.swift:824] UpdateSensors(trigger:location:) > updating sensors ["frontmost_app"]
14:49:17.422 [Info] [main] [HAAPI.swift:824] UpdateSensors(trigger:location:) > updating sensors ["frontmost_app"]
14:49:30.550 [Info] [main] [HAAPI.swift:824] UpdateSensors(trigger:location:) > updating sensors ["frontmost_app"]
14:49:32.363 [Info] [main] [HAAPI.swift:824] UpdateSensors(trigger:location:) > updating sensors ["frontmost_app"]
```

## Link to pull request in Documentation repository
No user-facing changes.

## Any other notes
Unlike #1013, this does not persist the sensor values to disk. This is a place that can be improved, but there are some unanswered questions/complications with storing to disk (especially around migrations and cleaning up the values when upgrading and when hardware devices change and wrong values are shown) that could probably be solved a little cleaner in the future transparently to consumers of these types.
2021-01-17 16:32:22 -08:00
Zac West
ee02799ac6 Allow Network Hardware Address to decide "internal" on Mac (#1370)
Fixes #1353.

## Summary
This allows you to use a docked ethernet adapter as the thing to decide whether you are currently internal. This will help hardware without Wi-Fi or with Wi-Fi disabled to use the feature.

## Screenshots
<img width="400" alt="Screen Shot 2021-01-12 at 20 26 28" src="https://user-images.githubusercontent.com/74188/104407176-df106580-5515-11eb-82a0-2b5d4eb23694.png"><img width="400" alt="Screen Shot 2021-01-12 at 20 26 23" src="https://user-images.githubusercontent.com/74188/104407181-e0da2900-5515-11eb-9c2c-773c725cb841.png">

## 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
- Removes some "is this internal?" dead code during onboarding. Probably worth doing the internal/external pull in at this point.
- Pulls some of the class method things on ConnectionInfo into the connectivity wrapper in Environment.
2021-01-12 21:18:37 -08:00
Tom Brien
55d472c93e Allow hiding complications when watch is locked (#1253)
* Allow private complications

* Add string

* Add british string, tea and crumpets and what not

* Move row

* Probably want to save setting...

* No idea when this moved...

* Fix logic

* Tweak migration

Forgot to commit this earlier

* Bump schema

* Flip logic

* Add helper

* Change func name

* Use helper in template func

* Update function name

* Tidy up

Co-authored-by: Zac West <74188+zacwest@users.noreply.github.com>
2020-11-02 09:21:03 -08:00
Zac West
f5b99fe47a Remove SPM (🎉) and upgrade deps (#1242)
Words cannot describe how bad SPM is. For the future record, here are the big reasons:

- Xcode fails to find Swift Package Manager Binary Target dependency… FB8743041

This manifests as "cannot find module Clibsodium" or "Realm" or whatever.

- Xcode Swift Package Manager checkout retry has 0-second delay FB8742078

Xcode's built-in version of git/curl has bugs with pipelining, forcing us to replace it with another version to get ci to be more reliable.

- xcframework via Swift Package Manager both statically links to library and embeds it FB8721223

This requires us massaging the output build products because Xcode produces invalid binaries, which fail all the validation Apple does on App Store Connect upload and on Developer ID Notarization.

-----

In total, this means using SPM produces invalid builds, often fails to build correctly, and often fails to check out dependencies correctly. What a let-down.
2020-10-25 20:13:52 -07:00
Zac West
9107c86521 Bump minimum target to iOS 12 (#1241) 2020-10-25 18:53:39 -07:00
Zac West
6528b9e548 Avoid generating invalid templates due to non-optional fields (#1222)
This resolves a crash on watchOS 6 when a Complication Template is missing required fields (e.g. one of the text providers) and instead returns the 'error' template.

watchOS 7 wasn't exactly better as it would not crash but it wouldn't be obvious about the error happening, so this also improves that situation.

This is a half-measure to telling the user which fields are optional or not when editing the complication, but it should be a _lot_ more obvious when we do not have the information necessary to make the template.
2020-10-20 22:42:00 -07:00
Zac West
413d3a42bc Fix Complication Ring/Gauge values in locales using , as decimal separator (#1206)
In HA versions prior to 0.117, the template rendering returns strings for floats using `.` as the decimal separator. If the user's current locale uses `,` as the separator, our string to number parsing here fails to understand what the number is. Since it's freeform text, this also needs to fall back to using the locale-aware formatter in case they typed manually something like `0,33`.

Fixes #1188.
2020-10-18 09:01:17 -07:00
Zac West
b9dde39e4e Support multiple Apple Watch complications (#1197)
This allows for configuring more than 1 e.g. Modular Small at a time. This requires watchOS 7; for releases before watchOS 7 we do not allow a secondary template to be created. This could be improved by allowing swapping between one of the multiple for watchOS 6 and earlier, but I didn't implement this.

- Adds a "Display Name" to Complications. This is optional and falls back to the template type. This is primarily to differentiate complications; the underlying unique ID is just a UUID.
- Enable previews of complications, which is used when selecting them. This is a stripped-down version of the items in the template, usually just an icon provider or one of the text providers. This is largely easier now since we're now requesting templates for all complications, even those not actively visible.

This also changes the flow when setting up initially. Instead of a list of families to choose from at the start, the user must tap the 'Add' button and pick one from there.

Fixes #839.
2020-10-16 19:42:42 -07:00
Zac West
a2a9b8266b Handle non-String template rendering (#1187)
- Converts to String for the API-like things we provide for template rendering: intent handling and x-url-callback.
- Handles various kinds of results for Complication template handling: tries to smooth values to floats for percentile-based rings and gauges, describes via String for anywhere else.
- Adds a small amount of validation when entering templates in a Complication's Configuration.

Fixes #1177. Fixes #1180.
2020-10-15 21:17:51 -07:00
Zac West
d37e9f867f Fix non-English Gauge/Ring, fix Column 2 Alignment (#1186)
These styles were using the localized strings as options, which were then not equating. The way the current getters work, their failure to exist in the dictionary it would always use 'ring' for Gauge and 'closed' for Ring.

Replaces Row 2 Alignment (which had a similar issue) with Column 2 Alignment, which is what the complications want. This right-aligns the second columns.
2020-10-13 21:11:55 -07:00
Zac West
0b4d5b6ba1 Improve Watch Complication update timing (#1176)
- Moves our background refresh timing from every 5 minutes to every 15 minutes. Apple [documents this](https://developer.apple.com/documentation/clockkit/updating_your_complication) as:

> The system carefully budgets background refresh tasks. You can schedule only one refresh task at a time. If you have a complication on the active watch face, you can safely schedule four refresh tasks a hour.

- When we refresh the rendering data backing complications, we now immediately tell ClockKit to invalidate/refresh our active complications. I'm not sure what was triggering refreshes before, but they were highly irregular. With this change, I can reliably see (at the new timing above) my complications update at around :00, :15, :30, and :45 on the hour.
- Stops restricting complication rendering to only the active complication. This makes switching between watch faces have the most accurate data possible, and is a very small increase in the size of this request/response -- we're already doing a network call, and the biggest cost of a network call is doing one more than the JSON payload size (which is small).
- Reduces how often we do complication updates on the iPhone side of thing. This doesn't help as much as I had thought it did; we're restricted in how often we can push watch data updates, and since we're not (yet?) using the "update the complications" WatchConnectivity feature, we're not necessarily directly forcing an update anyway.
- Reduces minorly how often we execute syncs on startup. If there's any synced Actions or NotificationCategory, this ends up doing 2+ syncs on startup; removing this restriction does 0-1, depending on if there's any synced. It always occurs when changes are made.
2020-10-10 21:51:51 -07:00
Zac West
36fdb37249 Improve reliability of refreshing Watch Complications (#1168)
One of our top crashes (on all platforms) is crashing when completing the background refresh operation of the Watch Extension's update cycle. I believe this is because the task is being called more than once; presumably because we're mixing multiple types of tasks in one pointer -- communication updates and complication updates, and they stomp on each other.

Another issue here is that we're not using Background Sessions to do the complication updates, when we want to -- when I refactored Webhooks out of the HomeAssistantAPI code path, I neglected to update this Webhook call to handle background updating; it now does.

- Updates complication text rendering to go through the background session supporting Webhook update mechanism.
- Adds support for ring and gauge template rendering. Fixes #1127.
2020-10-10 13:38:13 -07:00
Zac West
53ecc94bf2 Fix ring and single-color-tinted Watch Complications (#1170)
- Fixes, in general, any complication involving a Ring -- none of the values were being persisted in a way it could understand and color was missing entirely.
- Fixes Extra Large's "Simple Image", "Stack Image", "Ring Text" and "Ring Image". Fixes #1165.
- Fixes Utility's Small "Square" image (the size name was wrong), "Ring Image" (same as above), "Ring Text". Fixes #1164.
2020-10-09 11:02:34 -07:00
Zac West
ceafb85346 Implement Graphic Bezel Circular Text (#1169)
Requires an icon; adds the flag that we need the icon for the template and sets the image size.
2020-10-08 23:38:08 -07:00
Zac West
45f59fb5c7 Really fix the example notification category YAML (#1153)
* Really fix the example notification category YAML

* Move indentation fully into variable
2020-10-04 18:42:10 -07:00
Zac West
c18e5755b1 Fix example for notification category dictionary-based URL (#1148)
Fixes #1146.
2020-10-04 11:23:08 -07:00
Zac West
4d9a530637 Reorganize files in repo, pull out build settings from pbxproj (#1140)
This is somewhat in prep of being able to make the project file generated, but also just organizes things into more concrete directory structures.

This pulls out _all_ of the build settings from the root level, and most from the target level, into xcconfigs.

The new directory structure looks like:

- Sources
  - App
    - (everything from HomeAssistant/)
  - WatchApp
  - Shared
  - MacBridge
  - Extensions
    - Intents
    - NotificationContent
    - NotificationService
    - Share
    - Today
    - Watch
    - Widgets
- Tests
  - App
  - UI
  - Shared

Somewhat intentionally, the file structure under these is not yet standardized/organized.

The project targets are now:

- App
- WatchApp
- Shared-iOS
- Shared-watchOS
- MacBridge
- Tests-App
- Tests-UI
- Tests-Shared
- Extension-Intents
- Extension-NotificationContent
- Extension-NotificationService
- Extension-Share
- Extension-Today
- Extension-Widget
- WatchExtension-Watch

This does not yet clean up resources vs. sources, nor does it handle some of the "it's in Sources/App but it's part of Shared" crossover directory issues.
2020-10-03 00:15:04 -07:00