Skip to content

Commit

Permalink
Converted to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunoo authored Jul 26, 2020
1 parent 18d9037 commit 8bf7a9f
Show file tree
Hide file tree
Showing 15 changed files with 2,139 additions and 176 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json'
},
rules: {
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
'@typescript-eslint/brace-style': 'error',
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/func-call-spacing': 'error',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/lines-between-class-members': ['error', {"exceptAfterSingleLine": true}],
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-parens': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': ['error', {"allowComparingNullableBooleansToTrue": false, "allowComparingNullableBooleansToFalse": false}],
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/quotes': ['error', 'single', {"allowTemplateLiterals": false}],
'@typescript-eslint/semi': ['error'],
'@typescript-eslint/space-before-function-paren': ['error', 'never'],
'@typescript-eslint/type-annotation-spacing': 'error',
'comma-dangle': 'error',
'no-confusing-arrow': 'error',
'no-lonely-if': 'error',
'no-trailing-spaces': 'error',
'no-unneeded-ternary': 'error',
'one-var': ['error', 'never']
}
}
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "10:00"
target-branch: "beta"
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
50 changes: 50 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: NodeJS

on:
push:
branches: '**'
pull_request:
release: # Run when release is created
types: [created]

jobs:
build:

strategy:
matrix:
node-version: [10.x, 12.x, 13.x, 14.x]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: npm install and build
run: |
npm ci
npm run build --if-present
env:
CI: true

publish-npm:
# publish only if we are on our own repo, event was 'release' (a tag was created) and the tag starts with "v" (aka version tag)
if: github.repository == 'Sunoo/homebridge-rpi-rf-switch' && github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')

needs: build # only run if build succeeds

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 10 # use the minimum required version
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
26 changes: 26 additions & 0 deletions .github/workflows/prerelease.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/env node

const fs = require('fs');
const semver = require('semver');
const child_process = require('child_process');

function getTagVersionFromNpm(tag) {
try {
return child_process.execSync(`npm info ${package.name} version --tag="${tag}"`).toString('utf8').trim();
} catch (e) {
return null;
}
}

// load package.json
const package = JSON.parse(fs.readFileSync('package.json', 'utf8'));

// work out the correct tag
const currentLatest = getTagVersionFromNpm('latest') || '0.0.0';
const currentBeta = getTagVersionFromNpm('beta') || '0.0.0';
const latestNpmTag = semver.gt(currentBeta, currentLatest, { includePrerelease: true }) ? currentBeta : currentLatest;
const publishTag = semver.gt(package.version, latestNpmTag, { includePrerelease: true }) ? package.version : latestNpmTag;

// save the package.json
package.version = publishTag;
fs.writeFileSync('package.json', JSON.stringify(package, null, 4));
41 changes: 41 additions & 0 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Beta

on:
workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
ref: beta
- uses: actions/[email protected]
with:
node-version: 10
- name: npm install and build
run: |
npm ci
npm run build --if-present
env:
CI: true

publish-npm:
if: github.repository == 'Sunoo/homebridge-rpi-rf-switch'

needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 10
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: node .github/workflows/prerelease.js
- run: npm --no-git-tag-version version prerelease --preid=beta
- run: npm publish --tag=beta
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
27 changes: 27 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Stale

on:
issues:
types: [reopened]
schedule:
- cron: "*/60 * * * *"

jobs:
stale:

runs-on: ubuntu-latest
env:
ACTIONS_STEP_DEBUG: true
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
days-before-stale: 7
days-before-close: 2
exempt-issue-labels: 'long running,help wanted'
exempt-pr-labels: 'awaiting-approval,work-in-progress'
remove-stale-when-updated: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
__pycache__
dist
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"line_length": false,
"no-duplicate-heading": false
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# homebridge-rpi-rf-switch

[![npm](https://img.shields.io/npm/v/homebridge-rpi-rf-switch) ![npm](https://img.shields.io/npm/dt/homebridge-rpi-rf-switch)](https://www.npmjs.com/package/homebridge-rpi-rf-switch)

[rpi-rf](https://pypi.org/project/rpi-rf/) Plugin for [Homebridge](https://github.com/nfarina/homebridge)

This plugin allows you to send 433MHz RF commands via HomeKit. I had no luck getting anything other than rpi-rf to communicate with my hardware. There are other plugins though, try those if this doesn't work for you.

### Installation
## Installation

1. Install pip using `sudo apt install python3-pip`.
2. Install rpi-rf using `sudo pip3 install rpi-rf`.
3. Install Homebridge using the [official instructions](https://github.com/homebridge/homebridge/wiki).
4. Install this plugin using `sudo npm install -g homebridge-rpi-rf-switch --unsafe-perm`.
5. Update your configuration file. See configuration sample below.

### Configuration

Edit your `config.json` accordingly. Configuration sample:
```

```json
"platforms": [{
"platform": "rfSwitch",
"name": "RF Switch",
Expand Down Expand Up @@ -45,4 +49,5 @@ Edit your `config.json` accordingly. Configuration sample:
| \|- codelength | RF code length. (Default: 24) | No |

### Note on Getting RF Codes

I've had the best luck with `RFSniffer` from the [433Utils](https://github.com/ninjablocks/433Utils) project. Your mileage may vary.
Loading

0 comments on commit 8bf7a9f

Please sign in to comment.