diff --git a/Accessory Delegates/ PLCClassAccessoryDelegates/SmartSprinkler.swift b/Accessory Delegates/ PLCClassAccessoryDelegates/SmartSprinkler.swift index a5d3fed9..735be808 100644 --- a/Accessory Delegates/ PLCClassAccessoryDelegates/SmartSprinkler.swift +++ b/Accessory Delegates/ PLCClassAccessoryDelegates/SmartSprinkler.swift @@ -12,13 +12,14 @@ import SoftPLC import ModbusDriver import IOTypes import JVSwift +import JVSwiftCore import WeatherKit import JVWeather import CoreLocation import OSLog // MARK: - PLC level class -class SmartSprinkler:PLCClassAccessoryDelegate{ +class SmartSprinkler:PLCClassAccessoryDelegate, Loggable{ // MARK: - Accessory binding typealias AccessorySubclass = Accessory.SmartSprinkler @@ -32,8 +33,7 @@ class SmartSprinkler:PLCClassAccessoryDelegate{ private let weatherReporter = WeatherReporter() private var needsIrrigation:Bool{ - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "Smartsprinkler") - logger.warning( "Drystate \(self.weatherReporter.wasDry)/\(self.weatherReporter.isDry)/\(self.weatherReporter.willBeDry)/\(self.weatherReporter.isWindy)") + SmartSprinkler.logger.warning( "Drystate \(self.weatherReporter.wasDry)/\(self.weatherReporter.isDry)/\(self.weatherReporter.willBeDry)/\(self.weatherReporter.isWindy)") return (weatherReporter.wasDry && weatherReporter.isDry && weatherReporter.willBeDry && !weatherReporter.isWindy) } diff --git a/Accessory Delegates/AccessoryDelegate.swift b/Accessory Delegates/AccessoryDelegate.swift index f71bdac7..5f72a867 100644 --- a/Accessory Delegates/AccessoryDelegate.swift +++ b/Accessory Delegates/AccessoryDelegate.swift @@ -9,6 +9,7 @@ import Foundation import HAP import JVSwift +import JVSwiftCore import SoftPLC import OSLog @@ -18,7 +19,7 @@ import OSLog /// An object (typically some hardware driver) capable of /// receiving events from a HomeKit-Accessory and /// process them accordingly. -public protocol AccessoryDelegate: HAP.AccessoryDelegate{ +public protocol AccessoryDelegate: HAP.AccessoryDelegate, Loggable{ var name:String{get} @@ -37,8 +38,7 @@ extension AccessoryDelegate{ ofAccessory accessory: HAP.Accessory, didChangeValue newValue: T?){ - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "AccessoryDelegate") - logger.info("✴️\tValue '\(characteristic.description ?? "", privacy: .public)' of '\(accessory.info.name.value ?? "", privacy: .public)/\(service.label ?? "", privacy: .public)' changed to \(String(describing:newValue), privacy: .public)") + Self.logger.info("✴️\tValue '\(characteristic.description ?? "", privacy: .public)' of '\(accessory.info.name.value ?? "", privacy: .public)/\(service.label ?? "", privacy: .public)' changed to \(String(describing:newValue), privacy: .public)") characteristicChanged.set() diff --git a/Accessory Delegates/LeafAccessoryDelegate.swift b/Accessory Delegates/LeafAccessoryDelegate.swift index d06ee570..ef237ef5 100644 --- a/Accessory Delegates/LeafAccessoryDelegate.swift +++ b/Accessory Delegates/LeafAccessoryDelegate.swift @@ -9,11 +9,11 @@ import Foundation import HAP import LeafDriver +import JVSwiftCore import OSLog import JVNetworking class LeafAccessoryDelegate:LeafDriver, AccessoryDelegate, AccessorySource{ - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "LeafAccessoryDelegate") var name: String{ return String(localized:"Electric Car") @@ -68,7 +68,7 @@ class LeafAccessoryDelegate:LeafDriver, AccessoryDelegate, AccessorySource{ startCharging = characteristic.value as! Bool default: - logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") + LeafAccessoryDelegate.logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") } case accessory.aircoService: @@ -79,11 +79,11 @@ class LeafAccessoryDelegate:LeafDriver, AccessoryDelegate, AccessorySource{ setAirco = characteristic.value as! Bool default: - logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") + LeafAccessoryDelegate.logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") } default: - logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") + LeafAccessoryDelegate.logger.warning( "Unhandled characteristic change for accessory \(accessory.info.name.value ?? "")") } diff --git a/Accessory Delegates/MilightAccessoryDelegate.swift b/Accessory Delegates/MilightAccessoryDelegate.swift index 197a4bff..238be2fa 100644 --- a/Accessory Delegates/MilightAccessoryDelegate.swift +++ b/Accessory Delegates/MilightAccessoryDelegate.swift @@ -9,6 +9,7 @@ import Foundation import HAP import JVSwift +import JVSwiftCore import MilightDriver import OSLog @@ -55,8 +56,7 @@ class MilightAccessoryDelegate:MilightDriverV6, AccessoryDelegate{ if inWhiteMode != oldValue{ let currentBrightness = brightness if inWhiteMode{ - let logger = Logger(subsystem: "be.oneclick.MilightDriver", category: "MilightDriverV6") - logger.info("Switching to dedicated whitemode") + MilightAccessoryDelegate.logger.info("Switching to dedicated whitemode") hue = 0 saturation = 0 @@ -94,8 +94,7 @@ class MilightAccessoryDelegate:MilightDriverV6, AccessoryDelegate{ saturation = Int(characteristic.value as! Float) default: - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "MilightAccessoryDelegate") - logger.warning("Unhandled characteristic change for accessory \(self.name)") + MilightAccessoryDelegate.logger.warning("Unhandled characteristic change for accessory \(self.name)") } } diff --git a/Accessory Delegates/TizenAccessoryDelegate.swift b/Accessory Delegates/TizenAccessoryDelegate.swift index 675ec322..9ef9508d 100644 --- a/Accessory Delegates/TizenAccessoryDelegate.swift +++ b/Accessory Delegates/TizenAccessoryDelegate.swift @@ -8,8 +8,8 @@ import Foundation import HAP +import JVSwiftCore import TizenDriver -import OSLog class TizenAccessoryDelegate:TizenDriver, AccessoryDelegate, AccessorySource{ @@ -59,8 +59,7 @@ class TizenAccessoryDelegate:TizenDriver, AccessoryDelegate, AccessorySource{ } default: - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "TizenAccessoryDelegate") - logger.warning("Unhandled characteristic change for accessory \(self.name)") + TizenAccessoryDelegate.logger.warning("Unhandled characteristic change for accessory \(self.name)") } characteristicChanged.set() } diff --git a/HAPiNest.xcodeproj/project.xcworkspace/xcuserdata/janverrept.xcuserdatad/Bookmarks/bookmarks.plist b/HAPiNest.xcodeproj/project.xcworkspace/xcuserdata/janverrept.xcuserdatad/Bookmarks/bookmarks.plist index ee6a1598..ee7fe2e0 100644 --- a/HAPiNest.xcodeproj/project.xcworkspace/xcuserdata/janverrept.xcuserdatad/Bookmarks/bookmarks.plist +++ b/HAPiNest.xcodeproj/project.xcworkspace/xcuserdata/janverrept.xcuserdatad/Bookmarks/bookmarks.plist @@ -34,13 +34,13 @@ EndingColumnNumber 0 EndingLineNumber - 43 + 44 StartingColumnNumber 0 StartingLineNumber - 42 + 43 Timestamp - 730460898.103404 + 734182256.930252 rebasable-url diff --git a/HAPiNest/HAPiNestApp.swift b/HAPiNest/HAPiNestApp.swift index 5b51aa2d..1db4b9a5 100644 --- a/HAPiNest/HAPiNestApp.swift +++ b/HAPiNest/HAPiNestApp.swift @@ -24,7 +24,7 @@ import ModbusDriver /// by translating those changes into actions for the hardware. /// The main accessory-delegate in this App is a SoftPLC that can interact with the outside world by means of a number of Input and Output-modules. @main -struct HAPiNestApp: App { +struct HAPiNestApp: App, Loggable { @SwiftUI.Environment(\.scenePhase) var scenePhase let appcontroller:AppController = AppController(name: "HAPiNest", terminal: TerminalDriver()) diff --git a/HAPiNest/HomekitServer/HomeKitServer.swift b/HAPiNest/HomekitServer/HomeKitServer.swift index d1716161..ed124b00 100644 --- a/HAPiNest/HomekitServer/HomeKitServer.swift +++ b/HAPiNest/HomekitServer/HomeKitServer.swift @@ -16,8 +16,7 @@ import OSLog import SwiftUI import LeafDriver -public class HomeKitServer:Singleton{ - let logger = Logger(subsystem: "be.oneclick.HAPiNest", category: "HomeKitServer") +public class HomeKitServer:Singleton, Loggable{ public static var shared: HomeKitServer = HomeKitServer() public var dashboard:HomeKitServerView? public var name:String @@ -41,7 +40,7 @@ public class HomeKitServer:Singleton{ AppController(name: "Console", location: .systemUtilities, terminal: TerminalDriver()).startIfInstalled() AppController(name: "Home", location: .systemApps, terminal: TerminalDriver()).startIfInstalled() #endif - logger.info("Initializing the server \(self.name, privacy: .public)...") + HomeKitServer.logger.info("Initializing the server \(self.name, privacy: .public)...") // TODO: - reimplement SMAInverter diff --git a/HAPiNest/ServerBasedAutomations/WakeupLights.swift b/HAPiNest/ServerBasedAutomations/WakeupLights.swift index bbdcca66..b091aaad 100644 --- a/HAPiNest/ServerBasedAutomations/WakeupLights.swift +++ b/HAPiNest/ServerBasedAutomations/WakeupLights.swift @@ -22,7 +22,6 @@ class WakeupLights:PLCClass{ // use a helper class a.k.a. composition instead of inheritance. class BrightnessTimer { - // Public property for time to make a 100% change private var timer: Timer? private func adjust(brightness:inout Int?, to targetBrightness:Int?, over totalTime:TimeInterval = 5.0){ @@ -61,11 +60,11 @@ class BrightnessTimer { brightness = newBrightness }else{ - stop() + self.stop() } } - func stop() { + private func stop() { timer?.invalidate() timer = nil }