-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AWSensor support for Measurement<Unit>
- Loading branch information
Showing
12 changed files
with
343 additions
and
294 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// AWSensor.swift | ||
// | ||
// | ||
// Created by Mike Manzo on 5/30/20. | ||
// | ||
|
||
import Foundation | ||
|
||
open class AWSensor: SWKSensor { | ||
/// | ||
/// Provides a simple way to "see" what ths device is reporting | ||
/// | ||
override var prettyString: String { | ||
return String("\(_name): \(_value)") | ||
} | ||
|
||
/// | ||
/// A compact way to progamatically represent an AmbientWeather Sensor as defined in the API docs | ||
/// - Parameters: | ||
/// - _value: We are taking advantage of the fact that some of the AW sensors can have units that are convertible. Those that are fixed - are fixed. | ||
/// | ||
required public init (type: SWKSensorType, name: String, sensorID: String, measurement: Any, unit: String, desc: String) { | ||
super.init(type: type, name: name, sensorID: sensorID, measurement: measurement, unit: unit, desc: desc) | ||
|
||
switch type { | ||
case .Pressure: | ||
_value = Measurement(value: Double(measurement as! Float), unit: UnitPressure.inchesOfMercury) | ||
case .Temperature: | ||
_value = Measurement(value: Double(measurement as! Float), unit: UnitTemperature.fahrenheit) | ||
case .AirQuality: | ||
_value = Measurement(value: Double(measurement as! Float), unit: Unit(symbol: "µg/m^3")) | ||
case .WindSpeed: | ||
_value = Measurement(value: Double(measurement as! Float), unit: UnitSpeed.milesPerHour) | ||
case .RainRate: | ||
_value = Measurement(value: Double(measurement as! Float) , unit: Unit(symbol: "in/hr")) | ||
case .Rain: | ||
_value = Measurement(value: Double(measurement as! Float) , unit: UnitLength.inches) | ||
case .Humidity: | ||
_value = Measurement(value: Double(measurement as! Int), unit: Unit(symbol: "%")) | ||
case .WindDirection: | ||
_value = Measurement(value: Double(measurement as! Int), unit: UnitAngle.degrees) | ||
case .Radiation, .Battery, .RainDate, .General: // Unit-less | ||
break | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.