Skip to content

Commit c96a90d

Browse files
authored
Merge pull request #15 from smirko-dev/feature/refactoring
Refactoring
2 parents 689ab83 + 4a0f251 commit c96a90d

File tree

11 files changed

+451
-242
lines changed

11 files changed

+451
-242
lines changed

.github/workflows/FitbitBuild.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,6 @@ jobs:
4646
path: build/app.sdk4.fba
4747
if-no-files-found: error
4848

49-
build-sdk5:
50-
name: Build SDK5
51-
runs-on: ubuntu-latest
52-
53-
steps:
54-
- name: Checkout branch
55-
uses: actions/checkout@v2
56-
with:
57-
lfs: true
58-
59-
- name: Setup node
60-
uses: actions/setup-node@v1
61-
62-
- name: Select SDK 5
63-
run: cp package.sdk5.json package.json
64-
65-
- name: Checkout Fitbit SDK
66-
run: npm add --also=dev @fitbit/sdk
67-
68-
- name: Checkout Fitbit SDK-CLI
69-
run: npm add --also=dev @fitbit/sdk-cli
70-
71-
- name: Run Build
72-
run: npx fitbit-build --if-present
73-
74-
- name: Copy App
75-
run: cp build/app.fba build/app.sdk5.fba
76-
77-
- name: Upload artifact
78-
uses: actions/upload-artifact@v2
79-
if: ${{ success() }}
80-
with:
81-
path: build/app.sdk5.fba
82-
if-no-files-found: error
83-
8449
build-sdk6:
8550
name: Build SDK6
8651
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Version 1.0
8+
9+
### Added
10+
- Support button entities
11+
12+
### Changed
13+
- Created HomeassistantAPI module
14+
715
## Version 0.6
816

917
### Added

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
[![](https://img.shields.io/badge/Fitbit%20App%20Gallery-%2300B0B9?style=flat&logo=fitbit&logoColor=white)](https://gallery.fitbit.com/details/158edb1c-f748-4dbf-a682-b9dae2b74457)
44
![languages](https://img.shields.io/badge/languages-JavaScript%20|%20CSS-blue)
55
![platform](https://img.shields.io/badge/platforms-Ionic%20|%20Versa%20|%20Versa%202%20|%20Versa%20Lite%20|%20Versa%203%20|%20Sense-silver)
6-
[![version](https://img.shields.io/badge/version-%200.6-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/CHANGELOG.md)
6+
[![version](https://img.shields.io/badge/version-%201.0-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/CHANGELOG.md)
77
[![](https://img.shields.io/badge/license-MIT-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/LICENSE)
88
[![FitbitBuild Actions Status](https://github.com/smirko-dev/fitbit-homeassistant/workflows/FitbitBuild/badge.svg)](https://github.com/smirko-dev/fitbit-homeassistant/actions)
99
[![CodeQL Actions Status](https://github.com/smirko-dev/fitbit-homeassistant/workflows/CodeQL/badge.svg)](https://github.com/smirko-dev/fitbit-homeassistant/actions)
1010

1111
## Description
1212

13-
This app allows to control [Home Assistant](https://www.home-assistant.io/) entities from a [Fitbit watch](https://www.fitbit.com/global/eu/home).
13+
This app allows to control [Home Assistant](https://www.home-assistant.io/) entities from a [Fitbit watch](https://www.fitbit.com/global/eu/home) via the [HomeAssistantAPI module](companion/) .
1414

1515
Supported languages: de-DE, en-US, it-IT.
1616

@@ -21,6 +21,7 @@ Supported entity types:
2121
- automation (execute)
2222
- script (execute)
2323
- cover (open/close)
24+
- button (execute)
2425

2526
App icon is from https://icon-icons.com/de/symbol/home-assistant/138491 ([Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)).
2627

@@ -53,7 +54,6 @@ Choose SDK version
5354
| SDK | Device |
5455
|-----|-----------------------------------|
5556
| 4 | Versa, Versa Lite, Versa 2, Ionic |
56-
| 5 | Versa 3, Sense |
5757
| 6 | Versa 3, Sense |
5858

5959
```

app/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ me.onunload = saveSettings;
2222

2323
// List of {id: "", name: "", state: ""}
2424
let Entities = [];
25-
const nextStates = {
25+
const NextStates = {
2626
on: "turn_off",
2727
off: "turn_on",
2828
open: "close_cover",
@@ -47,7 +47,7 @@ function setupList(list, data) {
4747
tile.getElementById("itemText").text = `${info.name}`;
4848
tile.getElementById("itemState").text = `${gettext(info.state)}`;
4949
let touch = tile.getElementById("itemTouch");
50-
touch.onclick = () => sendData({key: "change", entity: Entities[info.index].id, state: nextStates[info.state]});
50+
touch.onclick = () => sendData({key: "change", entity: Entities[info.index].id, state: NextStates[info.state]});
5151
}
5252
}
5353
};
@@ -69,6 +69,7 @@ messaging.peerSocket.onmessage = (evt) => {
6969
else if (evt.data.key === "change") {
7070
Entities.forEach((entity, index) => {
7171
if (entity.id === evt.data.id) {
72+
//DEBUG console.log(`Updated: ${evt.data.id} to ${evt.data.state}`);
7273
Entities[index].state = evt.data.state;
7374
setupList(EntityList, Entities);
7475
}
@@ -129,7 +130,7 @@ function loadSettings() {
129130
url: "localhost",
130131
port: "8123",
131132
token: "",
132-
force: false
133+
force: true
133134
};
134135
}
135136
}

common/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as messaging from "messaging";
44
// Send data
55
export function sendData(data) {
66
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
7-
console.log('Sent', JSON.stringify(data));
7+
//DEBUG console.log('Sent', JSON.stringify(data));
88
messaging.peerSocket.send(data);
99
}
1010
}
@@ -14,4 +14,4 @@ export function isEmpty(obj) {
1414
//return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
1515
let json = JSON.stringify(obj);
1616
return json === '{}' || json === '[]';
17-
}
17+
}

0 commit comments

Comments
 (0)