@sebbo2002/pyatv-mqtt-bridge 5.0.0-develop.1 → 5.0.0-develop.2

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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var b=Object.create;var u=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var E=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of q(t))!P.call(o,s)&&s!==e&&u(o,s,{get:()=>t[s],enumerable:!(i=C(t,s))||i.enumerable});return o};var k=(o,t,e)=>(e=o!=null?b(w(o)):{},E(t||!o||!o.__esModule?u(e,"default",{value:o,enumerable:!0}):e,o));var c=(o,t,e)=>new Promise((i,s)=>{var r=a=>{try{l(e.next(a))}catch(p){s(p)}},n=a=>{try{l(e.throw(a))}catch(p){s(p)}},l=a=>a.done?i(a.value):Promise.resolve(a.value).then(r,n);l((e=e.apply(o,t)).next())});var g=require("fs"),y=require("path");var d=require("mqtt"),h=k(require("@sebbo2002/node-pyatv"),1);var f=class{constructor(t){this.mqttClient=null;this.teardown=[];if(typeof t.broker!="string")throw new Error("options.broker is not set!");if(!Array.isArray(t.devices)||!t.devices.length)throw new Error("options.devices is not set!");if(t.devices.find(e=>typeof e.topic!="string"))throw new Error("options.devices.topic is not set!");if(t.devices.find(e=>typeof e.host!="string"))throw new Error("options.devices.host is not set!");if(t.devices.find(e=>typeof e.name!="string"))throw new Error("options.devices.name is not set!");this.options=t,this.teardown=[],this.start().catch(e=>{this.log({level:"error",host:null,message:"Unable to start bridge",error:e})})}log(t){if(this.options.log)try{this.options.log.apply(this,[t])}catch(e){console.log("Unable to call custom log function:"),console.log(e)}}start(){return c(this,null,function*(){let t=e=>this.log({level:"error",host:null,message:"MQTT error",error:e});this.mqttClient=(0,d.connect)(this.options.broker),this.mqttClient.on("error",t),this.teardown.unshift(()=>c(this,null,function*(){this.mqttClient&&(this.mqttClient.off("error",t),yield new Promise(e=>{this.mqttClient&&this.mqttClient.end(!1,()=>e(void 0))}))})),yield Promise.all(this.options.devices.map(e=>this.startDevice(e)))})}startDevice(t){return c(this,null,function*(){this.log({level:"info",host:t.host,message:"Setup device\u2026"});let e=h.default.device(Object.assign({},t,{debug:r=>this.log({level:"info",host:t.host,message:r})}));this.mqttClient&&(this.mqttClient.publish(t.topic+"/host",t.host,{retain:!0}),this.mqttClient.publish(t.topic+"/name",t.name,{retain:!0}),this.mqttClient.publish(t.topic+"/id",t.id||"",{retain:!0}));let i=r=>{if(r instanceof h.NodePyATVDeviceEvent&&(this.log({level:"info",host:t.host,message:JSON.stringify(r)}),this.mqttClient)){let n=r.value===null?"":String(r.value);this.mqttClient.publish(t.topic+"/"+r.key,n,{retain:!0})}},s=r=>{r instanceof Error&&this.log({level:"error",host:t.host,message:"Push Error",error:r})};e.on("update",i),e.on("error",s),this.teardown.unshift(()=>c(this,null,function*(){e.off("update",i),e.off("error",s)})),this.mqttClient&&(this.mqttClient.subscribe(t.topic+"/+"),this.teardown.unshift(()=>new Promise(r=>{this.mqttClient&&this.mqttClient.unsubscribe(t.topic+"/+",r)})),this.mqttClient.on("message",r=>{let n=Object.keys(h.NodePyATVKeys).find(l=>t.topic+"/"+l===r);n&&e.pressKey(n).catch(l=>{this.log({level:"error",host:t.host,message:`Unable to press key "${n}"`,error:l})})}))})}stop(){return c(this,null,function*(){yield Promise.all(this.teardown)})}};console.log("# pyatv-mqtt-bridge");console.log("----------------------------");var A=process.argv.indexOf("--debug")>-1,v=(0,y.resolve)(process.cwd(),process.argv[process.argv.length-1]);(0,g.existsSync)(v)||(console.log("Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json"),process.exit(1));var m;try{m=JSON.parse((0,g.readFileSync)(v,"utf8"))}catch(o){console.log("Unable to parse configuration file:"),console.log(o),console.log(`
3
+ Have you removed the comments?
4
+ `),process.exit(1)}try{A&&Object.assign(m,{log:o=>{let t=`[${o.level}]`;o.host&&(t+=`[${o.host}]`),t+=" ",o.message&&(t+=o.message),o.message&&o.error&&(t+=": "),o.error&&o.error.stack&&(t+=o.error.stack),o.error&&(t+=o.error.toString()),console.log(t)}}),new f(m)}catch(o){console.log("Unable to start bridge:"),console.log(o)}
5
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bin/cli.ts","../../src/lib/index.ts"],"sourcesContent":["#!/usr/bin/env node\n'use strict';\n\nimport {existsSync, readFileSync} from 'fs';\nimport {resolve} from 'path';\nimport PyAtvMqttBridge from '../lib/index.js';\nimport {LogParam} from '../lib/types.js';\n\nconsole.log('# pyatv-mqtt-bridge');\nconsole.log('----------------------------');\n\nconst debug = process.argv.indexOf('--debug') > -1;\nconst configPath = resolve(process.cwd(), process.argv[process.argv.length - 1]);\nif (!existsSync(configPath)) {\n console.log('Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json');\n process.exit(1);\n}\n\nlet config;\ntry {\n config = JSON.parse(readFileSync(configPath, 'utf8'));\n}\ncatch (err) {\n console.log('Unable to parse configuration file:');\n console.log(err);\n console.log('\\nHave you removed the comments?\\n');\n process.exit(1);\n}\n\ntry {\n if (debug) {\n Object.assign(config, {\n log: (msg: LogParam) => {\n let string = `[${msg.level}]`;\n if (msg.host) {\n string += `[${msg.host}]`;\n }\n string += ' ';\n if (msg.message) {\n string += msg.message;\n }\n if (msg.message && msg.error) {\n string += ': ';\n }\n if (msg.error && msg.error.stack) {\n string += msg.error.stack;\n }\n if (msg.error) {\n string += msg.error.toString();\n }\n\n console.log(string);\n }\n });\n }\n\n new PyAtvMqttBridge(config);\n} catch (err) {\n console.log('Unable to start bridge:');\n console.log(err);\n}\n","'use strict';\n\nimport {Config, ConfigDevice, LogParam} from './types.js';\nimport {connect, MqttClient} from 'mqtt';\nimport pyatv, {NodePyATVDeviceEvent, NodePyATVKeys} from '@sebbo2002/node-pyatv';\n\nexport default class PyAtvMqttBridge {\n private mqttClient: MqttClient | null = null;\n private readonly options: Config;\n private readonly teardown: Array<() => Promise<void>> = [];\n\n constructor(options: Config) {\n if (typeof options.broker !== 'string') {\n throw new Error('options.broker is not set!');\n }\n if (!Array.isArray(options.devices) || !options.devices.length) {\n throw new Error('options.devices is not set!');\n }\n if (options.devices.find(d => typeof d.topic !== 'string')) {\n throw new Error('options.devices.topic is not set!');\n }\n if (options.devices.find(d => typeof d.host !== 'string')) {\n throw new Error('options.devices.host is not set!');\n }\n if (options.devices.find(d => typeof d.name !== 'string')) {\n throw new Error('options.devices.name is not set!');\n }\n\n this.options = options;\n this.teardown = [];\n\n this.start().catch(err => {\n this.log({\n level: 'error',\n host: null,\n message: 'Unable to start bridge',\n error: err\n });\n });\n }\n\n private log(msg: LogParam) {\n if (this.options.log) {\n try {\n this.options.log.apply(this, [msg]);\n } catch (err) {\n console.log('Unable to call custom log function:');\n console.log(err);\n }\n }\n }\n\n private async start() {\n const errorListener = (error: Error) => this.log({\n level: 'error',\n host: null,\n message: 'MQTT error',\n error\n });\n\n this.mqttClient = connect(this.options.broker);\n this.mqttClient.on('error', errorListener);\n this.teardown.unshift(async () => {\n if (this.mqttClient) {\n this.mqttClient.off('error', errorListener);\n await new Promise(resolve => {\n if (this.mqttClient) {\n this.mqttClient.end(false, () => resolve(undefined));\n }\n });\n }\n });\n\n await Promise.all(\n this.options.devices.map(device => this.startDevice(device))\n );\n }\n\n private async startDevice(device: ConfigDevice) {\n this.log({\n level: 'info',\n host: device.host,\n message: 'Setup device…'\n });\n\n const atv = pyatv.device(Object.assign({}, device, {\n debug: (message: string) => this.log({\n level: 'info',\n host: device.host,\n message\n })\n }));\n\n\n /* MQTT <-- PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.publish(device.topic + '/host', device.host, {retain: true});\n this.mqttClient.publish(device.topic + '/name', device.name, {retain: true});\n this.mqttClient.publish(device.topic + '/id', device.id || '', {retain: true});\n }\n\n const updateListener = (event: NodePyATVDeviceEvent | Error) => {\n if(event instanceof NodePyATVDeviceEvent) {\n this.log({\n level: 'info',\n host: device.host,\n message: JSON.stringify(event)\n });\n\n if (this.mqttClient) {\n const value = event.value === null ? '' : String(event.value);\n this.mqttClient.publish(device.topic + '/' + event.key, value, {retain: true});\n }\n }\n };\n const errorListener = (error: Error | NodePyATVDeviceEvent) => {\n if (error instanceof Error) {\n this.log({\n level: 'error',\n host: device.host,\n message: 'Push Error',\n error\n });\n }\n };\n\n atv.on('update', updateListener);\n atv.on('error', errorListener);\n this.teardown.unshift(async () => {\n atv.off('update', updateListener);\n atv.off('error', errorListener);\n });\n\n\n /* MQTT --> PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.subscribe(device.topic + '/+');\n this.teardown.unshift(() => {\n return new Promise(resolve => {\n if(this.mqttClient) {\n this.mqttClient.unsubscribe(device.topic + '/+', resolve);\n }\n });\n });\n\n this.mqttClient.on('message', topic => {\n const key = Object\n .keys(NodePyATVKeys)\n .find(key => device.topic + '/' + key === topic) as NodePyATVKeys | undefined;\n\n if(key) {\n atv.pressKey(key).catch(error => {\n this.log({\n level: 'error',\n host: device.host,\n message: `Unable to press key \"${key}\"`,\n error\n });\n });\n }\n });\n }\n }\n\n async stop(): Promise<void> {\n await Promise.all(this.teardown);\n }\n}\n"],"mappings":";qqBAGA,IAAAA,EAAuC,cACvCC,EAAsB,gBCDtB,IAAAC,EAAkC,gBAClCC,EAAyD,sCAEzD,IAAqBC,EAArB,KAAqC,CAKjC,YAAYC,EAAiB,CAJ7B,KAAQ,WAAgC,KAExC,KAAiB,SAAuC,CAAC,EAGrD,GAAI,OAAOA,EAAQ,QAAW,SAC1B,MAAM,IAAI,MAAM,4BAA4B,EAEhD,GAAI,CAAC,MAAM,QAAQA,EAAQ,OAAO,GAAK,CAACA,EAAQ,QAAQ,OACpD,MAAM,IAAI,MAAM,6BAA6B,EAEjD,GAAIA,EAAQ,QAAQ,KAAKC,GAAK,OAAO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AAIC,CAAM,CACtB,CACJ,CAAC,EAGL,IAAIC,EAAgBJ,CAAM,CAC9B,OAASC,EAAP,CACE,QAAQ,IAAI,yBAAyB,EACrC,QAAQ,IAAIA,CAAG,CACnB","names":["import_fs","import_path","import_mqtt","import_node_pyatv","PyAtvMqttBridge","options","d","err","msg","__async","errorListener","error","resolve","device","atv","pyatv","message","updateListener","event","value","topic","key","debug","configPath","config","err","msg","string","PyAtvMqttBridge"]}
package/dist/bin/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  #!/usr/bin/env node
2
- export {};
package/dist/bin/cli.js CHANGED
@@ -1,55 +1,5 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
- import { existsSync, readFileSync } from 'fs';
4
- import { resolve } from 'path';
5
- import PyAtvMqttBridge from '../lib/index.js';
6
- console.log('# pyatv-mqtt-bridge');
7
- console.log('----------------------------');
8
- const debug = process.argv.indexOf('--debug') > -1;
9
- const configPath = resolve(process.cwd(), process.argv[process.argv.length - 1]);
10
- if (!existsSync(configPath)) {
11
- console.log('Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json');
12
- process.exit(1);
13
- }
14
- let config;
15
- try {
16
- config = JSON.parse(readFileSync(configPath, 'utf8'));
17
- }
18
- catch (err) {
19
- console.log('Unable to parse configuration file:');
20
- console.log(err);
21
- console.log('\nHave you removed the comments?\n');
22
- process.exit(1);
23
- }
24
- try {
25
- if (debug) {
26
- Object.assign(config, {
27
- log: (msg) => {
28
- let string = `[${msg.level}]`;
29
- if (msg.host) {
30
- string += `[${msg.host}]`;
31
- }
32
- string += ' ';
33
- if (msg.message) {
34
- string += msg.message;
35
- }
36
- if (msg.message && msg.error) {
37
- string += ': ';
38
- }
39
- if (msg.error && msg.error.stack) {
40
- string += msg.error.stack;
41
- }
42
- if (msg.error) {
43
- string += msg.error.toString();
44
- }
45
- console.log(string);
46
- }
47
- });
48
- }
49
- new PyAtvMqttBridge(config);
50
- }
51
- catch (err) {
52
- console.log('Unable to start bridge:');
53
- console.log(err);
54
- }
2
+ import{a as t}from"../chunk-OEFAITBU.js";import{existsSync as c,readFileSync as n}from"fs";import{resolve as i}from"path";console.log("# pyatv-mqtt-bridge");console.log("----------------------------");var l=process.argv.indexOf("--debug")>-1,s=i(process.cwd(),process.argv[process.argv.length-1]);c(s)||(console.log("Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json"),process.exit(1));var r;try{r=JSON.parse(n(s,"utf8"))}catch(o){console.log("Unable to parse configuration file:"),console.log(o),console.log(`
3
+ Have you removed the comments?
4
+ `),process.exit(1)}try{l&&Object.assign(r,{log:o=>{let e=`[${o.level}]`;o.host&&(e+=`[${o.host}]`),e+=" ",o.message&&(e+=o.message),o.message&&o.error&&(e+=": "),o.error&&o.error.stack&&(e+=o.error.stack),o.error&&(e+=o.error.toString()),console.log(e)}}),new t(r)}catch(o){console.log("Unable to start bridge:"),console.log(o)}
55
5
  //# sourceMappingURL=cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";AACA,YAAY,CAAC;AAEb,OAAO,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAG9C,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AACnC,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AACnD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AACjF,IAAI,CAAC,UAA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,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC;SACJ,CAAC,CAAC;KACN;IAED,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;CAC/B;AAAC,OAAO,GAAG,EAAE;IACV,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACpB"}
1
+ {"version":3,"sources":["../../src/bin/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n'use strict';\n\nimport {existsSync, readFileSync} from 'fs';\nimport {resolve} from 'path';\nimport PyAtvMqttBridge from '../lib/index.js';\nimport {LogParam} from '../lib/types.js';\n\nconsole.log('# pyatv-mqtt-bridge');\nconsole.log('----------------------------');\n\nconst debug = process.argv.indexOf('--debug') > -1;\nconst configPath = resolve(process.cwd(), process.argv[process.argv.length - 1]);\nif (!existsSync(configPath)) {\n console.log('Usage: pyatv-mqtt-bridge [--debug] ~/pyatv-mqtt-bridge-config.json');\n process.exit(1);\n}\n\nlet config;\ntry {\n config = JSON.parse(readFileSync(configPath, 'utf8'));\n}\ncatch (err) {\n console.log('Unable to parse configuration file:');\n console.log(err);\n console.log('\\nHave you removed the comments?\\n');\n process.exit(1);\n}\n\ntry {\n if (debug) {\n Object.assign(config, {\n log: (msg: LogParam) => {\n let string = `[${msg.level}]`;\n if (msg.host) {\n string += `[${msg.host}]`;\n }\n string += ' ';\n if (msg.message) {\n string += msg.message;\n }\n if (msg.message && msg.error) {\n string += ': ';\n }\n if (msg.error && msg.error.stack) {\n string += msg.error.stack;\n }\n if (msg.error) {\n string += msg.error.toString();\n }\n\n console.log(string);\n }\n });\n }\n\n new PyAtvMqttBridge(config);\n} catch (err) {\n console.log('Unable to start bridge:');\n console.log(err);\n}\n"],"mappings":";yCAGA,OAAQ,cAAAA,EAAY,gBAAAC,MAAmB,KACvC,OAAQ,WAAAC,MAAc,OAItB,QAAQ,IAAI,qBAAqB,EACjC,QAAQ,IAAI,8BAA8B,EAE1C,IAAMC,EAAQ,QAAQ,KAAK,QAAQ,SAAS,EAAI,GAC1CC,EAAaC,EAAQ,QAAQ,IAAI,EAAG,QAAQ,KAAK,QAAQ,KAAK,OAAS,CAAC,CAAC,EAC1EC,EAAWF,CAAU,IACtB,QAAQ,IAAI,oEAAoE,EAChF,QAAQ,KAAK,CAAC,GAGlB,IAAIG,EACJ,GAAI,CACAA,EAAS,KAAK,MAAMC,EAAaJ,EAAY,MAAM,CAAC,CACxD,OACOK,EAAP,CACI,QAAQ,IAAI,qCAAqC,EACjD,QAAQ,IAAIA,CAAG,EACf,QAAQ,IAAI;AAAA;AAAA,CAAoC,EAChD,QAAQ,KAAK,CAAC,CAClB,CAEA,GAAI,CACIN,GACA,OAAO,OAAOI,EAAQ,CAClB,IAAMG,GAAkB,CACpB,IAAIC,EAAS,IAAID,EAAI,SACjBA,EAAI,OACJC,GAAU,IAAID,EAAI,SAEtBC,GAAU,IACND,EAAI,UACJC,GAAUD,EAAI,SAEdA,EAAI,SAAWA,EAAI,QACnBC,GAAU,MAEVD,EAAI,OAASA,EAAI,MAAM,QACvBC,GAAUD,EAAI,MAAM,OAEpBA,EAAI,QACJC,GAAUD,EAAI,MAAM,SAAS,GAGjC,QAAQ,IAAIC,CAAM,CACtB,CACJ,CAAC,EAGL,IAAIC,EAAgBL,CAAM,CAC9B,OAASE,EAAP,CACE,QAAQ,IAAI,yBAAyB,EACrC,QAAQ,IAAIA,CAAG,CACnB","names":["existsSync","readFileSync","resolve","debug","configPath","resolve","existsSync","config","readFileSync","err","msg","string","PyAtvMqttBridge"]}
@@ -0,0 +1,2 @@
1
+ var n=(c,t,e)=>new Promise((a,l)=>{var i=r=>{try{o(e.next(r))}catch(h){l(h)}},s=r=>{try{o(e.throw(r))}catch(h){l(h)}},o=r=>r.done?a(r.value):Promise.resolve(r.value).then(i,s);o((e=e.apply(c,t)).next())});import{connect as m}from"mqtt";import p,{NodePyATVDeviceEvent as g,NodePyATVKeys as u}from"@sebbo2002/node-pyatv";var f=class{constructor(t){this.mqttClient=null;this.teardown=[];if(typeof t.broker!="string")throw new Error("options.broker is not set!");if(!Array.isArray(t.devices)||!t.devices.length)throw new Error("options.devices is not set!");if(t.devices.find(e=>typeof e.topic!="string"))throw new Error("options.devices.topic is not set!");if(t.devices.find(e=>typeof e.host!="string"))throw new Error("options.devices.host is not set!");if(t.devices.find(e=>typeof e.name!="string"))throw new Error("options.devices.name is not set!");this.options=t,this.teardown=[],this.start().catch(e=>{this.log({level:"error",host:null,message:"Unable to start bridge",error:e})})}log(t){if(this.options.log)try{this.options.log.apply(this,[t])}catch(e){console.log("Unable to call custom log function:"),console.log(e)}}start(){return n(this,null,function*(){let t=e=>this.log({level:"error",host:null,message:"MQTT error",error:e});this.mqttClient=m(this.options.broker),this.mqttClient.on("error",t),this.teardown.unshift(()=>n(this,null,function*(){this.mqttClient&&(this.mqttClient.off("error",t),yield new Promise(e=>{this.mqttClient&&this.mqttClient.end(!1,()=>e(void 0))}))})),yield Promise.all(this.options.devices.map(e=>this.startDevice(e)))})}startDevice(t){return n(this,null,function*(){this.log({level:"info",host:t.host,message:"Setup device\u2026"});let e=p.device(Object.assign({},t,{debug:i=>this.log({level:"info",host:t.host,message:i})}));this.mqttClient&&(this.mqttClient.publish(t.topic+"/host",t.host,{retain:!0}),this.mqttClient.publish(t.topic+"/name",t.name,{retain:!0}),this.mqttClient.publish(t.topic+"/id",t.id||"",{retain:!0}));let a=i=>{if(i instanceof g&&(this.log({level:"info",host:t.host,message:JSON.stringify(i)}),this.mqttClient)){let s=i.value===null?"":String(i.value);this.mqttClient.publish(t.topic+"/"+i.key,s,{retain:!0})}},l=i=>{i instanceof Error&&this.log({level:"error",host:t.host,message:"Push Error",error:i})};e.on("update",a),e.on("error",l),this.teardown.unshift(()=>n(this,null,function*(){e.off("update",a),e.off("error",l)})),this.mqttClient&&(this.mqttClient.subscribe(t.topic+"/+"),this.teardown.unshift(()=>new Promise(i=>{this.mqttClient&&this.mqttClient.unsubscribe(t.topic+"/+",i)})),this.mqttClient.on("message",i=>{let s=Object.keys(u).find(o=>t.topic+"/"+o===i);s&&e.pressKey(s).catch(o=>{this.log({level:"error",host:t.host,message:`Unable to press key "${s}"`,error:o})})}))})}stop(){return n(this,null,function*(){yield Promise.all(this.teardown)})}};export{f as a};
2
+ //# sourceMappingURL=chunk-OEFAITBU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/index.ts"],"sourcesContent":["'use strict';\n\nimport {Config, ConfigDevice, LogParam} from './types.js';\nimport {connect, MqttClient} from 'mqtt';\nimport pyatv, {NodePyATVDeviceEvent, NodePyATVKeys} from '@sebbo2002/node-pyatv';\n\nexport default class PyAtvMqttBridge {\n private mqttClient: MqttClient | null = null;\n private readonly options: Config;\n private readonly teardown: Array<() => Promise<void>> = [];\n\n constructor(options: Config) {\n if (typeof options.broker !== 'string') {\n throw new Error('options.broker is not set!');\n }\n if (!Array.isArray(options.devices) || !options.devices.length) {\n throw new Error('options.devices is not set!');\n }\n if (options.devices.find(d => typeof d.topic !== 'string')) {\n throw new Error('options.devices.topic is not set!');\n }\n if (options.devices.find(d => typeof d.host !== 'string')) {\n throw new Error('options.devices.host is not set!');\n }\n if (options.devices.find(d => typeof d.name !== 'string')) {\n throw new Error('options.devices.name is not set!');\n }\n\n this.options = options;\n this.teardown = [];\n\n this.start().catch(err => {\n this.log({\n level: 'error',\n host: null,\n message: 'Unable to start bridge',\n error: err\n });\n });\n }\n\n private log(msg: LogParam) {\n if (this.options.log) {\n try {\n this.options.log.apply(this, [msg]);\n } catch (err) {\n console.log('Unable to call custom log function:');\n console.log(err);\n }\n }\n }\n\n private async start() {\n const errorListener = (error: Error) => this.log({\n level: 'error',\n host: null,\n message: 'MQTT error',\n error\n });\n\n this.mqttClient = connect(this.options.broker);\n this.mqttClient.on('error', errorListener);\n this.teardown.unshift(async () => {\n if (this.mqttClient) {\n this.mqttClient.off('error', errorListener);\n await new Promise(resolve => {\n if (this.mqttClient) {\n this.mqttClient.end(false, () => resolve(undefined));\n }\n });\n }\n });\n\n await Promise.all(\n this.options.devices.map(device => this.startDevice(device))\n );\n }\n\n private async startDevice(device: ConfigDevice) {\n this.log({\n level: 'info',\n host: device.host,\n message: 'Setup device…'\n });\n\n const atv = pyatv.device(Object.assign({}, device, {\n debug: (message: string) => this.log({\n level: 'info',\n host: device.host,\n message\n })\n }));\n\n\n /* MQTT <-- PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.publish(device.topic + '/host', device.host, {retain: true});\n this.mqttClient.publish(device.topic + '/name', device.name, {retain: true});\n this.mqttClient.publish(device.topic + '/id', device.id || '', {retain: true});\n }\n\n const updateListener = (event: NodePyATVDeviceEvent | Error) => {\n if(event instanceof NodePyATVDeviceEvent) {\n this.log({\n level: 'info',\n host: device.host,\n message: JSON.stringify(event)\n });\n\n if (this.mqttClient) {\n const value = event.value === null ? '' : String(event.value);\n this.mqttClient.publish(device.topic + '/' + event.key, value, {retain: true});\n }\n }\n };\n const errorListener = (error: Error | NodePyATVDeviceEvent) => {\n if (error instanceof Error) {\n this.log({\n level: 'error',\n host: device.host,\n message: 'Push Error',\n error\n });\n }\n };\n\n atv.on('update', updateListener);\n atv.on('error', errorListener);\n this.teardown.unshift(async () => {\n atv.off('update', updateListener);\n atv.off('error', errorListener);\n });\n\n\n /* MQTT --> PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.subscribe(device.topic + '/+');\n this.teardown.unshift(() => {\n return new Promise(resolve => {\n if(this.mqttClient) {\n this.mqttClient.unsubscribe(device.topic + '/+', resolve);\n }\n });\n });\n\n this.mqttClient.on('message', topic => {\n const key = Object\n .keys(NodePyATVKeys)\n .find(key => device.topic + '/' + key === topic) as NodePyATVKeys | undefined;\n\n if(key) {\n atv.pressKey(key).catch(error => {\n this.log({\n level: 'error',\n host: device.host,\n message: `Unable to press key \"${key}\"`,\n error\n });\n });\n }\n });\n }\n }\n\n async stop(): Promise<void> {\n await Promise.all(this.teardown);\n }\n}\n"],"mappings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ACP,KAAMG,EAAO,KACb,QAAS,aACT,MAAAH,CACJ,CAAC,CAET,EAEAI,EAAI,GAAG,SAAUG,CAAc,EAC/BH,EAAI,GAAG,QAASL,CAAa,EAC7B,KAAK,SAAS,QAAQ,IAAYD,EAAA,sBAC9BM,EAAI,IAAI,SAAUG,CAAc,EAChCH,EAAI,IAAI,QAASL,CAAa,CAClC,EAAC,EAKG,KAAK,aACL,KAAK,WAAW,UAAUI,EAAO,MAAQ,IAAI,EAC7C,KAAK,SAAS,QAAQ,IACX,IAAI,QAAQD,GAAW,CACvB,KAAK,YACJ,KAAK,WAAW,YAAYC,EAAO,MAAQ,KAAMD,CAAO,CAEhE,CAAC,CACJ,EAED,KAAK,WAAW,GAAG,UAAWS,GAAS,CACnC,IAAMC,EAAM,OACP,KAAKC,CAAa,EAClB,KAAKD,GAAOT,EAAO,MAAQ,IAAMS,IAAQD,CAAK,EAEhDC,GACCR,EAAI,SAASQ,CAAG,EAAE,MAAMZ,GAAS,CAC7B,KAAK,IAAI,CACL,MAAO,QACP,KAAMG,EAAO,KACb,QAAS,wBAAwBS,KACjC,MAAAZ,CACJ,CAAC,CACL,CAAC,CAET,CAAC,EAET,GAEM,MAAsB,QAAAF,EAAA,sBACxB,MAAM,QAAQ,IAAI,KAAK,QAAQ,CACnC,GACJ","names":["connect","pyatv","NodePyATVDeviceEvent","NodePyATVKeys","PyAtvMqttBridge","options","d","err","msg","__async","errorListener","error","connect","resolve","device","atv","pyatv","message","updateListener","event","NodePyATVDeviceEvent","value","topic","key","NodePyATVKeys"]}
@@ -0,0 +1,2 @@
1
+ "use strict";var y=Object.create;var c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var q=(i,t)=>{for(var e in t)c(i,e,{get:t[e],enumerable:!0})},g=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!w.call(i,o)&&o!==e&&c(i,o,{get:()=>t[o],enumerable:!(r=d(t,o))||r.enumerable});return i};var b=(i,t,e)=>(e=i!=null?y(v(i)):{},g(t||!i||!i.__esModule?c(e,"default",{value:i,enumerable:!0}):e,i)),E=i=>g(c({},"__esModule",{value:!0}),i);var h=(i,t,e)=>new Promise((r,o)=>{var s=a=>{try{l(e.next(a))}catch(p){o(p)}},n=a=>{try{l(e.throw(a))}catch(p){o(p)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,n);l((e=e.apply(i,t)).next())});var P={};q(P,{default:()=>m});module.exports=E(P);var u=require("mqtt"),f=b(require("@sebbo2002/node-pyatv"),1);var m=class{constructor(t){this.mqttClient=null;this.teardown=[];if(typeof t.broker!="string")throw new Error("options.broker is not set!");if(!Array.isArray(t.devices)||!t.devices.length)throw new Error("options.devices is not set!");if(t.devices.find(e=>typeof e.topic!="string"))throw new Error("options.devices.topic is not set!");if(t.devices.find(e=>typeof e.host!="string"))throw new Error("options.devices.host is not set!");if(t.devices.find(e=>typeof e.name!="string"))throw new Error("options.devices.name is not set!");this.options=t,this.teardown=[],this.start().catch(e=>{this.log({level:"error",host:null,message:"Unable to start bridge",error:e})})}log(t){if(this.options.log)try{this.options.log.apply(this,[t])}catch(e){console.log("Unable to call custom log function:"),console.log(e)}}start(){return h(this,null,function*(){let t=e=>this.log({level:"error",host:null,message:"MQTT error",error:e});this.mqttClient=(0,u.connect)(this.options.broker),this.mqttClient.on("error",t),this.teardown.unshift(()=>h(this,null,function*(){this.mqttClient&&(this.mqttClient.off("error",t),yield new Promise(e=>{this.mqttClient&&this.mqttClient.end(!1,()=>e(void 0))}))})),yield Promise.all(this.options.devices.map(e=>this.startDevice(e)))})}startDevice(t){return h(this,null,function*(){this.log({level:"info",host:t.host,message:"Setup device\u2026"});let e=f.default.device(Object.assign({},t,{debug:s=>this.log({level:"info",host:t.host,message:s})}));this.mqttClient&&(this.mqttClient.publish(t.topic+"/host",t.host,{retain:!0}),this.mqttClient.publish(t.topic+"/name",t.name,{retain:!0}),this.mqttClient.publish(t.topic+"/id",t.id||"",{retain:!0}));let r=s=>{if(s instanceof f.NodePyATVDeviceEvent&&(this.log({level:"info",host:t.host,message:JSON.stringify(s)}),this.mqttClient)){let n=s.value===null?"":String(s.value);this.mqttClient.publish(t.topic+"/"+s.key,n,{retain:!0})}},o=s=>{s instanceof Error&&this.log({level:"error",host:t.host,message:"Push Error",error:s})};e.on("update",r),e.on("error",o),this.teardown.unshift(()=>h(this,null,function*(){e.off("update",r),e.off("error",o)})),this.mqttClient&&(this.mqttClient.subscribe(t.topic+"/+"),this.teardown.unshift(()=>new Promise(s=>{this.mqttClient&&this.mqttClient.unsubscribe(t.topic+"/+",s)})),this.mqttClient.on("message",s=>{let n=Object.keys(f.NodePyATVKeys).find(l=>t.topic+"/"+l===s);n&&e.pressKey(n).catch(l=>{this.log({level:"error",host:t.host,message:`Unable to press key "${n}"`,error:l})})}))})}stop(){return h(this,null,function*(){yield Promise.all(this.teardown)})}};0&&(module.exports={});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/index.ts"],"sourcesContent":["'use strict';\n\nimport {Config, ConfigDevice, LogParam} from './types.js';\nimport {connect, MqttClient} from 'mqtt';\nimport pyatv, {NodePyATVDeviceEvent, NodePyATVKeys} from '@sebbo2002/node-pyatv';\n\nexport default class PyAtvMqttBridge {\n private mqttClient: MqttClient | null = null;\n private readonly options: Config;\n private readonly teardown: Array<() => Promise<void>> = [];\n\n constructor(options: Config) {\n if (typeof options.broker !== 'string') {\n throw new Error('options.broker is not set!');\n }\n if (!Array.isArray(options.devices) || !options.devices.length) {\n throw new Error('options.devices is not set!');\n }\n if (options.devices.find(d => typeof d.topic !== 'string')) {\n throw new Error('options.devices.topic is not set!');\n }\n if (options.devices.find(d => typeof d.host !== 'string')) {\n throw new Error('options.devices.host is not set!');\n }\n if (options.devices.find(d => typeof d.name !== 'string')) {\n throw new Error('options.devices.name is not set!');\n }\n\n this.options = options;\n this.teardown = [];\n\n this.start().catch(err => {\n this.log({\n level: 'error',\n host: null,\n message: 'Unable to start bridge',\n error: err\n });\n });\n }\n\n private log(msg: LogParam) {\n if (this.options.log) {\n try {\n this.options.log.apply(this, [msg]);\n } catch (err) {\n console.log('Unable to call custom log function:');\n console.log(err);\n }\n }\n }\n\n private async start() {\n const errorListener = (error: Error) => this.log({\n level: 'error',\n host: null,\n message: 'MQTT error',\n error\n });\n\n this.mqttClient = connect(this.options.broker);\n this.mqttClient.on('error', errorListener);\n this.teardown.unshift(async () => {\n if (this.mqttClient) {\n this.mqttClient.off('error', errorListener);\n await new Promise(resolve => {\n if (this.mqttClient) {\n this.mqttClient.end(false, () => resolve(undefined));\n }\n });\n }\n });\n\n await Promise.all(\n this.options.devices.map(device => this.startDevice(device))\n );\n }\n\n private async startDevice(device: ConfigDevice) {\n this.log({\n level: 'info',\n host: device.host,\n message: 'Setup device…'\n });\n\n const atv = pyatv.device(Object.assign({}, device, {\n debug: (message: string) => this.log({\n level: 'info',\n host: device.host,\n message\n })\n }));\n\n\n /* MQTT <-- PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.publish(device.topic + '/host', device.host, {retain: true});\n this.mqttClient.publish(device.topic + '/name', device.name, {retain: true});\n this.mqttClient.publish(device.topic + '/id', device.id || '', {retain: true});\n }\n\n const updateListener = (event: NodePyATVDeviceEvent | Error) => {\n if(event instanceof NodePyATVDeviceEvent) {\n this.log({\n level: 'info',\n host: device.host,\n message: JSON.stringify(event)\n });\n\n if (this.mqttClient) {\n const value = event.value === null ? '' : String(event.value);\n this.mqttClient.publish(device.topic + '/' + event.key, value, {retain: true});\n }\n }\n };\n const errorListener = (error: Error | NodePyATVDeviceEvent) => {\n if (error instanceof Error) {\n this.log({\n level: 'error',\n host: device.host,\n message: 'Push Error',\n error\n });\n }\n };\n\n atv.on('update', updateListener);\n atv.on('error', errorListener);\n this.teardown.unshift(async () => {\n atv.off('update', updateListener);\n atv.off('error', errorListener);\n });\n\n\n /* MQTT --> PYATV */\n\n if (this.mqttClient) {\n this.mqttClient.subscribe(device.topic + '/+');\n this.teardown.unshift(() => {\n return new Promise(resolve => {\n if(this.mqttClient) {\n this.mqttClient.unsubscribe(device.topic + '/+', resolve);\n }\n });\n });\n\n this.mqttClient.on('message', topic => {\n const key = Object\n .keys(NodePyATVKeys)\n .find(key => device.topic + '/' + key === topic) as NodePyATVKeys | undefined;\n\n if(key) {\n atv.pressKey(key).catch(error => {\n this.log({\n level: 'error',\n host: device.host,\n message: `Unable to press key \"${key}\"`,\n error\n });\n });\n }\n });\n }\n }\n\n async stop(): Promise<void> {\n await Promise.all(this.teardown);\n }\n}\n"],"mappings":"uwBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAGA,IAAAI,EAAkC,gBAClCC,EAAyD,sCAEzD,IAAqBC,EAArB,KAAqC,CAKjC,YAAYC,EAAiB,CAJ7B,KAAQ,WAAgC,KAExC,KAAiB,SAAuC,CAAC,EAGrD,GAAI,OAAOA,EAAQ,QAAW,SAC1B,MAAM,IAAI,MAAM,4BAA4B,EAEhD,GAAI,CAAC,MAAM,QAAQA,EAAQ,OAAO,GAAK,CAACA,EAAQ,QAAQ,OACpD,MAAM,IAAI,MAAM,6BAA6B,EAEjD,GAAIA,EAAQ,QAAQ,KAAKC,GAAK,OAAOA,EAAE,OAAU,QAAQ,EACrD,MAAM,IAAI,MAAM,mCAAmC,EAEvD,GAAID,EAAQ,QAAQ,KAAKC,GAAK,OAAOA,EAAE,MAAS,QAAQ,EACpD,MAAM,IAAI,MAAM,kCAAkC,EAEtD,GAAID,EAAQ,QAAQ,KAAKC,GAAK,OAAOA,EAAE,MAAS,QAAQ,EACpD,MAAM,IAAI,MAAM,kCAAkC,EAGtD,KAAK,QAAUD,EACf,KAAK,SAAW,CAAC,EAEjB,KAAK,MAAM,EAAE,MAAME,GAAO,CACtB,KAAK,IAAI,CACL,MAAO,QACP,KAAM,KACN,QAAS,yBACT,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,QAAQ,CACnC,GACJ","names":["lib_exports","__export","PyAtvMqttBridge","__toCommonJS","import_mqtt","import_node_pyatv","PyAtvMqttBridge","options","d","err","msg","__async","errorListener","error","resolve","device","atv","pyatv","message","updateListener","event","value","topic","key"]}
@@ -0,0 +1,29 @@
1
+ import { NodePyATVDeviceOptions } from '@sebbo2002/node-pyatv';
2
+
3
+ interface Config {
4
+ broker: string;
5
+ log?: (msg: LogParam) => (void);
6
+ devices: ConfigDevice[];
7
+ }
8
+ interface ConfigDevice extends NodePyATVDeviceOptions {
9
+ topic: string;
10
+ }
11
+ interface LogParam {
12
+ level: string;
13
+ host: string | null;
14
+ message: string;
15
+ error?: Error;
16
+ }
17
+
18
+ declare class PyAtvMqttBridge {
19
+ private mqttClient;
20
+ private readonly options;
21
+ private readonly teardown;
22
+ constructor(options: Config);
23
+ private log;
24
+ private start;
25
+ private startDevice;
26
+ stop(): Promise<void>;
27
+ }
28
+
29
+ export { PyAtvMqttBridge as default };
@@ -1,5 +1,21 @@
1
- import { Config } from './types.js';
2
- export default class PyAtvMqttBridge {
1
+ import { NodePyATVDeviceOptions } from '@sebbo2002/node-pyatv';
2
+
3
+ interface Config {
4
+ broker: string;
5
+ log?: (msg: LogParam) => (void);
6
+ devices: ConfigDevice[];
7
+ }
8
+ interface ConfigDevice extends NodePyATVDeviceOptions {
9
+ topic: string;
10
+ }
11
+ interface LogParam {
12
+ level: string;
13
+ host: string | null;
14
+ message: string;
15
+ error?: Error;
16
+ }
17
+
18
+ declare class PyAtvMqttBridge {
3
19
  private mqttClient;
4
20
  private readonly options;
5
21
  private readonly teardown;
@@ -9,3 +25,5 @@ export default class PyAtvMqttBridge {
9
25
  private startDevice;
10
26
  stop(): Promise<void>;
11
27
  }
28
+
29
+ export { PyAtvMqttBridge as default };
package/dist/lib/index.js CHANGED
@@ -1,160 +1,2 @@
1
- 'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import { connect } from 'mqtt';
12
- import pyatv, { NodePyATVDeviceEvent, NodePyATVKeys } from '@sebbo2002/node-pyatv';
13
- export default class PyAtvMqttBridge {
14
- constructor(options) {
15
- this.mqttClient = null;
16
- this.teardown = [];
17
- if (typeof options.broker !== 'string') {
18
- throw new Error('options.broker is not set!');
19
- }
20
- if (!Array.isArray(options.devices) || !options.devices.length) {
21
- throw new Error('options.devices is not set!');
22
- }
23
- if (options.devices.find(d => typeof d.topic !== 'string')) {
24
- throw new Error('options.devices.topic is not set!');
25
- }
26
- if (options.devices.find(d => typeof d.host !== 'string')) {
27
- throw new Error('options.devices.host is not set!');
28
- }
29
- if (options.devices.find(d => typeof d.name !== 'string')) {
30
- throw new Error('options.devices.name is not set!');
31
- }
32
- this.options = options;
33
- this.teardown = [];
34
- this.start().catch(err => {
35
- this.log({
36
- level: 'error',
37
- host: null,
38
- message: 'Unable to start bridge',
39
- error: err
40
- });
41
- });
42
- }
43
- log(msg) {
44
- if (this.options.log) {
45
- try {
46
- this.options.log.apply(this, [msg]);
47
- }
48
- catch (err) {
49
- console.log('Unable to call custom log function:');
50
- console.log(err);
51
- }
52
- }
53
- }
54
- start() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const errorListener = (error) => this.log({
57
- level: 'error',
58
- host: null,
59
- message: 'MQTT error',
60
- error
61
- });
62
- this.mqttClient = connect(this.options.broker);
63
- this.mqttClient.on('error', errorListener);
64
- this.teardown.unshift(() => __awaiter(this, void 0, void 0, function* () {
65
- if (this.mqttClient) {
66
- this.mqttClient.off('error', errorListener);
67
- yield new Promise(resolve => {
68
- if (this.mqttClient) {
69
- this.mqttClient.end(false, () => resolve(undefined));
70
- }
71
- });
72
- }
73
- }));
74
- yield Promise.all(this.options.devices.map(device => this.startDevice(device)));
75
- });
76
- }
77
- startDevice(device) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- this.log({
80
- level: 'info',
81
- host: device.host,
82
- message: 'Setup device…'
83
- });
84
- const atv = pyatv.device(Object.assign({}, device, {
85
- debug: (message) => this.log({
86
- level: 'info',
87
- host: device.host,
88
- message
89
- })
90
- }));
91
- /* MQTT <-- PYATV */
92
- if (this.mqttClient) {
93
- this.mqttClient.publish(device.topic + '/host', device.host, { retain: true });
94
- this.mqttClient.publish(device.topic + '/name', device.name, { retain: true });
95
- this.mqttClient.publish(device.topic + '/id', device.id || '', { retain: true });
96
- }
97
- const updateListener = (event) => {
98
- if (event instanceof NodePyATVDeviceEvent) {
99
- this.log({
100
- level: 'info',
101
- host: device.host,
102
- message: JSON.stringify(event)
103
- });
104
- if (this.mqttClient) {
105
- const value = event.value === null ? '' : String(event.value);
106
- this.mqttClient.publish(device.topic + '/' + event.key, value, { retain: true });
107
- }
108
- }
109
- };
110
- const errorListener = (error) => {
111
- if (error instanceof Error) {
112
- this.log({
113
- level: 'error',
114
- host: device.host,
115
- message: 'Push Error',
116
- error
117
- });
118
- }
119
- };
120
- atv.on('update', updateListener);
121
- atv.on('error', errorListener);
122
- this.teardown.unshift(() => __awaiter(this, void 0, void 0, function* () {
123
- atv.off('update', updateListener);
124
- atv.off('error', errorListener);
125
- }));
126
- /* MQTT --> PYATV */
127
- if (this.mqttClient) {
128
- this.mqttClient.subscribe(device.topic + '/+');
129
- this.teardown.unshift(() => {
130
- return new Promise(resolve => {
131
- if (this.mqttClient) {
132
- this.mqttClient.unsubscribe(device.topic + '/+', resolve);
133
- }
134
- });
135
- });
136
- this.mqttClient.on('message', topic => {
137
- const key = Object
138
- .keys(NodePyATVKeys)
139
- .find(key => device.topic + '/' + key === topic);
140
- if (key) {
141
- atv.pressKey(key).catch(error => {
142
- this.log({
143
- level: 'error',
144
- host: device.host,
145
- message: `Unable to press key "${key}"`,
146
- error
147
- });
148
- });
149
- }
150
- });
151
- }
152
- });
153
- }
154
- stop() {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- yield Promise.all(this.teardown);
157
- });
158
- }
159
- }
1
+ import{a}from"../chunk-OEFAITBU.js";export{a as default};
160
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAGb,OAAO,EAAC,OAAO,EAAa,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,EAAC,oBAAoB,EAAE,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEjF,MAAM,CAAC,OAAO,OAAO,eAAe;IAKhC,YAAY,OAAe;QAJnB,eAAU,GAAsB,IAAI,CAAC;QAE5B,aAAQ,GAA+B,EAAE,CAAC;QAGvD,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SACjD;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;YAC5D,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAClD;QACD,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,EAAE;YACxD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;SACxD;QACD,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE;YACvD,MAAM,IAAI,K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ACvC,KAAK;6BACR,CAAC,CAAC;wBACP,CAAC,CAAC,CAAC;qBACN;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;KAAA;IAEK,IAAI;;YACN,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;KAAA;CACJ"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -8,50 +8,55 @@
8
8
  "url": "https://github.com/sebbo2002/pyatv-mqtt-bridge/issues"
9
9
  },
10
10
  "dependencies": {
11
- "@sebbo2002/node-pyatv": "^5.1.1",
11
+ "@sebbo2002/node-pyatv": "^6.0.1",
12
12
  "mqtt": "^4.3.7"
13
13
  },
14
14
  "description": "Bridge which allows you to control your Apple TV via MQTT",
15
15
  "devDependencies": {
16
- "@qiwi/semantic-release-gh-pages-plugin": "^5.2.4",
17
- "@sebbo2002/semantic-release-docker": "^2.1.0-develop.1",
18
- "@semantic-release/changelog": "^6.0.2",
16
+ "@qiwi/semantic-release-gh-pages-plugin": "^5.2.5",
17
+ "@sebbo2002/semantic-release-docker": "^3.0.0",
18
+ "@semantic-release/changelog": "^6.0.3",
19
19
  "@semantic-release/exec": "^6.0.3",
20
20
  "@semantic-release/git": "^10.0.1",
21
21
  "@semantic-release/github": "^8.0.7",
22
- "@semantic-release/npm": "^9.0.2",
22
+ "@semantic-release/npm": "^10.0.2",
23
23
  "@types/mocha": "^10.0.1",
24
- "@types/node": "^18.13.0",
24
+ "@types/node": "^18.15.11",
25
25
  "@types/ws": "^8.5.4",
26
- "@typescript-eslint/eslint-plugin": "^5.51.0",
27
- "@typescript-eslint/parser": "^5.51.0",
28
- "eslint": "^8.34.0",
29
- "eslint-plugin-jsonc": "^2.6.0",
26
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
27
+ "@typescript-eslint/parser": "^5.57.0",
28
+ "eslint": "^8.36.0",
29
+ "eslint-plugin-jsonc": "^2.7.0",
30
30
  "esm": "^3.2.25",
31
31
  "license-checker": "^25.0.1",
32
- "semantic-release": "^20.1.0",
32
+ "semantic-release": "^21.0.0",
33
33
  "semantic-release-license": "^1.0.3",
34
34
  "ts-node": "^10.8.1",
35
- "typedoc": "^0.23.25",
36
- "typescript": "^4.9.5"
35
+ "tsup": "^6.7.0",
36
+ "typedoc": "^0.23.28",
37
+ "typescript": "^5.0.3"
37
38
  },
38
39
  "engines": {
39
40
  "node": "^14.8.0 || >=16.0.0"
40
41
  },
42
+ "exports": {
43
+ "import": "./dist/lib/index.js",
44
+ "require": "./dist/lib/index.cjs"
45
+ },
41
46
  "files": [
42
47
  "/dist"
43
48
  ],
44
49
  "homepage": "https://github.com/sebbo2002/js-template#readme",
45
50
  "license": "MIT",
46
- "main": "./dist/lib/index.js",
51
+ "main": "./dist/lib/index.cjs",
52
+ "module": "./dist/lib/index.js",
47
53
  "name": "@sebbo2002/pyatv-mqtt-bridge",
48
- "preferGlobal": false,
49
54
  "repository": {
50
55
  "type": "git",
51
56
  "url": "https://github.com/sebbo2002/pyatv-mqtt-bridge.git"
52
57
  },
53
58
  "scripts": {
54
- "build": "tsc && chmod +x ./dist/bin/*",
59
+ "build": "tsup && cp ./dist/lib/index.d.ts ./dist/lib/index.d.cts",
55
60
  "build-all": "./.github/workflows/build.sh",
56
61
  "develop": "ts-node ./src/bin/cli.ts",
57
62
  "license-check": "license-checker --production --summary",
@@ -59,5 +64,5 @@
59
64
  "start": "node ./dist/bin/cli.js"
60
65
  },
61
66
  "type": "module",
62
- "version": "5.0.0-develop.1"
67
+ "version": "5.0.0-develop.2"
63
68
  }
@@ -1,15 +0,0 @@
1
- import { NodePyATVDeviceOptions } from '@sebbo2002/node-pyatv';
2
- export interface Config {
3
- broker: string;
4
- log?: (msg: LogParam) => (void);
5
- devices: ConfigDevice[];
6
- }
7
- export interface ConfigDevice extends NodePyATVDeviceOptions {
8
- topic: string;
9
- }
10
- export interface LogParam {
11
- level: string;
12
- host: string | null;
13
- message: string;
14
- error?: Error;
15
- }
package/dist/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":""}