homebridge-appletv-enhanced
Version:
Plugin that exposes the Apple TV to HomeKit with much richer features than the vanilla Apple TV implementation of HomeKit.
122 lines • 5.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nodePyatv = __importStar(require("@sebbo2002/node-pyatv"));
const path_1 = __importDefault(require("path"));
const PrefixLogger_1 = __importDefault(require("./PrefixLogger"));
class CustomPyATVInstance extends nodePyatv.NodePyATVInstance {
static atvremotePath = undefined;
static atvscriptPath = undefined;
static cachedDevices = {};
static log = undefined;
constructor(options) {
super(options);
}
static async customFind(options = {}) {
return nodePyatv.NodePyATVInstance.find(this.extendOptions(options), true)
.then(async (results) => {
for (const device of results.devices) {
if (device.mac !== undefined && device.mac !== null) {
CustomPyATVInstance.cachedDevices[device.mac.toUpperCase()] = device;
}
}
return results;
});
}
static deviceAdvanced(options) {
if (options.mac !== undefined && options.mac !== null) {
const cachedDevice = CustomPyATVInstance.cachedDevices[options.mac.toUpperCase()];
if (cachedDevice === undefined) {
return undefined;
}
return super.device(this.extendOptions({
...options,
// Don't add host. This ensures that pyatv does not try to connect via IP address
// This is required for cross subnet compatibility.
// host: cachedDevice.host,
mac: cachedDevice.mac?.toUpperCase(),
name: cachedDevice.name,
id: cachedDevice.id,
model: cachedDevice.model,
modelName: cachedDevice.modelName,
version: cachedDevice.version,
os: cachedDevice.os,
allIDs: cachedDevice.allIDs,
}));
}
else {
return super.device(this.extendOptions(options));
}
}
static getAtvremotePath() {
return CustomPyATVInstance.atvremotePath ?? 'atvremote';
}
static getAtvscriptPath() {
return CustomPyATVInstance.atvremotePath ?? 'atvscript';
}
static setLogger(logger) {
CustomPyATVInstance.log = new PrefixLogger_1.default(logger, 'CustomPyATVInstance');
}
static setStoragePath(storagePath) {
CustomPyATVInstance.atvscriptPath = path_1.default.join(storagePath, 'appletv-enhanced', '.venv', 'bin', 'atvscript');
CustomPyATVInstance.atvremotePath = path_1.default.join(storagePath, 'appletv-enhanced', '.venv', 'bin', 'atvremote');
CustomPyATVInstance.log?.debug(`Set atvscript path to "${CustomPyATVInstance.atvscriptPath}".`);
CustomPyATVInstance.log?.debug(`Set atvremote path to "${CustomPyATVInstance.atvremotePath}".`);
}
static extendOptions(options) {
const debug = (msg) => {
if (CustomPyATVInstance.log) {
// remove color
// eslint-disable-next-line no-control-regex
msg = msg.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
CustomPyATVInstance.log.verbose(msg);
}
};
return {
atvscriptPath: CustomPyATVInstance.atvscriptPath,
atvremotePath: CustomPyATVInstance.atvremotePath,
debug: debug,
...options,
};
}
async find(options) {
return CustomPyATVInstance.find(options);
}
}
exports.default = CustomPyATVInstance;
//# sourceMappingURL=CustomPyAtvInstance.js.map