Skip to content

Commit

Permalink
feat: Instance, Device & Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbo2002 committed Nov 7, 2020
1 parent eda6a56 commit 95c2b77
Show file tree
Hide file tree
Showing 21 changed files with 3,161 additions and 4,358 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.nyc_output
/examples
/node_modules
/src
/test-result
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test-result/**
node_modules/**
dist/**
coverage/**
56 changes: 31 additions & 25 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
{
"env": {
"node": true,
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"semi": "error",
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-console": [
"indent": [
"error",
{
"allow": ["log"]
}
],
"no-constant-condition": [
"warn"
4
]
}
}
},
"overrides": [
{
"files": [
"test/**/*.spec.ts"
],
"rules": {
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
}
]
}
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
/node_modules/
/coverage/

/node_modules
/dist
/coverage
/.idea/
/test-result
/.nyc_output
/test-result
60 changes: 0 additions & 60 deletions .gitlab-ci.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require:
- ts-node/register
- source-map-support/register
full-trace: true
extension:
- ts
24 changes: 24 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"cache": false,
"check-coverage": true,
"extension": [
".ts"
],
"include": [
"lib/**/*.ts"
],
"exclude": [
"coverage/**",
"node_modules/**"
],
"temp-directory": "./coverage/.nyc_output",
"sourceMap": true,
"reporter": [
"text",
"text-summary",
"cobertura",
"html"
],
"all": true,
"instrument": true
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:latest

# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH

RUN apt-get update && \
apt-get install -y python3-dev python3-pip curl sudo && \
pip3 install pyatv && \
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - && \
sudo apt-get install -y nodejs

COPY package*.json "/app/"
WORKDIR "/app"
RUN npm ci

COPY . "/app/"
CMD ["npm", "run", "test"]
41 changes: 41 additions & 0 deletions bin/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

import NodePyATVInstance from '../lib/instance';

(async () => {
try {
await NodePyATVInstance.check();

console.log('');
console.log('✔ node-pyatv seems to be ready to use!');
console.log(' Thank you and have a great day. Or night. Whatever.');
console.log('');
}
catch(error) {
console.log('');
console.log('#'.repeat(60));
console.log('#' + ' '.repeat(58) + '#');
console.log('# ⚠ Warning: node-pyatv is not ready to be used!' + ' '.repeat(10) + '#');
console.log('#' + ' '.repeat(58) + '#');
console.log('# To use the JavaScript module, pyatv >= 0.6.0 must be #');
console.log('# installed. Unfortunately this could not be found. During #');
console.log('# the check following error message was reported: #');
console.log('#' + ' '.repeat(58) + '#');
console.log(
String(error)
.replace('Error: ', '')
.replace(/(.{1,54})/g, '$1\n')
.split('\n')
.map(l => l.trim())
.filter(l => Boolean(l))
.map(l => `# > ${l}${' '.repeat(55 - l.length)}#`)
.join('\n')
);
console.log('#' + ' '.repeat(58) + '#');
console.log('# You can probably find more information here: #');
console.log('# https://github.com/sebbo2002/node-pyatv #');
console.log('#' + ' '.repeat(58) + '#');
console.log('#'.repeat(60));
console.log('');
}
})();
63 changes: 63 additions & 0 deletions lib/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

import {NodePyATVDeviceOptions, NodePyATVProtocol} from './types';

export default class NodePyATVDevice {
private readonly options: NodePyATVDeviceOptions;

constructor(options: NodePyATVDeviceOptions) {
this.options = Object.assign({}, options);

// @todo basic validation
}

get name(): string {
return this.options.name;
}

get host(): string {
return this.options.host;
}

get id(): string | undefined {
return this.options.id;
}

get protocol(): NodePyATVProtocol | undefined {
return this.options.protocol;
}

get debug(): true | ((msg: string) => void) | undefined {
return this.options.debug;
}

set debug(debug: true | ((msg: string) => void) | undefined) {
if(typeof debug === 'function') {
this.options.debug = debug;
} else {
this.options.debug = Boolean(debug) || undefined;
}
}

toJSON(): { name: string; host: string; id: string | undefined; protocol: NodePyATVProtocol | undefined } {
return {
name: this.name,
host: this.host,
id: this.id,
protocol: this.protocol
};
}

toString(): string {
return `NodePyATVDevice(${this.name}, ${this.host})`;
}

/*async getState(options: NodePyATVGetStatusOptions) {
}
async getMediaType(options: NodePyATVGetStatusOptions) {
const state = await this.getState(options);
return state.mediaType;
}*/
}
Loading

0 comments on commit 95c2b77

Please sign in to comment.