From 5d15d40e0b261f96b7fb826ced7fc3e3ef84e692 Mon Sep 17 00:00:00 2001 From: Marcel Dittmann Date: Fri, 1 Jul 2016 16:45:36 +0200 Subject: [PATCH] Fix Daylight Sensor Model --- .../DaylightSensor/DaylightSensorConfig.swift | 30 +++++-------------- .../DaylightSensor/DaylightSensorState.swift | 8 ++--- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorConfig.swift b/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorConfig.swift index 59ea660..a0c6256 100644 --- a/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorConfig.swift +++ b/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorConfig.swift @@ -13,8 +13,8 @@ public class DaylightSensorConfig: PartialSensorConfig { public let long: String public let lat: String - public let sunriseOffset: Int8 - public let sunsetOffset: Int8 + public let sunriseOffset: Int8? + public let sunsetOffset: Int8? init?(sensorConfig: SensorConfig) { @@ -26,18 +26,10 @@ public class DaylightSensorConfig: PartialSensorConfig { Log.error("Can't create DaylightSensorConfig, missing required attribute \"lat\""); return nil } - guard let sunriseOffset: Int8 = sensorConfig.sunriseOffset else { - Log.error("Can't create DaylightSensorConfig, missing required attribute \"sunriseoffset\""); return nil - } - - guard let sunsetOffset: Int8 = sensorConfig.sunsetOffset else { - Log.error("Can't create DaylightSensorConfig, missing required attribute \"sunsetoffset\""); return nil - } - self.long = long self.lat = lat - self.sunriseOffset = sunriseOffset - self.sunsetOffset = sunsetOffset + self.sunriseOffset = sensorConfig.sunriseOffset + self.sunsetOffset = sensorConfig.sunsetOffset super.init(on: sensorConfig.on, reachable: sensorConfig.reachable, battery: sensorConfig.battery, url: sensorConfig.url) } @@ -51,19 +43,11 @@ public class DaylightSensorConfig: PartialSensorConfig { guard let lat: String = "lat" <~~ json else { Log.error("Can't create DaylightSensorConfig, missing required attribute \"lat\" in JSON:\n \(json)"); return nil } - - guard let sunriseOffset: Int8 = "sunriseoffset" <~~ json else { - Log.error("Can't create DaylightSensorConfig, missing required attribute \"sunriseoffset\" in JSON:\n \(json)"); return nil - } - - guard let sunsetOffset: Int8 = "sunsetoffset" <~~ json else { - Log.error("Can't create DaylightSensorConfig, missing required attribute \"sunsetoffset\" in JSON:\n \(json)"); return nil - } - + self.long = long self.lat = lat - self.sunriseOffset = sunriseOffset - self.sunsetOffset = sunsetOffset + self.sunriseOffset = "sunriseoffset" <~~ json + self.sunsetOffset = "sunsetoffset" <~~ json super.init(json: json) } diff --git a/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorState.swift b/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorState.swift index f6b8e0d..8bc32a9 100644 --- a/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorState.swift +++ b/Sources/Base/BridgeResourceModels/Sensors/DaylightSensor/DaylightSensorState.swift @@ -11,15 +11,11 @@ import Gloss public class DaylightSensorState: PartialSensorState { - public let daylight: Bool + public let daylight: Bool? init?(state: SensorState) { - guard let daylight: Bool = state.daylight else { - Log.error("Can't create DaylightSensorState, missing required attribute \"daylight\""); return nil - } - - self.daylight = daylight + self.daylight = state.daylight super.init(lastUpdated: state.lastUpdated) }