Skip to content

Commit

Permalink
Merge pull request #15 from smirko-dev/feature/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
smirko-dev authored Jul 8, 2022
2 parents 689ab83 + 4a0f251 commit c96a90d
Show file tree
Hide file tree
Showing 11 changed files with 451 additions and 242 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/FitbitBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,6 @@ jobs:
path: build/app.sdk4.fba
if-no-files-found: error

build-sdk5:
name: Build SDK5
runs-on: ubuntu-latest

steps:
- name: Checkout branch
uses: actions/checkout@v2
with:
lfs: true

- name: Setup node
uses: actions/setup-node@v1

- name: Select SDK 5
run: cp package.sdk5.json package.json

- name: Checkout Fitbit SDK
run: npm add --also=dev @fitbit/sdk

- name: Checkout Fitbit SDK-CLI
run: npm add --also=dev @fitbit/sdk-cli

- name: Run Build
run: npx fitbit-build --if-present

- name: Copy App
run: cp build/app.fba build/app.sdk5.fba

- name: Upload artifact
uses: actions/upload-artifact@v2
if: ${{ success() }}
with:
path: build/app.sdk5.fba
if-no-files-found: error

build-sdk6:
name: Build SDK6
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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.0

### Added
- Support button entities

### Changed
- Created HomeassistantAPI module

## Version 0.6

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
[![](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)
![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-%200.6-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/CHANGELOG.md)
[![version](https://img.shields.io/badge/version-%201.0-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/CHANGELOG.md)
[![](https://img.shields.io/badge/license-MIT-blue)](https://github.com/smirko-dev/fitbit-homeassistant/blob/main/LICENSE)
[![FitbitBuild Actions Status](https://github.com/smirko-dev/fitbit-homeassistant/workflows/FitbitBuild/badge.svg)](https://github.com/smirko-dev/fitbit-homeassistant/actions)
[![CodeQL Actions Status](https://github.com/smirko-dev/fitbit-homeassistant/workflows/CodeQL/badge.svg)](https://github.com/smirko-dev/fitbit-homeassistant/actions)

## Description

This app allows to control [Home Assistant](https://www.home-assistant.io/) entities from a [Fitbit watch](https://www.fitbit.com/global/eu/home).
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/) .

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

Expand All @@ -21,6 +21,7 @@ Supported entity types:
- automation (execute)
- script (execute)
- cover (open/close)
- button (execute)

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)).

Expand Down Expand Up @@ -53,7 +54,6 @@ Choose SDK version
| SDK | Device |
|-----|-----------------------------------|
| 4 | Versa, Versa Lite, Versa 2, Ionic |
| 5 | Versa 3, Sense |
| 6 | Versa 3, Sense |

```
Expand Down
7 changes: 4 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ me.onunload = saveSettings;

// List of {id: "", name: "", state: ""}
let Entities = [];
const nextStates = {
const NextStates = {
on: "turn_off",
off: "turn_on",
open: "close_cover",
Expand All @@ -47,7 +47,7 @@ function setupList(list, data) {
tile.getElementById("itemText").text = `${info.name}`;
tile.getElementById("itemState").text = `${gettext(info.state)}`;
let touch = tile.getElementById("itemTouch");
touch.onclick = () => sendData({key: "change", entity: Entities[info.index].id, state: nextStates[info.state]});
touch.onclick = () => sendData({key: "change", entity: Entities[info.index].id, state: NextStates[info.state]});
}
}
};
Expand All @@ -69,6 +69,7 @@ messaging.peerSocket.onmessage = (evt) => {
else if (evt.data.key === "change") {
Entities.forEach((entity, index) => {
if (entity.id === evt.data.id) {
//DEBUG console.log(`Updated: ${evt.data.id} to ${evt.data.state}`);
Entities[index].state = evt.data.state;
setupList(EntityList, Entities);
}
Expand Down Expand Up @@ -129,7 +130,7 @@ function loadSettings() {
url: "localhost",
port: "8123",
token: "",
force: false
force: true
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as messaging from "messaging";
// Send data
export function sendData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
console.log('Sent', JSON.stringify(data));
//DEBUG console.log('Sent', JSON.stringify(data));
messaging.peerSocket.send(data);
}
}
Expand All @@ -14,4 +14,4 @@ export function isEmpty(obj) {
//return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
let json = JSON.stringify(obj);
return json === '{}' || json === '[]';
}
}
Loading

0 comments on commit c96a90d

Please sign in to comment.