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

Merge develop into master #2

Merged
merged 5 commits into from
Oct 6, 2019
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"rules": {
"indent": [
"error",
"tab",
4,
{
"SwitchCase": 1
}
Expand Down
96 changes: 27 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,41 @@

**Tests:**: [![Travis-CI](http://img.shields.io/travis/MiGoller/ioBroker.life360/master.svg)](https://travis-ci.org/MiGoller/ioBroker.life360)

## life360 adapter for ioBroker

An ioBroker adapter for Life360.

## Developer manual
This section is intended for the developer. It can be deleted later

### Getting started

You are almost done, only a few steps left:
1. Create a new repository on GitHub with the name `ioBroker.life360`
1. Initialize the current folder as a new git repository:
```bash
git init
git add .
git commit -m "Initial commit"
```
1. Link your local repository with the one on GitHub:
```bash
git remote add origin https://github.com/MiGoller/ioBroker.life360
```

1. Push all files to the GitHub repo:
```bash
git push origin master
```
1. Head over to [main.js](main.js) and start programming!

### Scripts in `package.json`
Several npm scripts are predefined for your convenience. You can run them using `npm run <scriptname>`
| Script name | Description |
|-------------|----------------------------------------------------------|
| `test:js` | Executes the tests you defined in `*.test.js` files. |
| `test:package` | Ensures your `package.json` and `io-package.json` are valid. |
| `test` | Performs a minimal test run on package files and your tests. |
| `coverage` | Generates code coverage using your test files. |

### Writing tests
When done right, testing code is invaluable, because it gives you the
confidence to change your code while knowing exactly if and when
something breaks. A good read on the topic of test-driven development
is https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92.
Although writing tests before the code might seem strange at first, but it has very
clear upsides.

The template provides you with basic tests for the adapter startup and package files.
It is recommended that you add your own tests into the mix.

### Publishing the adapter
See the documentation of [ioBroker.repositories](https://github.com/ioBroker/ioBroker.repositories#requirements-for-adapter-to-get-added-to-the-latest-repository).

### Test the adapter manually on a local ioBroker installation
In order to install the adapter locally without publishing, the following steps are recommended:
1. Create a tarball from your dev directory:
```bash
npm pack
```
1. Upload the resulting file to your ioBroker host
1. Install it locally (The paths are different on Windows):
```bash
cd /opt/iobroker
npm i /path/to/tarball.tgz
```

For later updates, the above procedure is not necessary. Just do the following:
1. Overwrite the changed files in the adapter directory (`/opt/iobroker/node_modules/iobroker.life360`)
1. Execute `iobroker upload life360` on the ioBroker host
## Life360 adapter for ioBroker

An ioBroker adapter for [Life360](https://www.life360.com).

## Description

This adapter connects to the [Life360](https://www.life360.com) cloud services to allow you to track people and to detect their presence at defined places. It retrieves information about the user's circles, the circles' members and the circles' places. These information persists the adapter in ioBroker states. Any states will get updated in a given interval.

## Installation

Right now you'll have to add the adapter to your ioBroker using a custom url pointing to the corresponding [GitHub](https://github.com/) repository at https://github.com/MiGoller/ioBroker.life360/tree/master .

## Configuration

You'll have to setup the adapter with your personal [Life360](https://www.life360.com) credentials to let the adapter poll the information from the cloud services. You can login with your mobile phone number or your email-address (recommended) for Life360, but in any case you'll have to set the password to your personal Life360 password.

Feel free to modify the default timespan of 60 seconds for the polling interval. The adapter does not allow modifying the interval to less than 15 seconds to prevent gaining any rate limits and to prevent ioBroker Admin getting slower and slower.

## Disclaimer
I did not find any official documentation for the [Life360](https://www.life360.com) REST APIs. Apparently [Life360](https://www.life360.com) does not support the use of the REST API for other applications than its own ones.

My REST API integration is based on reverse engineering done by the open source community and an API token discovered on [Life360](https://www.life360.com) code which is public available. [Life360](https://www.life360.com) could disable or modify this API token or change its REST API in a way that this adapter will not work as expected anymore.

## Changelog

### 0.1.1
* (migoller) First alpha release

### 0.0.1
* (MiGoller) initial release
* (migoller) initial release

## License
MIT License

Copyright (c) 2019 MiGoller <[email protected].com>
Copyright (c) 2019 Michael Goller <goller.michael@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 16 additions & 6 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,26 @@

<!-- Put your content here -->

<!-- For example columns with settings: -->
<div class="row">
<div class="col s6 input-field">
<input type="checkbox" class="value" id="option1" />
<label for="option1" class="translate">option1</label>
<input type="text" class="value" id="life360_username" />
<label for="life360_username" class="translate">Life360 email address</label>
</div>
<div class="col s6 input-field">
<input type="password" class="value" id="life360_password" />
<label for="life360_password" class="translate">Life360 password</label>
</div>
<div class="col s6 input-field">
<input type="text" class="value" id="life360_countryCode" />
<label for="life360_countryCode" class="translate">Life360 phone countrycode</label>
</div>
<div class="col s6 input-field">
<input type="text" class="value" id="life360_phone" />
<label for="life360_phone" class="translate">Life360 phone number</label>
</div>

<div class="col s6 input-field">
<input type="text" class="value" id="option2" />
<label for="option2" class="translate">option2</label>
<input type="text" class="value" id="life360_polling_interval" />
<label for="life360_polling_interval" class="translate">Life360 polling interval (sec.)</label>
</div>
</div>

Expand Down
Binary file modified admin/life360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 63 additions & 6 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "life360",
"version": "0.0.1",
"version": "0.1.1",
"news": {
"0.1.1": {
"en": "First release",
"de": "Erstes Release"
},
"0.0.1": {
"en": "initial release",
"de": "Erstveröffentlichung",
Expand Down Expand Up @@ -42,11 +46,11 @@
"zh-cn": "An ioBroker adapter for Life360."
},
"authors": [
"MiGoller <[email protected].com>"
"migoller <goller.michael@gmail.com>"
],
"keywords": [
"ioBroker",
"template",
"Life360",
"Smart Home",
"home automation"
],
Expand All @@ -69,9 +73,62 @@
]
},
"native": {
"option1": true,
"option2": "42"
"life360_username": "[email protected]",
"life360_password": "MySecretPassword",
"life360_phone": "",
"life360_countryCode": "",
"life360_polling_interval": "60"
},
"objects": [],
"instanceObjects": []
"instanceObjects": [
{
"_id": "info",
"type": "channel",
"common": {
"name": "Information"
},
"native": {}
},
{
"_id": "info.connection",
"type": "state",
"common": {
"name": "connected",
"desc": "Connected to Life360 cloud services?",
"type": "boolean",
"def": "false",
"read": "true",
"role": "value.info",
"write": "false"
},
"native": {}
},
{
"_id": "circles",
"type": "device",
"common": {
"name": "Circles",
"desc": "Life360 circles."
},
"native": {}
},
{
"_id": "places",
"type": "device",
"common": {
"name": "Places",
"desc": "Life360 places."
},
"native": {}
},
{
"_id": "people",
"type": "device",
"common": {
"name": "People",
"desc": "Life360 people."
},
"native": {}
}
]
}
104 changes: 104 additions & 0 deletions lib/iobHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"use strict";

/**
* IobLogger simplifies logging for adapter development and operations.
*/
exports.IobLogger = class {
/**
* Creates a new IobLogger instance
* @param {*} adapter_instance Set to your adapter instance to enable logging in ioBroker.
*/
constructor(adapter_instance) {
// this.myAdapter = adapter_instance;
this.setAdapter(adapter_instance);
}

/**
* Sets the ioBroker adapter instance to log to.
* @param {*} adapter_instance Set to your adapter instance to enable logging in ioBroker.
*/
setAdapter(adapter_instance) {
this.myAdapter = adapter_instance;
}

/**
* Create an ERROR log message.
* @param {*} message
*/
error(message) {
if (!this.myAdapter) console.error(`ERROR: ${message}`); else this.myAdapter.log.error(message);
}

/**
* Create a WARN log message.
* @param {*} message
*/
warn(message) {
if (!this.myAdapter) console.warn(`WARN: ${message}`); else this.myAdapter.log.warn(message);
}

/**
* Create an INFO log message.
* @param {*} message
*/
info(message) {
if (!this.myAdapter) console.log(`INFO: ${message}`); else this.myAdapter.log.info(message);
}

/**
* Create a DEBUG log message.
* @param {*} message
*/
debug(message) {
if (!this.myAdapter) console.debug(`DEBUG: ${message}`); else this.myAdapter.log.debug(message);
}

/**
* Create a SILLY log message.
* @param {*} message
*/
silly(message) {
if (!this.myAdapter) console.debug(`SILLY: ${message}`); else this.myAdapter.log.silly(message);
}

/**
* Logger is a wrapper for logging.
* @param {string} level Set to "error", "warn", "info", "debug"
* @param {*} message The message to log
*/
logger(level, message) {
switch (level) {
case "error":
this.error(message);
break;

case "warn":
this.warn(message);
break;

case "info":
this.info(message);
break;

case "debug":
this.debug(message);
break;

case "silly":
this.silly(message);
break;

default:
break;
}
}

/**
* Log is an alias for Logger!
* @param {string} level Set to "error", "warn", "info", "debug", "silly"
* @param {*} message The message to log
*/
log(level, message) {
this.logger(level, message);
}
}
Loading