Skip to content

Commit

Permalink
Merge branch 'next' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
johannrichard authored Nov 1, 2024
2 parents cc1a40c + 5e76157 commit a4c4ea5
Show file tree
Hide file tree
Showing 12 changed files with 4,388 additions and 3,019 deletions.
36 changes: 0 additions & 36 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ web_modules/
# Github templates and actions, own stuff
.github
api
.husky
.prettierrc
.prettierignore
commitlint.config.js
60 changes: 60 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["**/dist", "**/commitlint.config.js"],
}, ...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
), {
plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2018,
sourceType: "module",
},

rules: {
quotes: ["warn", "single"],

indent: ["warn", 2, {
SwitchCase: 1,
}],

"linebreak-style": ["warn", "unix"],
semi: ["warn", "always"],
"comma-dangle": ["warn", "always-multiline"],
"dot-notation": "warn",
eqeqeq: "warn",
curly: ["warn", "all"],
"brace-style": ["warn"],
"prefer-arrow-callback": ["warn"],
"max-len": ["warn", 140],
"no-console": ["warn"],

"lines-between-class-members": ["warn", "always", {
exceptAfterSingleLine: true,
}],

"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-require-imports": "warn",
},
}];
73 changes: 38 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"main": "dist/index.js",
"scripts": {
"lint": "eslint src/**.ts",
"postinstall": "husky install",
"postinstall": "yarn husky install",
"prepack": "yarn pinst --disable",
"postpack": "yarn pinst --enable",
"watch": "yarn dlx nodemon",
Expand All @@ -37,49 +37,52 @@
"iot"
],
"dependencies": {
"async-mutex": "^0.3.2",
"axios": "^0.25.0",
"axios-retry": "^3.2.4",
"body-parser": "^1.20.1",
"async-mutex": "^0.5.0",
"axios": "^1.7.7",
"axios-retry": "^4.5.0",
"body-parser": "^1.20.3",
"chalk": "4.1.2",
"cockatiel": "^2.0.2",
"express": "^4.18.2",
"cockatiel": "^3.2.1",
"express": "^4.21.1",
"fakegato-history": "^0.6.5",
"intervals-for-humans": "^1.0.4",
"is-valid-host": "^1.0.1",
"limit-number": "^3.0.0",
"qs": "^6.11.0",
"semver": "^7.3.8",
"qs": "^6.13.0",
"semver": "^7.6.3",
"simple-color-converter": "^2.1.13"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/github": "^8.0.7",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/body-parser": "^1.19.2",
"@types/express": "^4.17.15",
"@types/node": "^18.11.18",
"@types/qs": "^6.9.7",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"depcheck": "^1.4.3",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.0",
"@semantic-release/github": "^11.0.0",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"@types/body-parser": "^1.19.5",
"@types/express": "^5.0.0",
"@types/node": "^20.17.5",
"@types/qs": "^6.9.16",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"depcheck": "^1.4.7",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"generate-changelog": "^1.8.0",
"homebridge": "^1.6.0",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"nodemon": "^2.0.20",
"homebridge": "^1.8.5",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"nodemon": "^3.1.7",
"pinst": "^3.0.0",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.5",
"typescript": "^4.9.4"
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"semantic-release": "^24.2.0",
"typescript": "^5.6.3"
},
"lint-staged": {
"**/*.+(js|jsx|css|less|scss|ts|tsx|md)": [
Expand Down
20 changes: 11 additions & 9 deletions src/dingzAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
Brightness: 0 as number,
};

private motionTimer?: NodeJS.Timer;
private motionTimer?: NodeJS.Timeout;

private config: DingzDeviceConfig;
private hw: DingzDeviceHWInfo;
Expand Down Expand Up @@ -717,7 +717,9 @@ export class DingzAccessory extends DingzDaBaseAccessory {
service.getCharacteristic(this.platform.Characteristic.Brightness),
);
} catch (e) {
this.log.warn('Attempt to remove "Brightness" characteristic failed');
this.log.warn(
`Attempt to remove "Brightness" characteristic failed ${e}`,
);
} finally {
service.addCharacteristic(this.platform.Characteristic.Brightness);
service
Expand Down Expand Up @@ -782,7 +784,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
value: CharacteristicValue,
callback: CharacteristicSetCallback,
) {
const isOn: boolean = value > 0 ? true : false;
const isOn: boolean = Number(value) > 0 ? true : false;
this.dingzStates.Dimmers[index].output = value as number;
this.dingzStates.Dimmers[index].on = isOn;

Expand Down Expand Up @@ -938,9 +940,9 @@ export class DingzAccessory extends DingzDaBaseAccessory {
const windowCovering = this.dingzStates.WindowCovers[id];
if (windowCovering) {
// Make sure we're setting motion when changing the position
if (position > windowCovering.position) {
if (Number(position) > windowCovering.position) {
windowCovering.moving = 'up';
} else if (position < windowCovering.position) {
} else if (Number(position) < windowCovering.position) {
windowCovering.moving = 'down';
} else {
windowCovering.moving = 'stop';
Expand All @@ -951,7 +953,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
await this.setWindowCovering({
id: id,
blind: position as number,
lamella: (windowCovering.lamella / 90) * 100, // FIXES #419, we must convert ° to %
lamella: windowCovering.lamella, // FIXES #419, we must convert ° to %
callback: callback,
});
}
Expand Down Expand Up @@ -1078,7 +1080,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
// Only check for motion if we have a PIR and set the Interval
if (this.platform.config.motionPoller ?? true) {
this.log.info('Motion POLLING enabled');
const motionInterval: NodeJS.Timer = setInterval(() => {
const motionInterval: NodeJS.Timeout = setInterval(() => {
this.getDeviceMotion()
.then((data) => {
if (data?.success) {
Expand Down Expand Up @@ -1115,7 +1117,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
private removeMotionService() {
// Remove motionService & motionTimer
if (this.motionTimer) {
clearTimeout(this.motionTimer);
clearInterval(this.motionTimer);
this.motionTimer = undefined;
}
const service: Service | undefined = this.accessory.getService(
Expand Down Expand Up @@ -1518,7 +1520,7 @@ export class DingzAccessory extends DingzDaBaseAccessory {
lamella = Math.round(lamella);

this.log.debug(
`Setting WindowCovering ${id} to position ${blind} and angle ${lamella}°`,
`Setting WindowCovering ${id} to position ${blind} and ${lamella}% tilt position`,
);
// The API says the parameters can be omitted. This is not true
// {{ip}}/api/v1/shade/0?blind=<value>&lamella=<value>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/axiosDebugHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AxiosInstance,
AxiosRequestConfig,
AxiosResponse,
InternalAxiosRequestConfig,
} from 'axios';
import { Logger } from 'homebridge';
import { DingzLogger } from './dingzLogHelper';
Expand Down Expand Up @@ -38,8 +39,8 @@ export class AxiosDebugHelper {

public addLogger(
instance: AxiosInstance,
): AxiosRequestConfig | AxiosResponse | void {
instance.interceptors.request.use((config: AxiosRequestConfig) => {
): InternalAxiosRequestConfig | AxiosResponse | void {
instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
this.request(config);
return config;
});
Expand Down
5 changes: 3 additions & 2 deletions src/lib/dingzDaBaseAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ export class DingzDaBaseAccessory {
break;
default:
this.log.error(
`HTTP ${e.code} ${e.message} ${e.response?.statusText ?? ' '}--> ` +
this.device.address,
`HTTP ${e.code} ${e.message} ${e.response?.statusText ?? ' '}--> ${
this.device.address
}`,
);
break;
}
Expand Down
14 changes: 8 additions & 6 deletions src/myStromButtonAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
PlatformAccessory,
CharacteristicGetCallback,
} from 'homebridge';
import { Policy } from 'cockatiel';
import { ExponentialBackoff, handleAll, retry } from 'cockatiel';

import { DingzDaHomebridgePlatform } from './platform';
import { MyStromDeviceHWInfo } from './lib/myStromTypes';
Expand All @@ -14,10 +14,12 @@ import { ButtonState } from './lib/dingzTypes';
import { DingzDaBaseAccessory } from './lib/dingzDaBaseAccessory';

// Policy for long running tasks, retry every hour
const retrySlow = Policy.handleAll()
.orWhenResult((retry) => retry === true)
.retry()
.exponential({ initialDelay: 10000, maxDelay: 60 * 60 * 1000 });
const retrySlowPolicy = retry(handleAll, {
backoff: new ExponentialBackoff({
maxDelay: 60 * 60 * 1000,
initialDelay: 10000,
}),
});

/**
* Platform Accessory
Expand Down Expand Up @@ -89,7 +91,7 @@ export class MyStromButtonAccessory extends DingzDaBaseAccessory {
this.buttonServiceSetup();

// Set the callback URL (Override!)
retrySlow.execute(() => {
retrySlowPolicy.execute(() => {
this.platform.setButtonCallbackUrl({
baseUrl: this.baseUrl,
token: this.device.token,
Expand Down
15 changes: 8 additions & 7 deletions src/myStromButtonPlusAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
PlatformAccessory,
CharacteristicGetCallback,
} from 'homebridge';
import { Policy } from 'cockatiel';
import { ExponentialBackoff, handleAll, retry } from 'cockatiel';

import { DingzDaHomebridgePlatform } from './platform';
import {
Expand All @@ -17,11 +17,12 @@ import { ButtonId, ButtonState } from './lib/dingzTypes';
import { MyStromButtonAccessory } from './myStromButtonAccessory';

// Policy for long running tasks, retry every hour
const retrySlow = Policy.handleAll()
.orWhenResult((retry) => retry === true)
.retry()
.exponential({ initialDelay: 10000, maxDelay: 60 * 60 * 1000 });

const retrySlowPolicy = retry(handleAll, {
backoff: new ExponentialBackoff({
maxDelay: 60 * 60 * 1000,
initialDelay: 10000,
}),
});
/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -129,7 +130,7 @@ export class MyStromButtonPlusAccessory extends MyStromButtonAccessory {
.on(CharacteristicEventTypes.GET, this.getHumidity.bind(this));

// Set the callback URL (Override!)
retrySlow.execute(() => {
retrySlowPolicy.execute(() => {
this.platform.setButtonCallbackUrl({
baseUrl: this.baseUrl,
token: this.device.token,
Expand Down
Loading

0 comments on commit a4c4ea5

Please sign in to comment.