Skip to content

Commit

Permalink
Fix Daylight Sensor Model
Browse files Browse the repository at this point in the history
  • Loading branch information
Spriter committed Jul 1, 2016
1 parent 38590f4 commit 5d15d40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5d15d40

Please sign in to comment.