08-27-2021 04:14 - edited 08-27-2021 04:15
08-27-2021 04:14 - edited 08-27-2021 04:15
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.
05-20-2022 21:59 - edited 05-20-2022 22:02
05-20-2022 21:59 - edited 05-20-2022 22:02
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
08-30-2021 07:30
08-30-2021 07:30
Hello
did you find somewhere the link between enum and numbers?
08-30-2021 12:36
08-30-2021 12:36
Nope, the numbers don't match up with anything as far as I know
08-31-2021 03:54
08-31-2021 03:54
Bump, as I've tried the example in the API and it has given me numbers. Is this now substituing the strings?
09-24-2021 03:32
09-24-2021 03:32
Hi,
you'll find the "list" condition/enum here:
https://discord.com/channels/355793206182412290/360916874902372352/890710177987305553
05-20-2022 21:59 - edited 05-20-2022 22:02
05-20-2022 21:59 - edited 05-20-2022 22:02
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
03-09-2023 06:05
03-09-2023 06:05
Is 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.
01-15-2025 13:53
01-15-2025 13:53
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.