Skip to content

Commit

Permalink
release v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Dec 1, 2024
1 parent b444b50 commit 18fe6ec
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 85 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- After update to v4.0.0 RESTFull and MQTT config settings need to be updated

## [4.1.0] - (01.12.2024)

## Changes

- move from commonJS to esm module
- moved constants.json to constants.js
- cleanup

## [4.0.2] - (18.08.2024)

## Changes
Expand Down
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';
const path = require('path');
const fs = require('fs');
const OpenWebIfDevice = require('./src/openwebifdevice.js');
const ImpulseGenerator = require('./src/impulsegenerator.js');
const CONSTANTS = require('./src/constants.json');
import { join } from 'path';
import { mkdirSync, existsSync, writeFileSync } from 'fs';
import OpenWebIfDevice from './src/openwebifdevice.js';
import ImpulseGenerator from './src/impulsegenerator.js';
import { PluginName, PlatformName } from './src/constants.js';

class OpenWebIfPlatform {
constructor(log, config, api) {
// only load if configured
if (!config || !Array.isArray(config.devices)) {
log.warn(`No configuration found for ${CONSTANTS.PluginName}`);
log.warn(`No configuration found for ${PluginName}`);
return;
}
this.accessories = [];

//check if prefs directory exist
const prefDir = path.join(api.user.storagePath(), 'openwebifTv');
const prefDir = join(api.user.storagePath(), 'openwebifTv');
try {
fs.mkdirSync(prefDir, { recursive: true });
mkdirSync(prefDir, { recursive: true });
} catch (error) {
log.error(`Prepare directory error: ${error.message ?? error}`);
return;
Expand Down Expand Up @@ -70,8 +70,8 @@ class OpenWebIfPlatform {
];

files.forEach((file) => {
if (!fs.existsSync(file)) {
fs.writeFileSync(file, '');
if (!existsSync(file)) {
writeFileSync(file, '');
}
});
} catch (error) {
Expand All @@ -83,7 +83,7 @@ class OpenWebIfPlatform {
try {
const openWebIfDevice = new OpenWebIfDevice(api, device, devInfoFile, inputsFile, channelsFile, inputsNamesFile, inputsTargetVisibilityFile, refreshInterval);
openWebIfDevice.on('publishAccessory', (accessory) => {
api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]);
api.publishExternalAccessories(PluginName, [accessory]);
log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
})
.on('devInfo', (devInfo) => {
Expand Down Expand Up @@ -132,6 +132,6 @@ class OpenWebIfPlatform {
}
};

module.exports = (api) => {
api.registerPlatform(CONSTANTS.PluginName, CONSTANTS.PlatformName, OpenWebIfPlatform, true);
export default (api) => {
api.registerPlatform(PluginName, PlatformName, OpenWebIfPlatform, true);
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "OpenWebIf TV",
"name": "homebridge-openwebif-tv",
"version": "4.0.26",
"version": "4.1.0",
"description": "Homebridge plugin to control Sat Receivers based on openWebIf api.",
"license": "MIT",
"author": "grzegorz914",
Expand All @@ -16,6 +16,7 @@
"bugs": {
"url": "https://github.com/grzegorz914/homebridge-openwebif-tv/issues"
},
"type": "module",
"main": "index.js",
"files": [
"src",
Expand Down
27 changes: 27 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const PlatformName = "OpenWebIfTv";
export const PluginName = "homebridge-openwebif-tv";

export const ApiUrls = {
"DeviceInfo": "/api/deviceinfo",
"DeviceStatus": "/api/statusinfo",
"GetAllServices": "/api/getallservices",
"SetPower": "/api/powerstate?newstate=",
"SetChannel": "/api/zap?sRef=",
"SetVolume": "/api/vol?set=set",
"ToggleMute": "/api/vol?set=mute",
"SetRcCommand": "/api/remotecontrol?command="
};

export const InputSourceType = [
"OTHER",
"HOME_SCREEN",
"TUNER",
"HDMI",
"COMPOSITE_VIDEO",
"S_VIDEO",
"COMPONENT_VIDEO",
"DVI",
"AIRPLAY",
"USB",
"APPLICATION"
]
27 changes: 0 additions & 27 deletions src/constants.json

This file was deleted.

8 changes: 4 additions & 4 deletions src/impulsegenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
const EventEmitter = require('events');
import EventEmitter from 'events';

class ImpulseGenerator extends EventEmitter {
constructor() {
Expand All @@ -15,7 +15,7 @@ class ImpulseGenerator extends EventEmitter {
this.timers = [];
for (const timer of timers) {
this.emit(timer.name);

const newTimer = setInterval(() => {
this.emit(timer.name);
}, timer.sampling);
Expand All @@ -39,12 +39,12 @@ class ImpulseGenerator extends EventEmitter {
this.timersState = false;
this.state();

return true;
return true
}

state() {
this.emit('state', this.timersState);
return this.timersState;
}
}
module.exports = ImpulseGenerator;
export default ImpulseGenerator;
9 changes: 5 additions & 4 deletions src/mqtt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
const AsyncMqtt = require("async-mqtt");
const EventEmitter = require('events');
import asyncMqtt from 'async-mqtt';
const { connectAsync } = asyncMqtt;
import EventEmitter from 'events';

class Mqtt extends EventEmitter {
constructor(config) {
Expand All @@ -16,7 +17,7 @@ class Mqtt extends EventEmitter {
this.on('connect', async () => {
try {
//connect
this.mqttClient = await AsyncMqtt.connectAsync(url, options);
this.mqttClient = await connectAsync(url, options);
this.emit('connected', 'MQTT Connected.');

//subscribe
Expand Down Expand Up @@ -52,4 +53,4 @@ class Mqtt extends EventEmitter {
this.emit('connect');
};
};
module.exports = Mqtt;
export default Mqtt
24 changes: 12 additions & 12 deletions src/openwebif.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
const fs = require('fs');
const fsPromises = fs.promises;
const axios = require('axios');
const EventEmitter = require('events');
const ImpulseGenerator = require('./impulsegenerator.js');
const CONSTANTS = require('./constants.json');

class OPENWEBIF extends EventEmitter {
import { promises } from 'fs';
const fsPromises = promises;
import axios from 'axios';
import EventEmitter from 'events';
import ImpulseGenerator from './impulsegenerator.js';
import { ApiUrls } from './constants.js';

class OpenWebIf extends EventEmitter {
constructor(config) {
super();
const host = config.host;
Expand Down Expand Up @@ -56,7 +56,7 @@ class OPENWEBIF extends EventEmitter {

async connect() {
try {
const deviceInfo = await this.axiosInstance(CONSTANTS.ApiUrls.DeviceInfo);
const deviceInfo = await this.axiosInstance(ApiUrls.DeviceInfo);
const devInfo = deviceInfo.data;
const debug = this.debugLog ? this.emit('debug', `Connect data: ${JSON.stringify(devInfo, null, 2)}`) : false;
this.devInfo = devInfo;
Expand All @@ -78,7 +78,7 @@ class OPENWEBIF extends EventEmitter {
await this.saveData(this.devInfoFile, devInfo);

//get all channels
const channelsInfo = this.getInputsFromDevice ? await this.axiosInstance(CONSTANTS.ApiUrls.GetAllServices) : false;
const channelsInfo = this.getInputsFromDevice ? await this.axiosInstance(ApiUrls.GetAllServices) : false;
const allChannels = channelsInfo ? channelsInfo.data.services : false;
const debug1 = this.debugLog ? this.emit('debug', `Channels info: ${channelsInfo}`) : false;

Expand Down Expand Up @@ -113,7 +113,7 @@ class OPENWEBIF extends EventEmitter {

async checkState() {
try {
const deviceState = await this.axiosInstance(CONSTANTS.ApiUrls.DeviceStatus);
const deviceState = await this.axiosInstance(ApiUrls.DeviceStatus);
const devState = deviceState.data;
const debug = this.debugLog ? this.emit('debug', `State: ${JSON.stringify(devState, null, 2)}`) : false;

Expand Down Expand Up @@ -221,4 +221,4 @@ class OPENWEBIF extends EventEmitter {
};
};
};
module.exports = OPENWEBIF;
export default OpenWebIf;
Loading

0 comments on commit 18fe6ec

Please sign in to comment.