@sebbo2002/pyatv-mqtt-bridge 3.1.5-develop.3 → 4.0.0-develop.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -1 +0,0 @@
1
- <!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</title><meta name="description" content="Documentation for @sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</a></li><li><a href="default.html">default</a></li></ul><h1>Class default</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><span class="target">default</span></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Constructors</h3><ul class="tsd-index-list"><li class="tsd-kind-constructor tsd-parent-kind-class"><a href="default.html#constructor" class="tsd-kind-icon">constructor</a></li></ul></section><section class="tsd-index-section "><h3>Methods</h3><ul class="tsd-index-list"><li class="tsd-kind-method tsd-parent-kind-class"><a href="default.html#stop" class="tsd-kind-icon">stop</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Constructors</h2><section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-class"><a id="constructor" class="tsd-anchor"></a><h3 class="tsd-anchor-link">constructor<a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-class"><li class="tsd-signature tsd-kind-icon">new default<span class="tsd-signature-symbol">(</span>options<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Config</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="default.html" class="tsd-signature-type" data-tsd-kind="Class">default</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sebbo2002/pyatv-mqtt-bridge/blob/a61a3c9/src/lib/index.ts#L12">index.ts:12</a></li></ul></aside><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>options: <span class="tsd-signature-type">Config</span></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="default.html" class="tsd-signature-type" data-tsd-kind="Class">default</a></h4></li></ul></section></section><section class="tsd-panel-group tsd-member-group "><h2>Methods</h2><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class"><a id="stop" class="tsd-anchor"></a><h3 class="tsd-anchor-link">stop<a href="#stop" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class"><li class="tsd-signature tsd-kind-icon">stop<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sebbo2002/pyatv-mqtt-bridge/blob/a61a3c9/src/lib/index.ts#L167">index.ts:167</a></li></ul></aside><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4></li></ul></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class=""><a href="../modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="current tsd-kind-class"><a href="default.html" class="tsd-kind-icon">default</a><ul><li class="tsd-kind-constructor tsd-parent-kind-class"><a href="default.html#constructor" class="tsd-kind-icon">constructor</a></li><li class="tsd-kind-method tsd-parent-kind-class"><a href="default.html#stop" class="tsd-kind-icon">stop</a></li></ul></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="../assets/main.js"></script></body></html>
@@ -1,65 +0,0 @@
1
- <!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</title><meta name="description" content="Documentation for @sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><div class="tsd-panel tsd-typography">
2
- <a href="#pyatv-mqtt-bridge" id="pyatv-mqtt-bridge" style="color: inherit; text-decoration: none;">
3
- <h1>pyatv-mqtt-bridge</h1>
4
- </a>
5
- <p><a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="License"></a>
6
- <img src="https://img.shields.io/depfu/sebbo2002/pyatv-mqtt-bridge?style=flat-square" alt="Dependencies"></p>
7
- <p>MQTT Bridge allows you to remote control your Apple TV using the MQTT protocol. For many home automation systems, for
8
- example, this protocol is supported, so Apple TV can be integrated into your existing automation system. In addition to
9
- simulating key presses, you can also query the current state of Apple TV.</p>
10
-
11
- <a href="#☁-installation" id="☁-installation" style="color: inherit; text-decoration: none;">
12
- <h2>☁ Installation</h2>
13
- </a>
14
- <p>Before you use this module you need to install <code>pyatv</code>. See FAQ section for installation tips.</p>
15
- <p>To install the javascript module via npm run:</p>
16
- <pre><code><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> -</span><span class="hl-0">g</span><span class="hl-1"> @</span><span class="hl-0">sebbo2002</span><span class="hl-1">/</span><span class="hl-0">pyatv</span><span class="hl-1">-</span><span class="hl-0">mqtt</span><span class="hl-1">-</span><span class="hl-0">bridge</span>
17
- </code></pre>
18
- <p>You can also use the provided Docker container to run <code>pyatv-mqtt-bridge</code> within docker:</p>
19
- <pre><code><span class="hl-0">docker</span><span class="hl-1"> </span><span class="hl-0">pull</span><span class="hl-1"> </span><span class="hl-0">sebbo2002</span><span class="hl-1">/</span><span class="hl-0">pyatv</span><span class="hl-1">-</span><span class="hl-0">mqtt</span><span class="hl-1">-</span><span class="hl-0">bridge</span>
20
- </code></pre>
21
-
22
- <a href="#⚒-quick-start" id="⚒-quick-start" style="color: inherit; text-decoration: none;">
23
- <h2>⚒ Quick Start</h2>
24
- </a>
25
- <ol>
26
- <li><p>Use pyatv to connect to your Apple TV and authenticate [<a href="https://pyatv.dev/documentation/getting-started/">?</a>]</p>
27
- </li>
28
- <li><p>Create a new pyatv-mqtt-bridge configuration file. Your can use the
29
- <a href="https://github.com/sebbo2002/pyatv-mqtt-bridge/blob/develop/config.example.json"><code>config.example.json</code></a> to start
30
- with.</p>
31
- </li>
32
- </ol>
33
- <pre><code class="language-json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;broker&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;mqtt://192.168.1.1&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;devices&quot;</span><span class="hl-1">: [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;name&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;Any Name&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;topic&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;home/livingroom/appletv&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;host&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;192.168.1.2&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;id&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">&quot;airplayCredentials&quot;</span><span class="hl-1">: </span><span class="hl-3">&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD&quot;</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> ]</span><br/><span class="hl-1">}</span>
34
- </code></pre>
35
- <ol start="3">
36
- <li>Start pyatv
37
- ```bash
38
- pyatv-mqtt-bridge /home/eve/pyatv-mqtt-bridge.json</li>
39
- </ol>
40
-
41
- <a href="#or-use-the-docker-container" id="or-use-the-docker-container" style="color: inherit; text-decoration: none;">
42
- <h1>or use the Docker container</h1>
43
- </a>
44
- <p>docker run -d --restart=always --name=pyatv-mqtt-bridge <br> -v $(pwd)/config.json:/app/config.json:ro <br> sebbo2002/pyatv-mqtt-bridge</p>
45
- <pre><code><br/><br/><br/><span class="hl-1">## 🤨 </span><span class="hl-4">FAQ</span><br/><br/><span class="hl-1">#### </span><span class="hl-0">How</span><span class="hl-1"> </span><span class="hl-0">to</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> </span><span class="hl-0">pyatv</span><br/><br/><span class="hl-3">```bash</span><br/><span class="hl-3">pip3 install pyatv</span>
46
- </code></pre>
47
-
48
- <a href="#how-can-i-enable-debugging-mode" id="how-can-i-enable-debugging-mode" style="color: inherit; text-decoration: none;">
49
- <h4>How can I enable debugging mode?</h4>
50
- </a>
51
- <pre><code class="language-bash"><span class="hl-1">pyatv-mqtt-bridge --debug /home/eve/pyatv-mqtt-bridge.json</span><br/><br/><span class="hl-5"># or if you use the Docker container</span><br/><br/><span class="hl-1">docker run -d --restart=always --name=pyatv-mqtt-bridge \</span><br/><span class="hl-1"> -v </span><span class="hl-3">$(pwd)</span><span class="hl-1">/config.json:/app/config.json:ro \</span><br/><span class="hl-1"> sebbo2002/pyatv-mqtt-bridge \</span><br/><span class="hl-1"> pyatv-mqtt-bridge --debug /app/config.json</span>
52
- </code></pre>
53
-
54
- <a href="#how-can-i-send-commands-to-the-apple-tv" id="how-can-i-send-commands-to-the-apple-tv" style="color: inherit; text-decoration: none;">
55
- <h4>How can I send commands to the Apple TV?</h4>
56
- </a>
57
- <p>To execute a command send any message to the topic <code>$device/$command</code>. <code>$device</code> is the configured topic of the device
58
- and <code>$command</code> is a command from <a href="https://github.com/sebbo2002/node-pyatv/blob/develop/src/lib/types.ts#L49">this list</a>.
59
- Example: <code>/home/living/appletv/menu</code>.</p>
60
-
61
- <a href="#copyright-and-license" id="copyright-and-license" style="color: inherit; text-decoration: none;">
62
- <h2>Copyright and license</h2>
63
- </a>
64
- <p>Copyright (c) Sebastian Pekarek under the <a href="LICENSE">MIT license</a>.</p>
65
- </div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/default.html" class="tsd-kind-icon">default</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>
@@ -1 +0,0 @@
1
- <!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</title><meta name="description" content="Documentation for @sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@sebbo2002/pyatv-mqtt-bridge - v3.1.5-develop.3</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Classes</h3><ul class="tsd-index-list"><li class="tsd-kind-class"><a href="classes/default.html" class="tsd-kind-icon">default</a></li></ul></section></div></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/default.html" class="tsd-kind-icon">default</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>
package/src/bin/cli.ts DELETED
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- import {existsSync} from 'fs';
5
- import {resolve} from 'path';
6
- import PyAtvMqttBridge from '../lib/index';
7
- import {LogParam} from '../lib/types';
8
-
9
- console.log('# pyatv-mqtt-bridge');
10
- console.log('----------------------------');
11
-
12
- const debug = process.argv.indexOf('--debug') > -1;
13
- const configPath = resolve(process.cwd(), process.argv[process.argv.length - 1]);
14
- if (!existsSync(configPath)) {
15
- console.log('Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json');
16
- process.exit(1);
17
- }
18
-
19
- let config;
20
- try {
21
- config = require(configPath);
22
- }
23
- catch (err) {
24
- console.log('Unable to parse configuration file:');
25
- console.log(err);
26
- console.log('\nHave you removed the comments?\n');
27
- process.exit(1);
28
- }
29
-
30
- try {
31
- if (debug) {
32
- Object.assign(config, {
33
- log: (msg: LogParam) => {
34
- let string = `[${msg.level}]`;
35
- if (msg.host) {
36
- string += `[${msg.host}]`;
37
- }
38
- string += ' ';
39
- if (msg.message) {
40
- string += msg.message;
41
- }
42
- if (msg.message && msg.error) {
43
- string += ': ';
44
- }
45
- if (msg.error && msg.error.stack) {
46
- string += msg.error.stack;
47
- }
48
- if (msg.error) {
49
- string += msg.error.toString();
50
- }
51
-
52
- console.log(string);
53
- }
54
- });
55
- }
56
-
57
- new PyAtvMqttBridge(config);
58
- } catch (err) {
59
- console.log('Unable to start bridge:');
60
- console.log(err);
61
- }
package/src/lib/index.ts DELETED
@@ -1,170 +0,0 @@
1
- 'use strict';
2
-
3
- import {Config, ConfigDevice, LogParam} from './types';
4
- import {connect, MqttClient} from 'mqtt';
5
- import pyatv, {NodePyATVDeviceEvent, NodePyATVKeys} from '@sebbo2002/node-pyatv';
6
-
7
- export default class PyAtvMqttBridge {
8
- private mqttClient: MqttClient | null = null;
9
- private readonly options: Config;
10
- private readonly teardown: Array<() => Promise<void>> = [];
11
-
12
- constructor(options: Config) {
13
- if (typeof options.broker !== 'string') {
14
- throw new Error('options.broker is not set!');
15
- }
16
- if (!Array.isArray(options.devices) || !options.devices.length) {
17
- throw new Error('options.devices is not set!');
18
- }
19
- if (options.devices.find(d => typeof d.topic !== 'string')) {
20
- throw new Error('options.devices.topic is not set!');
21
- }
22
- if (options.devices.find(d => typeof d.host !== 'string')) {
23
- throw new Error('options.devices.host is not set!');
24
- }
25
- if (options.devices.find(d => typeof d.name !== 'string')) {
26
- throw new Error('options.devices.name is not set!');
27
- }
28
-
29
- this.options = options;
30
- this.teardown = [];
31
-
32
- this.start().catch(err => {
33
- this.log({
34
- level: 'error',
35
- host: null,
36
- message: 'Unable to start bridge',
37
- error: err
38
- });
39
- });
40
- }
41
-
42
- private log(msg: LogParam) {
43
- if (this.options.log) {
44
- try {
45
- this.options.log.apply(this, [msg]);
46
- } catch (err) {
47
- console.log('Unable to call custom log function:');
48
- console.log(err);
49
- }
50
- }
51
- }
52
-
53
- private async start() {
54
- const errorListener = (error: Error) => this.log({
55
- level: 'error',
56
- host: null,
57
- message: 'MQTT error',
58
- error
59
- });
60
-
61
- this.mqttClient = connect(this.options.broker);
62
- this.mqttClient.on('error', errorListener);
63
- this.teardown.unshift(async () => {
64
- if (this.mqttClient) {
65
- this.mqttClient.off('error', errorListener);
66
- await new Promise(resolve => {
67
- if (this.mqttClient) {
68
- this.mqttClient.end(false, () => resolve(undefined));
69
- }
70
- });
71
- }
72
- });
73
-
74
- await Promise.all(
75
- this.options.devices.map(device => this.startDevice(device))
76
- );
77
- }
78
-
79
- private async startDevice(device: ConfigDevice) {
80
- this.log({
81
- level: 'info',
82
- host: device.host,
83
- message: 'Setup device…'
84
- });
85
-
86
- const atv = pyatv.device(Object.assign({}, device, {
87
- debug: (message: string) => this.log({
88
- level: 'info',
89
- host: device.host,
90
- message
91
- })
92
- }));
93
-
94
-
95
- /* MQTT <-- PYATV */
96
-
97
- if (this.mqttClient) {
98
- this.mqttClient.publish(device.topic + '/host', device.host, {retain: true});
99
- this.mqttClient.publish(device.topic + '/name', device.name, {retain: true});
100
- this.mqttClient.publish(device.topic + '/id', device.id || '', {retain: true});
101
- }
102
-
103
- const updateListener = (event: NodePyATVDeviceEvent | Error) => {
104
- if(event instanceof NodePyATVDeviceEvent) {
105
- this.log({
106
- level: 'info',
107
- host: device.host,
108
- message: JSON.stringify(event)
109
- });
110
-
111
- if (this.mqttClient) {
112
- const value = event.value === null ? '' : String(event.value);
113
- this.mqttClient.publish(device.topic + '/' + event.key, value, {retain: true});
114
- }
115
- }
116
- };
117
- const errorListener = (error: Error | NodePyATVDeviceEvent) => {
118
- if (error instanceof Error) {
119
- this.log({
120
- level: 'error',
121
- host: device.host,
122
- message: 'Push Error',
123
- error
124
- });
125
- }
126
- };
127
-
128
- atv.on('update', updateListener);
129
- atv.on('error', errorListener);
130
- this.teardown.unshift(async () => {
131
- atv.off('update', updateListener);
132
- atv.off('error', errorListener);
133
- });
134
-
135
-
136
- /* MQTT --> PYATV */
137
-
138
- if (this.mqttClient) {
139
- this.mqttClient.subscribe(device.topic + '/+');
140
- this.teardown.unshift(() => {
141
- return new Promise(resolve => {
142
- if(this.mqttClient) {
143
- this.mqttClient.unsubscribe(device.topic + '/+', resolve);
144
- }
145
- });
146
- });
147
-
148
- this.mqttClient.on('message', topic => {
149
- const key = Object
150
- .keys(NodePyATVKeys)
151
- .find(key => device.topic + '/' + key === topic) as NodePyATVKeys | undefined;
152
-
153
- if(key) {
154
- atv.pressKey(key).catch(error => {
155
- this.log({
156
- level: 'error',
157
- host: device.host,
158
- message: `Unable to press key "${key}"`,
159
- error
160
- });
161
- });
162
- }
163
- });
164
- }
165
- }
166
-
167
- async stop(): Promise<void> {
168
- await Promise.all(this.teardown);
169
- }
170
- }
package/src/lib/types.ts DELETED
@@ -1,18 +0,0 @@
1
- import {NodePyATVDeviceOptions} from '@sebbo2002/node-pyatv';
2
-
3
- export interface Config {
4
- broker: string;
5
- log?: (msg: LogParam) => (void),
6
- devices: ConfigDevice[];
7
- }
8
-
9
- export interface ConfigDevice extends NodePyATVDeviceOptions {
10
- topic: string;
11
- }
12
-
13
- export interface LogParam {
14
- level: string;
15
- host: string | null;
16
- message: string;
17
- error?: Error;
18
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "esModuleInterop": true,
5
- "module": "none",
6
- "moduleResolution": "node",
7
- "outDir": "./dist",
8
- "sourceMap": true,
9
- "strict": true,
10
- "target": "es6"
11
- },
12
- "exclude": [
13
- "node_modules",
14
- "**/*.spec.ts"
15
- ],
16
- "include": [
17
- "src/**/*"
18
- ]
19
- }
package/typedoc.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "entryPoints": ["./src/lib/index.ts"],
3
- "exclude": [],
4
- "excludeInternal": true,
5
- "excludePrivate": true,
6
- "excludeProtected": true,
7
- "includeVersion": true,
8
- "name": "",
9
- "out": "./docs/reference",
10
- "plugin": [],
11
- "readme": "README.md",
12
- "theme": "default"
13
- }