Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jonathan-fielding/yalealarmsystem
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: jonathandann/yalesyncalarm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Aug 29, 2019

  1. Add tsconfig.json

    jonathandann committed Aug 29, 2019
    Copy the full SHA
    4db6ea2 View commit details

Commits on Aug 31, 2019

  1. Copy the full SHA
    b5c8505 View commit details
  2. import fetch

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    5da0e5a View commit details
  3. Copy the full SHA
    2658b4c View commit details
  4. Copy the full SHA
    58dd4d4 View commit details
  5. Target es6, strict

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    4cc86a5 View commit details
  6. Copy the full SHA
    00115c5 View commit details
  7. Copy the full SHA
    9ac3e83 View commit details
  8. Export functions

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    691a649 View commit details
  9. Add AlarmState enum

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    a0477a8 View commit details
  10. Copy the full SHA
    88c1f24 View commit details
  11. Copy the full SHA
    7dbe162 View commit details
  12. Copy the full SHA
    af38360 View commit details
  13. Remove access_token global, this is unused and misleading, it looks l…

    …ike it’s used in other functions, but it’s never assigned. Instead the caller is always required to store the access token (the result of getAccessToken()) and pass it to setStatus() et al.
    jonathandann committed Aug 31, 2019
    Copy the full SHA
    d299b9f View commit details
  14. Copy the full SHA
    15269c0 View commit details
  15. Copy the full SHA
    50abe97 View commit details
  16. Copy the full SHA
    96ed9ad View commit details
  17. Copy the full SHA
    a866d67 View commit details
  18. Use async/await

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    29f60a8 View commit details
  19. Copy the full SHA
    6ed0716 View commit details
  20. Copy the full SHA
    f0b09fb View commit details
  21. Factor our URL building

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    2850ed4 View commit details
  22. Consistent whitespace

    jonathandann committed Aug 31, 2019
    Copy the full SHA
    6f53dff View commit details

Commits on Sep 1, 2019

  1. Copy the full SHA
    8ee2006 View commit details
  2. Bump npm version

    jonathandann committed Sep 1, 2019
    Copy the full SHA
    e5d1b10 View commit details
  3. Copy the full SHA
    3158d6f View commit details

Commits on Sep 2, 2019

  1. Add back Content-Type to header. Looks like PAW is automatically addi…

    …ng that when it’s missing from POST requests. Without it, the API returns an error.
    jonathandann committed Sep 2, 2019
    Copy the full SHA
    f738ef7 View commit details
  2. Use esnext, marks js functions as async, which makes await in node --…

    …experimental-repl-await actually work
    jonathandann committed Sep 2, 2019
    Copy the full SHA
    edfb7ba View commit details
  3. Copy the full SHA
    6d12a3c View commit details

Commits on Sep 3, 2019

  1. Copy the full SHA
    4702fb0 View commit details
  2. Copy the full SHA
    87daa14 View commit details
  3. Move index.ts to src/, update tsconfig.json to compile to ./lib, upda…

    …te .gitignore to ignore ./lib
    jonathandann committed Sep 3, 2019
    Copy the full SHA
    ffc0ae9 View commit details
  4. Copy the full SHA
    4ae38e9 View commit details
  5. Copy the full SHA
    c8fbff9 View commit details
  6. Copy the full SHA
    36ccd0b View commit details
  7. Run prettier

    jonathandann committed Sep 3, 2019
    Copy the full SHA
    d389f2b View commit details
  8. Nuke ESLint for now

    jonathandann committed Sep 3, 2019
    Copy the full SHA
    d73d2e3 View commit details

Commits on Sep 4, 2019

  1. Copy the full SHA
    ab59efc View commit details
  2. Add npm run prepare

    jonathandann committed Sep 4, 2019
    Copy the full SHA
    952fa34 View commit details
  3. Copy the full SHA
    02f2c9c View commit details
  4. Copy the full SHA
    3f6e0c9 View commit details

Commits on Sep 5, 2019

  1. Copy the full SHA
    6a65226 View commit details

Commits on Sep 6, 2019

  1. Copy the full SHA
    1660d9e View commit details
  2. Copy the full SHA
    ba7f45b View commit details
  3. Copy the full SHA
    dcf4af4 View commit details
  4. Pull out fetch functions, factor out duplicated error parsing & throw…

    …ing, create and parse Sensor discriminated union type
    jonathandann committed Sep 6, 2019
    Copy the full SHA
    e26480e View commit details
  5. Copy the full SHA
    eeb83b8 View commit details
  6. Copy the full SHA
    478a302 View commit details
  7. Remove namespace Sensor

    jonathandann committed Sep 6, 2019
    Copy the full SHA
    d87932d View commit details
  8. Copy the full SHA
    e1bb893 View commit details
Showing with 905 additions and 165 deletions.
  1. +2 −1 .gitignore
  2. +7 −0 .prettierrc
  3. +3 −0 .vscode/settings.json
  4. +18 −0 .vscode/tasks.json
  5. +25 −0 LICENSE
  6. +59 −37 README.md
  7. +0 −97 index.js
  8. +36 −6 package-lock.json
  9. +42 −24 package.json
  10. +112 −0 src/Decoders.ts
  11. +40 −0 src/Lock.ts
  12. +69 −0 src/Logger.ts
  13. +81 −0 src/Model.ts
  14. +398 −0 src/Yale.ts
  15. +13 −0 tsconfig.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules/
dist/
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": true,
"semi": false,
"singleQuote": true
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
18 changes: 18 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MIT License

https://github.com/jonathandann/yalesyncalarm
Copyright (c) 2019 Jonathan Dann

Forked from https://github.com/jonathan-fielding/yalealarmsystem
Copyright 2019 Jonathan Fielding, Jack Mellor & Adam Green

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
96 changes: 59 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,85 @@
# Yale Alarm System Node.js API Wrapper
[![Known Vulnerabilities](https://snyk.io//test/github/jonathan-fielding/homebridge-yalealarmsystem/badge.svg?targetFile=package.json)](https://snyk.io//test/github/jonathan-fielding/homebridge-yalealarmsystem?targetFile=package.json)
# Yale Sync & Smart Home Alarm API

This Node.js module wraps the undocumented API used to control the [Yale Smart Alarm System](https://www.yale.co.uk/en/yale/couk/products/smart-living/smart-home-alarms/smart-home-alarm-and-view-kit/).
![npm](https://img.shields.io/npm/v/yalesyncalarm)
[![Known Vulnerabilities](https://snyk.io//test/github/jonathandann/yalesyncalarm/badge.svg?targetFile=package.json)](https://snyk.io//test/github/jonathandann/yalesyncalarm/badge.svg?targetFile=package.json)
[![npm](https://img.shields.io/npm/l/yalesyncalarm.svg 'license')](https://github.com/jonathandann/yalesyncalarm/blob/master/LICENSE)

## Installation
API wrapper for the undocumented API used by the [Yale Sync Smart Home Alarm](https://www.yale.co.uk/en/yale/couk/products/smart-living/smart-home-alarms/sync-smart-alarm/) and [Yale Smart Home Alarm](https://www.yale.co.uk/en/yale/couk/products/smart-living/smart-home-alarms/smart-home-alarm-starter-kit/).

`npm i yalealarmsystem --save`
The state of the alarm system (the panel) is exposed, along with contact and motion sensors.

## Usage
# Installation

### getAccessToken
`npm install --save yalesyncalarm`

`getAccessToken` will retrieve a token to use for the API, it takes two arguments, your username and password used to login to the App of your alarm system.
# Usage

```
getAccessToken('username', 'password');
```
## Typescript

### getStatus
The NPM module ships pre-compiled `js` files, and `d.ts` files so it still can be used from typescript directly.

`getStatus` will retrieve the status of the alarm system, it returns the response the API returns.
```typescript
// File.ts

```
getStatus('access_token');
```
import { Yale } from 'yalesyncalarm'

As the example shows you will need to pass the sessionCookie into the getStatus method call, as this module is promise based you can simply chain the getStatus method call after your getAccessToken call.
const yale = new Yale(username, password)
await yale.update() // fetches panel and sensor state

```
getAccessToken('username', 'password').then(getStatus);
const panel = await yale.panel()
const panelState = await yale.getPanelState()
const updatedPanelState = await yale.setPanelState(Panel.State.Armed)

const motionSensors = await yale.motionSensors()
const contactSensors = await yale.contactSensors()

const updatedMotionSensor = await yale.updateMotionSensor(motionSensor)
const updatedContactSensor = await yale.updateMotionSensor(contactSensor)
```

### setStatus
`Yale.AccessToken` contains both the token itself and an expiry date, after which the token is no longer valid. Clients are expected to verify the token is valid before calling other methods, or handle errors thrown by API calls that use the access token.

`setStatus` will set the status of the alarm system. It takes two parameters:
`Yale.Panel.Mode` is an enum consisting of `.arm`, `.disarm` and `.home` cases. The Yale alarms do not discrimiate between _home_ and _night_ modes as some other alarm systems do.

* Access Token - This is retrieved using `getAccessToken`
* Mode - The mode can either be 'arm', 'home' or 'disarm'
`Yale.Devices.Sensor` is a discriminated union for _Door Contact Sensors_ and _Passive IR Sensors_. The states of these are conveniently expressed as `enums`. Each sensor has an `identifier` which can be used to track the state of a sensor across multiple calls to `Yale.Devices.getSensors()`.

```
setStatus('access_token', 'arm');
```
## Javascript

As the example shows you will need to pass the sessionCookie into the setStatus method call, as this module is promise based you can simply chain the setStatus method call after your getAccessToken call.
The installed NPM module ships pre-compiled `js` files. Therefore you are not required to build the `js` from the original typescript source in order to use the package.

```javascript
// File.js

var Yale = require('yalesyncalarm')

var yale = new Yale.Yale(username, password)
await yale.update() // fetches panel and sensor state

var panel = await yale.panel()
var panelState = await yale.getPanelState()
var updatedPanelState = await yale.setPanelState('arm)
var motionSensors = await yale.motionSensors()
var contactSensors = await yale.contactSensors()
var updatedMotionSensor = await yale.updateMotionSensor(motionSensor)
var updatedContactSensor = await yale.updateMotionSensor(contactSensor)
```
getAccessToken('username', 'password').then((access_token) => {
setStatus(access_token, 'arm');
});
```
## License
# Limitations
The undocumented Yale API can change on a whim, so this may break at any time. If it does, please submit a pull request if you can work out what right changes should be to make it work again.
Copyright 2019 Jonathan Fielding, Jack Mellor & Adam Green
My best guess is that the `Yale Home` app itself uses a non-HTTP-based protocol like XMPP/MQTT to both send and recieve state changes. The HTTP API used in this project works for pulling state for Yale Sync and Yale Smart Home APIs, but there's no way (yet) to subscribe to state changes.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# Building from Source

```bash
git clone https://github.com/jonathandann/yalesyncalarm.git && cd yalesyncalarm && npm install
```

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
After running `npm install`, `npm` should automatically run `npm run build`, which runs `node_modules/typescript/bin/tsc` to compile the typescript files. If it doesn't then you can run either `node_modules/typescript/bin/tsc` or `npm run build`.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
There are useful configs already included for [prettier](https://prettier.io) and [Visual Studio Code](https://code.visualstudio.com).
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Visual Studio Code is configured to use the version of typescript installed as a development dependency in the npm package.
97 changes: 0 additions & 97 deletions index.js

This file was deleted.

42 changes: 36 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading