Git Product home page Git Product logo

fitbit-weather's Introduction

Weather module for Fitbit OS

This library permits to retrieve weather information from the device.
You can choose your favourite weather provider between Yahoo, OpenWeatherMap, DarkSky and WeatherUnderground Weatherbit

Installation

npm i fitbit-weather

Companion

Create an index.js file in the companion folder if you don't already have one.
Add the following code in this file :

import * as weather from 'fitbit-weather/companion'

weather.setup({ provider : weather.Providers.yahoo, apiKey : 'YOUR_KEY' })

App

Add the following code in your app/index.js file

import * as weather from 'fitbit-weather/app'

weather.fetch(30 * 60 * 1000) // return the cached value if it is less than 30 minutes old 
  .then(weather => console.log(JSON.stringify(weather)))
  .catch(error => console.log(JSON.stringify(error)))

API

  • companion.setup({ provider, apiKey}) : configure the provider / apiKey used to fetch the weather
  • app.fetch(maximumAge = 0) : retrieve the weather, if given the parameter is the maximum age in milliseconds of a possible cached weather data that is acceptable to return. Default is 0
  • app.get() : returns immediately the last cached weather data (the value can be undefined when no data has been received)

Example of result

  {
    "temperatureC":15,
    "temperatureF":59,
    "location":"Castelnau-D'Estretefonds",
    "description":"Mostly Clear",
    "isDay":false,
    "conditionCode":0,
    "realConditionCode":"this is the real conditioncode returned by the provider",
    "sunrise":1507442496594,
    "sunset":1507483356594,
    "timestamp":1507496916594
  }

Condition codes

const Conditions = {
  ClearSky        : 0,
  FewClouds       : 1,
  ScatteredClouds : 2,
  BrokenClouds    : 3,
  ShowerRain      : 4,
  Rain            : 5,
  Thunderstorm    : 6,
  Snow            : 7,
  Mist            : 8,
  Unknown         : 1000,
}

Providers codes

const Providers = {
  yahoo           : "yahoo",
  openweathermap  : "owm",
  wunderground    : "wu",
  darksky         : "darksky",
  weatherbit      : "weatherbit"
}

Contribution

I'm not a javascript expert so every comment/code reactoring/best practice is appreciated. Don't hesitate to make PR and tell me what's wrong.

fitbit-weather's People

Contributors

gregoiresage avatar liljeberg avatar ygalanter avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.