This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ContentView.swift | |
| // Injected | |
| // | |
| // Created by Jason Meulenhoff on 22/05/2020. | |
| // Copyright © 2020 Jason Meulenhoff. All rights reserved. | |
| // | |
| import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct SensorsViewPage: View { | |
| var name = "Motion Sensors" | |
| @EnvironmentObject var viewModel: HomeKitViewModel | |
| var body: some View { | |
| GeometryReader() { reader in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import SwiftUI | |
| struct EitherBackground<L: View, R: View>: ViewModifier { | |
| var left: L | |
| var right: R | |
| var leftCondition: Bool | |
| init(left: L, right: R, leftCondition: Bool) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import SwiftUI | |
| struct EitherBackground<L: View, R: View>: ViewModifier { | |
| var left: L | |
| var right: R | |
| var leftCondition: Bool | |
| init(left: L, right: R, leftCondition: Bool) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import SwiftUI | |
| struct SensorView: View { | |
| @ObservedObject var motionSensor: MotionSensor | |
| var body: some View { | |
| VStack(alignment: .trailing) { | |
| VStack { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Combine | |
| import HomeKit | |
| class MotionSensor: NSObject, HomeKitAccessory { | |
| private enum Identifiers: String { | |
| case presence = "00000022-0000-1000-8000-0026BB765291" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol HomeKitAccessory: ObservableObject { | |
| var accessory: HMAccessory { get } | |
| } | |
| extension HomeKitAccessory { | |
| /** | |
| Finds a value based on a identifier | |
| */ | |
| func findValue<T>(key: String) -> Resource<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Combine | |
| import HomeKit | |
| import SwiftUI | |
| class HomeKitViewModel: NSObject, ObservableObject { | |
| // Uniquely identify HomeKit Accessories based on description | |
| enum HomeKitDevice: String { | |
| case nestThermostat = "Nest Thermostat" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct TemperatureDial: View { | |
| @State private var value: CGFloat = 0 | |
| private let initialTemperature: CGFloat | |
| private let scale: CGFloat = 275 | |
| private let indicatorLength: CGFloat = 25 | |
| private let maxTemperature: CGFloat = 32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .gesture( | |
| DragGesture().onChanged() { value in | |
| let x: CGFloat = min(max(value.location.x, 0), self.innerScale) | |
| let y: CGFloat = min(max(value.location.y, 0), self.innerScale) | |
| let ending = CGPoint(x: x, y: y) | |
| let start = CGPoint(x: (self.innerScale) / 2, y: (self.innerScale) / 2) | |
| let angle = self.angle(between: start, ending: ending) |