Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weather update #23

Merged
merged 5 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version 1.7.1

### Changed
- Fixed update of weather info

## Version 1.7.0

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![](https://img.shields.io/badge/Fitbit%20App%20Gallery-%2300B0B9?style=flat&logo=fitbit&logoColor=white)](https://gallery.fitbit.com/details/ae441b73-2660-407f-b796-a98d1d0583a0)
![languages](https://img.shields.io/badge/languages-JavaScript%20|%20CSS-blue)
![platform](https://img.shields.io/badge/platforms-Ionic%20|%20Versa%20|%20Versa%202%20|%20Versa%20Lite%20|%20Versa%203%20|%20Sense-silver)
[![version](https://img.shields.io/badge/version-%201.7.0-blue)](https://github.com/smirko-dev/fitbit-clockface/blob/master/CHANGELOG.md)
[![version](https://img.shields.io/badge/version-%201.7.1-blue)](https://github.com/smirko-dev/fitbit-clockface/blob/master/CHANGELOG.md)
[![](https://img.shields.io/badge/license-MIT-blue)](https://github.com/smirko-dev/fitbit-clockface/blob/master/LICENSE)
[![FitbitBuild Actions Status](https://github.com/smirko-dev/fitbit-clockface/workflows/FitbitBuild/badge.svg)](https://github.com/smirko-dev/fitbit-clockface/actions)
[![CodeQL Actions Status](https://github.com/smirko-dev/fitbit-clockface/workflows/CodeQL/badge.svg)](https://github.com/smirko-dev/fitbit-clockface/actions)
Expand Down
48 changes: 28 additions & 20 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const INVISIBLE = 0.0;
const VISIBLE = 0.8;

// Current weather status
let WeatherIcon = 'thermometer.png';
let WeatherValue = 'N/A';
weatherImage.image = 'thermometer.png';
weatherLabel.text = 'N/A';

// Permissions
const CalendarPermissionGranted = appbit.permissions.granted('access_calendar');
Expand Down Expand Up @@ -79,13 +79,14 @@ function applySettings(activity, color, info) {
weatherImage.style.opacity = INVISIBLE;
weatherLabel.style.opacity = INVISIBLE;
batteryImage.style.opacity = VISIBLE;
renderBattery();
updateBattery();
}
else if (info === 'weather') {
batteryImage.style.opacity = INVISIBLE;
batteryLabel.style.opacity = INVISIBLE;
weatherImage.style.opacity = VISIBLE;
weatherLabel.style.opacity = VISIBLE;
updateWeather();
}
else {
batteryImage.style.opacity = INVISIBLE;
Expand Down Expand Up @@ -127,7 +128,7 @@ messaging.peerSocket.onmessage = (evt) => {
else if (evt.data.key === "info") {
applySettings(settings.activity, settings.color, evt.data.value);
}
renderAppointment();
updateAppointment();
}

// Clock callback
Expand All @@ -136,35 +137,42 @@ clock.initialize("minutes", data => {
minuteLabel.text = data.minutes;
dateLabel.text = data.date;

renderAppointment();
updateAppointment();
});

// Battery change callback
battery.onchange = (evt) => {
renderBattery();
updateBattery();
}

// Appointment callback
appointment.initialize(() => {
renderAppointment();
updateAppointment();
});

// Weather callback
weather.initialize(data => {
//DEBUG console.log(`Weather: ${data.icon} - ${data.temperature} ${data.unit} in ${data.location}`);
data = units.temperature === "F" ? toFahrenheit(data) : data;
WeatherValue = `${data.temperature}\u00B0${units.temperature}`;
weatherLabel.text = WeatherValue;
WeatherIcon = `${data.icon}`;
weatherImage.image = WeatherIcon;
updateWeather();
});

// Update weather
function updateWeather() {
let data = weather.current();
if (data) {
//DEBUG console.log(`Weather: ${data.icon} - ${data.temperature} ${data.unit} in ${data.location}`);
data = units.temperature === "F" ? toFahrenheit(data) : data;
weatherLabel.text = `${data.temperature}\u00B0${units.temperature}`;
weatherImage.image = `${data.icon}`;
}
}

// Display callback
display.addEventListener("change", () => {
if (display.on) {
// Update appointment and battery on display on
renderAppointment();
renderBattery();
// Update content on display on
updateAppointment();
updateBattery();
updateWeather();
}
else {
// Stop updating activity
Expand All @@ -179,7 +187,7 @@ appointmentsLabel.addEventListener("mousedown", () => {
})

// Update appointment
function renderAppointment() {
function updateAppointment() {
let event = appointment.next();
if (event) {
const date = fromEpochSec(event.startDate);
Expand Down Expand Up @@ -226,10 +234,10 @@ function updateActivity() {
}

// Update battery
function renderBattery() {
function updateBattery() {
// Update the battery <text> element every time when battery changed
batteryLabel.text = Math.floor(battery.chargeLevel) + "%";
if (device.modelId != 27 ) {
if (device.modelId != 27) {
batteryLabel.style.opacity = INVISIBLE;
}
else {
Expand All @@ -246,4 +254,4 @@ function renderBattery() {
}
}

renderBattery();
updateBattery();
2 changes: 1 addition & 1 deletion package.sdk4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "compactclock",
"version": "1.7.0",
"version": "1.7.1",
"license": "MIT",
"devDependencies": {
"@fitbit/sdk": "~4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion package.sdk6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "compactclock",
"version": "1.7.0",
"version": "1.7.1",
"license": "MIT",
"devDependencies": {
"@fitbit/sdk": "~5.0.0",
Expand Down