Weather API
Variable: weather
Type: WeatherProvider
The Weather API provides current weather conditions for the current location only.
The access_location
permission is required.
import { me as companion } from "companion";
import weather from "weather";
if (companion.permissions.granted("access_location")) {
weather
.getWeatherData()
.then((data) => {
if (data.locations.length > 0) {
const temp = Math.floor(data.locations[0].currentWeather.temperature);
const cond = data.locations[0].currentWeather.weatherCondition;
const loc = data.locations[0].name;
const unit = data.temperatureUnit;
console.log(`It's ${temp}\u00B0 ${unit} and ${cond} in ${loc}`);
}
})
.catch((ex) => {
console.error(ex);
});
}
Interface: WeatherProvider
Methods
getWeatherData()
getWeatherData(options?: { temperatureUnit?: TemperatureUnit | undefined; } | undefined)
Returns: Promise<WeatherData>
New in SDK 5.2
Retrieve the current weather data for the current location
If the optional temperatureUnit
parameter is specified but has an invalid value,
the returned Promise will reject with a TypeError.
If the request to get the current weather fails because there's no location permission granted, the returned Promise will reject with a TypeError notyfing as such.
If for some reason, getting the current location fails (ex. no GPS signal), the returned Promise will reject with a LocationUnavailableError.
If the request to get the current weather fails due to networking reasons, the returned Promise will reject with a NetworkUnreachableError if the service can't be reached, or a WeatherServiceUnavailableError if the service is temporarly or permanently out.
Parameter: options
Extra options for the retrieval
temperatureUnit Temperature unit in which you want the response data to be returned
Enum: TemperatureUnit
New in SDK 6.0
Temperature unit types
Members
Celsius
Fahrenheit
Interface: Location
New in SDK 6.0
Specific location to show the weather for
Properties
readonly currentWeather
Object represeting the current weather in this location
readonly name
string
Name of the location eg: Yosemite
readonly timeOffsetUTC
number
Offset from UTC in seconds eg -28800
Interface: CurrentWeather
New in SDK 6.0
Object that contains the current weather conditions and the current timestamp
Properties
readonly epochTime
number
Time of observation as epoch time (UTC) in seconds
readonly temperature
number
Current temperature data in the requested temperature unit
readonly weatherCondition
Weather condition value
Enum: WeatherCondition
New in SDK 6.0
Weather condition type.
Conditions marked with the Day
/Night
suffix may only occur during that part of the day.
Members
ClearNight
Cloudy
Cold
Flurries
Fog
FreezingRain
HazyMoonlight
HazySunshineDay
Hot
Ice
IntermittentCloudsDay
IntermittentCloudsNight
MostlyClearNight
MostlyCloudyDay
MostlyCloudyNight
MostlyCloudyWithFlurriesDay
MostlyCloudyWithFlurriesNight
MostlyCloudyWithShowersDay
MostlyCloudyWithShowersNight
MostlyCloudyWithSnowDay
MostlyCloudyWithSnowNight
MostlyCloudyWithThunderstormsDay
MostlyCloudyWithThunderstormsNight
MostlySunnyDay
Overcast
PartlyCloudyNight
PartlyCloudyWithShowersNight
PartlyCloudyWithThunderstormsNight
PartlySunnyDay
PartlySunnyWithFlurriesDay
PartlySunnyWithShowersDay
PartlySunnyWithThunderstormsDay
Rain
RainAndSnow
Showers
Sleet
Snow
SunnyDay
Thunderstorms
Windy
Interface: WeatherData
New in SDK 6.0
The data containing all the requested locations and the temperature unit used to represent temperature in each location
Properties
readonly locations
Location[]
List of locations with their respective temperature data
readonly temperatureUnit
Temperature unit requested in the query,if present, otherwise the default temperature unit type (Celsius or Fahrenheit) as received from the weather service