Skip to content

Commit

Permalink
Add wind speed and direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Schneider committed Jun 25, 2015
1 parent c04a951 commit 7495780
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.11.0
* Add wind speed
* Add wind direction

## 0.10.1
* Better handling for bad API responses

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ By default weather will show the sunset time. To change this, check/uncheck the
### Show Temp
By default weather will show the current temperature. To change this, check/uncheck the option.

### Show Wind Direction
By default weather will show the current wind direction. To change this, check/uncheck the option.

### Show Wind Speed
By default weather will show the current wind speed. To change this, check/uncheck the option.

### Update Interval
By default weather will update the weather every 15 minutes. To change this, just enter the number of minutes you want weather to wait before updating.

Expand Down
4 changes: 4 additions & 0 deletions lib/weather-data.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
WindDirection = require './wind-direction'

module.exports =
class WeatherData
apiCallTypes:
Expand Down Expand Up @@ -52,6 +54,8 @@ class WeatherData
@sunrise = @formatTime @parseUnixTimestamp(data.sys.sunrise)
@sunset = @formatTime @parseUnixTimestamp(data.sys.sunset)
@pressure = Math.round(data.main.pressure)
@windSpeed = Math.round(data.wind.speed)
@windDirection = (new WindDirection(data.wind.deg)).cardinal

@weatherApiCall @apiCallTypes.forecast

Expand Down
11 changes: 8 additions & 3 deletions lib/weather-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ WeatherData = require './weather-data'

class WeatherView extends HTMLElement
configRerenderTriggers: [
'zipcode', 'showIcon', 'showHumidity', 'showHigh',
'showLow', 'showTemp', 'showSunrise', 'showSunset',
'showHumidity', 'showPressure']
'zipcode', 'showIcon', 'showHumidity', 'showHigh', 'showLow', 'showTemp',
'showSunrise', 'showSunset', 'showHumidity', 'showPressure', 'showWindSpeed',
'showWindDirection']
configResponseMappings:
showTemp:
suffix: 'F'
Expand All @@ -27,6 +27,11 @@ class WeatherView extends HTMLElement
showPressure:
suffix: 'hPa'
dataAttribute: 'pressure'
showWindSpeed:
dataAttribute: 'windSpeed'
suffix: 'MPH'
showWindDirection:
dataAttribute: 'windDirection'
data: null
initialize: ->
@classList.add('weather', 'inline-block')
Expand Down
7 changes: 6 additions & 1 deletion lib/weather.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ module.exports = Weather =
showPressure:
type: 'boolean'
default: true

showWindSpeed:
type: 'boolean'
default: true
showWindDirection:
type: 'boolean'
default: true
consumeStatusBar: (statusBar) ->
@statusBarTile = statusBar.addRightTile(item: @weatherView, priority: 100)

Expand Down
61 changes: 61 additions & 0 deletions lib/wind-direction.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports =
class WindDirection
cardinal: null
degrees: null
directionMappings:
N:
min: 0.00
max: 11.25
NNE:
min: 11.25
max: 33.75
NE:
min: 33.75
max: 56.25
ENE:
min: 56.25
max: 78.75
E:
min: 78.75
max: 101.25
ESE:
min: 101.25
max: 123.75
SE:
min: 123.75
max: 146.25
SSE:
min: 146.25
max: 168.75
S:
min: 168.75
max: 191.25
SSW:
min: 191.25
max: 213.75
SW:
min: 213.75
max: 236.25
WSW:
min: 236.25
max: 258.75
W:
min: 258.75
max: 281.25
WNW:
min: 281.25
max: 303.75
NW:
min: 303.75
max: 326.25
NNW:
min: 326.25
max: 348.75
N:
min: 348.75
max: 360.00
constructor: (degrees) ->
for direction, bounds of @directionMappings
if degrees >= bounds.min && degrees < bounds.max
@cardinal = direction
break

0 comments on commit 7495780

Please sign in to comment.