Using the Weather API for SDK 4.3 and using the default code provided in the documentation
here, cond gives 33 instead of SunnyDay for example. And this worked perfectly before. So I highly doubt that my implementation is wrong.
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);
});
}
Answered! Go to the Best Answer.
Best AnswerSorry for bringing this old topic up,
But i know how to "link" the numbers to the old "Condition Names"
just do something like this:
import {weather,WeatherCondition} from "weather";
function findWeatherConditionName(WeatherCondition, conditionCode) {
for (const condition of Object.keys(WeatherCondition)) {
if (conditionCode === WeatherCondition[condition]) return condition;
}
}
And then call it like this:
if (companion.permissions.granted("access_location")) {
weather.getWeatherData().then((data) => {
if (data.locations.length > 0) {
const cond = findWeatherConditionName(WeatherCondition,data.locations[0].currentWeather.weatherCondition);
I hope it solves your problem
Best AnswerNope, the numbers don't match up with anything as far as I know
Best AnswerBump, as I've tried the example in the API and it has given me numbers. Is this now substituing the strings?
Best AnswerHi,
you'll find the "list" condition/enum here:
https://discord.com/channels/355793206182412290/360916874902372352/890710177987305553
Sorry for bringing this old topic up,
But i know how to "link" the numbers to the old "Condition Names"
just do something like this:
import {weather,WeatherCondition} from "weather";
function findWeatherConditionName(WeatherCondition, conditionCode) {
for (const condition of Object.keys(WeatherCondition)) {
if (conditionCode === WeatherCondition[condition]) return condition;
}
}
And then call it like this:
if (companion.permissions.granted("access_location")) {
weather.getWeatherData().then((data) => {
if (data.locations.length > 0) {
const cond = findWeatherConditionName(WeatherCondition,data.locations[0].currentWeather.weatherCondition);
I hope it solves your problem
Best AnswerIs there any reason why this works on Fitbit Simulator but not on device?
When I run this code on device it returns “undefined” and the WeatherCondition itself returns function (){ [native code] }.
When I run in the simulator it returns a weather condition text and the WeatherCondition itself returns [object Object].
As an interim I am using the returned WeatherCondition texts from the simulator and manually creating an array to look up to on device.
Plod-Along, I am having this same issue. It works fine in the simulator, but when I run it on the physical device (in my case a Sense 2), it always comes back as undefined. The for loop in Aaroneisele55's example never gets entered. Have you found another solution other than creating your own look up array? I'm worried about that being the solution as it seems like it might be brittle in the event of future API changes.
Best Answer