Skip to content

Commit

Permalink
Add lat and long location inputs. Some config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
schneiderderek committed Jul 11, 2015
1 parent 67dd4fe commit 3fd3bad
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.13.0
* Add support for latitude and longitude location inputs
* Change how unit selection is handled
* Change how location method is handled

## 0.12.0
* Add support for metric units

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ The following configuration options are available, shown in the order they appea

| Name | Description | Default |
| ------------- | ------------- | ----------- |
| Metric | Use metric units | off |
| Show High | High temp for the day | on |
| Show Humidity | Current humidity | on |
| Latitude | Latitude (ignored if zipcode location method choosen) | 0 |
| Location Method | Whether to use zipcode or lat/long | zipcode |
| Longitude | Longitude (ignored if zipcode location method choosen) | 0 |
| Show High | High temp for the day | on |
| Show Humidity | Current humidity | on |
| Show Icon | icon associated with current weather | on |
| Show Low | Low temp for the day | on |
| Show Pressure | Current atmospheric pressure | on |
Expand All @@ -27,8 +29,9 @@ The following configuration options are available, shown in the order they appea
| Show Temp | Current temp | on |
| Show Wind Direction | Current wind direction | on |
| Show Wind Speed | Current wind speed | on |
| Units | Unit measurement | imperial |
| Update Interval | Number of minutes between updates | 15 min. |
| Zipcode | Location zipcode | 43201 |
| Zipcode | Location zipcode (ignored if lat/long location method choosen) | 43201 |

## Menu Options
To access the menu options click on the `Packages` option in the menubar, then `Weather`. There are currently two different options available in the package menu.
Expand Down
21 changes: 17 additions & 4 deletions lib/weather-data.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,31 @@ class WeatherData
atom.config.get('weather.zipcode')

units: ->
units = 'imperial'
units = 'metric' if atom.config.get 'weather.metric'
units
atom.config.get 'weather.units'

updateInterval: ->
atom.config.get('weather.updateInterval') * 60 * 1000

apiZipcodeFormat: ->
"#{@zipcode()},us"

locationMethod: ->
atom.config.get 'weather.locationMethod'

longitude: ->
atom.config.get('weather.longitude')

latitude: ->
atom.config.get('weather.latitude')

currentWeatherUrl: ->
"http://api.openweathermap.org/data/2.5/weather?zip=#{@apiZipcodeFormat()}&units=#{@units()}"

if @locationMethod() == 'zipcode'
location = "zip=#{@apiZipcodeFormat()}"
else
location = "lon=#{@longitude()}&lat=#{@latitude()}"

"http://api.openweathermap.org/data/2.5/weather?units=#{@units()}&#{location}"

forecastWeatherUrl: ->
lat = @location.lat
Expand Down
6 changes: 3 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',
'units', 'showIcon', 'showHumidity', 'showHigh', 'showLow', 'showTemp',
'showSunrise', 'showSunset', 'showHumidity', 'showPressure', 'showWindSpeed',
'showWindDirection', 'metric']
'showWindDirection']
configResponseMappings:
showTemp:
unit:
Expand Down Expand Up @@ -56,7 +56,7 @@ class WeatherView extends HTMLElement
for optionName in @configRerenderTriggers
atom.config.onDidChange "weather.#{optionName}", @showWeather.bind(@)

atom.config.onDidChange 'weather.metric', @refresh.bind(@)
atom.config.onDidChange "weather.locationMethod", @refresh.bind(@)

isVisible: ->
@classList.contains('hidden')
Expand Down
17 changes: 14 additions & 3 deletions lib/weather.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ module.exports = Weather =
showWindDirection:
type: 'boolean'
default: true
metric:
type: 'boolean'
default: false
units:
type: 'string'
default: 'imperial'
enum: ['imperial', 'metric']
locationMethod:
type: 'string'
default: 'zipcode'
enum: ['zipcode', 'latitude and longitude']
latitude:
type: 'number'
default: 0.0
longitude:
type: 'number'
default: 0.0

consumeStatusBar: (statusBar) ->
@statusBarTile = statusBar.addRightTile(item: @weatherView, priority: 100)
Expand Down

0 comments on commit 3fd3bad

Please sign in to comment.