Skip to content

Instantly share code, notes, and snippets.

View Plnda's full-sized avatar

Jason Meulenhoff Plnda

View GitHub Profile
//
// ContentView.swift
// Injected
//
// Created by Jason Meulenhoff on 22/05/2020.
// Copyright © 2020 Jason Meulenhoff. All rights reserved.
//
import UIKit
import SwiftUI
struct SensorsViewPage: View {
var name = "Motion Sensors"
@EnvironmentObject var viewModel: HomeKitViewModel
var body: some View {
GeometryReader() { reader in
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) {
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) {
import Foundation
import SwiftUI
struct SensorView: View {
@ObservedObject var motionSensor: MotionSensor
var body: some View {
VStack(alignment: .trailing) {
VStack {
import Foundation
import Combine
import HomeKit
class MotionSensor: NSObject, HomeKitAccessory {
private enum Identifiers: String {
case presence = "00000022-0000-1000-8000-0026BB765291"
}
protocol HomeKitAccessory: ObservableObject {
var accessory: HMAccessory { get }
}
extension HomeKitAccessory {
/**
Finds a value based on a identifier
*/
func findValue<T>(key: String) -> Resource<T> {
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"
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
.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)