homebridge-tasmota 0.2.3-beta.6 → 0.2.4-beta.0

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.
package/DEVICES.md CHANGED
@@ -33,6 +33,7 @@
33
33
  * [Valor Fireplace Remote ( 315 Mhz )](#valor-fireplace-remote--315-mhz-)
34
34
  * [Treatlife DS03 Fan Controller and Light Dimmer](#treatlife-ds03-fan-controller-and-light-dimmer)
35
35
  * [Greeni GNC-SW003-199](#greeni-gnc-sw003-199)
36
+ * [Always on Powerbar - Turns on after 30 seconds](#always-on-powerbar---turns-on-after-30-seconds)
36
37
  * [OpenMQTTGateway devices](#openmqttgateway-devices)
37
38
  * [Hampton Bay Light](#hampton-bay-light)
38
39
  * [Hampton Bay FAN](#hampton-bay-fan)
@@ -339,7 +340,8 @@ DimmerRange 100,255
339
340
  * Tasmota configuration
340
341
 
341
342
  ```
342
- backlog webbutton1 Ceiling; webbutton2 Flood; webbutton3 Porch; webbutton4 Step
343
+ Template {"NAME":"Trailer Switch","GPIO":[0,0,0,0,226,225,0,0,227,0,0,228,0,0],"FLAG":0,"BASE":18}
344
+ Backlog Module 0; WebButton1 Trailer Ceiling; WebButton2 Trailer Flood; WebButton3 Trailer Porch; WebButton4 Trailer Step
343
345
  ```
344
346
 
345
347
  # Gowfeel EN71 Water Valve
@@ -611,6 +613,14 @@ backlog Friendlyname1 Switch 1; Friendlyname2 Switch 2; Friendlyname3 Switch 3;
611
613
  Backlog MqttHost mqtt.local; topic tasmota_%06X; setoption57 1; setoption19 1
612
614
  ```
613
615
 
616
+ ## Always on Powerbar - Turns on after 30 seconds
617
+
618
+ ```
619
+ backlog PowerOnState 5; pulsetime1 130; pulsetime2 130; pulsetime3 130; pulsetime4 130; pulsetime5 130; pulsetime6 130
620
+ backlog Friendlyname1 Router; Friendlyname2 UCG Max; Friendlyname3 Switch; Friendlyname4 Switch 4; Friendlyname5 WiFi; Friendlyname6 Jessie
621
+ backlog WebButton1 Router; WebButton2 UCG Max; WebButton3 USW Switch; WebButton4 Switch 4; WebButton5 WiFi; WebButton6 Jessie
622
+ ```
623
+
614
624
  # OpenMQTTGateway devices
615
625
 
616
626
  I have been working on utilizing an OpenMQTTGateway device configured with a cc1101 RF Transceiver and the GatewayRF module. The goal is to control my Hampton Bay ( 303 Mhz ), and GE Fans ( 315 Mhz ) and other RF devices.
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota",
3
3
  "name": "homebridge-tasmota",
4
- "version": "0.2.3-beta.6",
5
- "type": "module",
4
+ "version": "0.2.4-beta.0",
6
5
  "description": "Homebridge plugin for Tasmota devices leveraging home assistant auto discovery.",
7
6
  "license": "Apache-2.0",
8
7
  "repository": {
@@ -17,13 +16,15 @@
17
16
  "node": ">=18"
18
17
  },
19
18
  "main": "dist/index.js",
19
+ "type": "module",
20
20
  "scripts": {
21
21
  "build": "rimraf ./dist && tsc",
22
22
  "document": "./gh-md-toc --hide-footer DEVICES.md",
23
- "lint": "eslint --fix src/**.ts",
23
+ "lint": "eslint src/**.ts",
24
+ "lint:fix": "eslint --fix src/**.ts",
24
25
  "oldWatch": "npm run build && npm link && nodemon",
25
26
  "prepublishOnly": "npm run lint && npm run build",
26
- "test": "rimraf ./dist && node --experimental-vm-modules node_modules/.bin/jest --detectOpenHandles",
27
+ "test": "rimraf ./dist && node --experimental-vm-modules node_modules/.bin/jest --detectOpenHandles --verbose=true",
27
28
  "test-coverage": "jest --coverage",
28
29
  "watch": "nodemon"
29
30
  },
@@ -33,7 +34,7 @@
33
34
  ],
34
35
  "ext": "ts",
35
36
  "ignore": [],
36
- "exec": "npm run build && DEBUG=-HAP-NodeJS:*,Tasmota* homebridge -U ./test/hbConfig -T -D -I -P .",
37
+ "exec": "npm run build && NODE_PATH=`pwd`:.. DEBUG=-HAP-NodeJS:*,Tasmota* node ~/node_modules/homebridge-config-ui-x/dist/bin/hb-service.js run --stdout -U ./test/hbConfig -T -D -I -P ./",
37
38
  "signal": "SIGTERM",
38
39
  "env": {
39
40
  "NODE_OPTIONS": "--trace-warnings"
@@ -55,6 +56,9 @@
55
56
  "@eslint/js": "^9.39.1",
56
57
  "@jest/globals": "^30.2.0",
57
58
  "@types/debug": "^4.1.12",
59
+ "@types/jest": "^29.5.12",
60
+ "@types/node": "^24.10.1",
61
+ "@types/nunjucks": "^3.2.6",
58
62
  "@typescript-eslint/eslint-plugin": "^8.47.0",
59
63
  "@typescript-eslint/parser": "^8.47.0",
60
64
  "eslint": "^9.39.1",
@@ -62,14 +66,12 @@
62
66
  "eslint-plugin-import-newlines": "^1.4.0",
63
67
  "eslint-plugin-jest": "^29.2.0",
64
68
  "eslint-plugin-sort-exports": "^0.9.1",
65
- "@types/jest": "^30.0.0",
66
- "@types/node": "^24.10.1",
67
- "@types/nunjucks": "^3.2.6",
68
- "homebridge": "^2.0.0-beta.0",
69
- "jest": "^30.2.0",
69
+ "homebridge": "^2.0.2",
70
+ "jest": "^29.7.0",
70
71
  "nodemon": "^3.1.11",
71
72
  "rimraf": "^6.1.2",
72
73
  "ts-jest": "^29.4.5",
74
+ "ts-node": "^10.9.2",
73
75
  "typescript": "^5.9.3"
74
76
  },
75
77
  "homepage": "https://github.com/NorthernMan54/homebridge-tasmota#readme"
@@ -1,45 +0,0 @@
1
- ---
2
- name: Bug Report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- <!-- You must use the issue template below when submitting a bug -->
11
-
12
- **Describe The Bug:**
13
- <!-- A clear and concise description of what the bug is. -->
14
-
15
- **To Reproduce:**
16
- <!-- Steps to reproduce the behavior. -->
17
-
18
- **Expected behavior:**
19
- <!-- A clear and concise description of what you expected to happen. -->
20
-
21
- **Logs:**
22
-
23
- ```
24
- Show the Homebridge logs here with the DEBUG flag set, remove any sensitive information.
25
- ```
26
-
27
- **Tasmota Device Config:**
28
-
29
- ```
30
- Please include the Tasmota Module Type / Configuration and Template ( if used )
31
- ```
32
-
33
- **Screenshots:**
34
- <!-- If applicable, add screenshots to help explain your problem. -->
35
-
36
- **Environment:**
37
-
38
- * **Tasmota Version**:
39
- * **Plugin Version**:
40
- * **Homebridge Version**: <!-- homebridge -V -->
41
- * **Node.js Version**: <!-- node -v -->
42
- * **NPM Version**: <!-- npm -v -->
43
- * **Operating System**: <!-- Raspbian / Ubuntu / Debian / Windows / macOS / Docker / hb-service -->
44
-
45
- <!-- Click the "Preview" tab before you submit to ensure the formatting is correct. -->
@@ -1,5 +0,0 @@
1
- # blank_issues_enabled: false
2
- # contact_links:
3
- # - name: Homebridge Discord Community
4
- # url: https://discord.gg/kqNCe2D
5
- # about: Ask your questions in the #YOUR_CHANNEL_HERE channel
@@ -1,23 +0,0 @@
1
- ---
2
- name: Feature Request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: enhancement
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe:**
11
- <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
12
-
13
- **Describe the solution you'd like:**
14
- <!-- A clear and concise description of what you want to happen. -->
15
-
16
- **Describe alternatives you've considered:**
17
- <!-- A clear and concise description of any alternative solutions or features you've considered. -->
18
-
19
- **Additional context:**
20
- <!-- Add any other context or screenshots about the feature request here. -->
21
-
22
-
23
- <!-- Click the "Preview" tab before you submit to ensure the formatting is correct. -->
@@ -1,39 +0,0 @@
1
- ---
2
- name: Support Request
3
- about: Need help?
4
- title: ''
5
- labels: question
6
- assignees: ''
7
-
8
- ---
9
-
10
- <!-- You must use the issue template below when submitting a support request -->
11
-
12
- **Describe Your Problem:**
13
- <!-- A clear and concise description of what problem you are trying to solve. -->
14
-
15
- **Logs:**
16
-
17
- ```
18
- Show the Homebridge logs here with the DEBUG flag set, remove any sensitive information.
19
- ```
20
-
21
- **Tasmota Device Config:**
22
-
23
- ```
24
- Please include the Tasmota Module Type / Configuration and Template ( if used )
25
- ```
26
-
27
- **Screenshots:**
28
- <!-- If applicable, add screenshots to help explain your problem. -->
29
-
30
- **Environment:**
31
-
32
- * **Tasmota Version**:
33
- * **Plugin Version**:
34
- * **Homebridge Version**: <!-- homebridge -V -->
35
- * **Node.js Version**: <!-- node -v -->
36
- * **NPM Version**: <!-- npm -v -->
37
- * **Operating System**: <!-- Raspbian / Ubuntu / Debian / Windows / macOS / Docker / hb-service -->
38
-
39
- <!-- Click the "Preview" tab before you submit to ensure the formatting is correct. -->
@@ -1,49 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- time: "10:00"
8
- open-pull-requests-limit: 10
9
- target-branch: "main"
10
- assignees:
11
- - NorthernMan54
12
- labels:
13
- - "dependencies"
14
- # Group related updates together (optional)
15
- groups:
16
- packages:
17
- patterns:
18
- - "*"
19
- # Automatically rebase PRs when conflicts occur
20
- rebase-strategy: "auto"
21
- # Commit message prefix
22
- commit-message:
23
- prefix: "chore"
24
- prefix-development: "chore"
25
- include: "scope"
26
-
27
- - package-ecosystem: "github-actions"
28
- directory: "/"
29
- schedule:
30
- interval: "daily"
31
- time: "09:00"
32
- # Create PRs for out-of-date actions
33
- open-pull-requests-limit: 10
34
- target-branch: "main"
35
- # Add labels to PRs
36
- labels:
37
- - "dependencies"
38
- # Group related updates together (optional)
39
- groups:
40
- actions:
41
- patterns:
42
- - "*"
43
- # Automatically rebase PRs when conflicts occur
44
- rebase-strategy: "auto"
45
- # Commit message prefix
46
- commit-message:
47
- prefix: "chore"
48
- prefix-development: "chore"
49
- include: "scope"
@@ -1,97 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- import assert from 'node:assert'
8
- import child_process from 'node:child_process'
9
- import fs from 'node:fs'
10
- import process from 'node:process'
11
-
12
- const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
13
-
14
- // Load the contents of the package.json file
15
- const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
16
-
17
- const refArgument = process.argv[2]
18
- const tagArgument = process.argv[3] || 'latest'
19
-
20
- if (!refArgument) {
21
- console.error('ref argument is missing')
22
- console.error('Usage: npm-version-script-esm.js <ref> [tag]')
23
- process.exit(1)
24
- }
25
-
26
- /**
27
- * Queries the NPM registry for the latest version for the provided base version and tag.
28
- * If the tag is latest, then the base version is returned if it exists. For other tags, the latest
29
- * version found for that base version and tag is returned.
30
- * @param baseVersion The base version to query for, e.g. 2.0.0
31
- * @param tag The tag to query for, e.g. beta or latest
32
- * @returns {string} Returns the version, or '' if not found
33
- */
34
- function getTagVersionFromNpm(baseVersion, tag) {
35
- try {
36
- return JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
37
- .filter(v => tag === 'latest' ? v === baseVersion : v.startsWith(`${baseVersion}-${tag}.`)) // find all published versions for this base version and tag
38
- .reduce((_, current) => current, '') // choose the last as they're sorted in ascending order, or '' if there are none
39
- } catch (e) {
40
- console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`, e)
41
- // throw e;
42
- return ''
43
- }
44
- }
45
-
46
- function desiredTargetVersion(ref) {
47
- // ref is a GitHub action ref string
48
- if (ref.startsWith('refs/pull/')) {
49
- throw new Error('The version script was executed inside a PR!')
50
- }
51
-
52
- assert(ref.startsWith('refs/heads/'))
53
- const branchName = ref.slice('refs/heads/'.length)
54
-
55
- const results = branchName.match(BRANCH_VERSION_PATTERN)
56
- if (results !== null) {
57
- if (results[1] !== tagArgument) {
58
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
59
- }
60
-
61
- return results[2]
62
- }
63
-
64
- throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`)
65
- }
66
-
67
- // derive the base version from the branch ref
68
- const baseVersion = desiredTargetVersion(refArgument)
69
-
70
- // query the npm registry for the latest version of the provided tag name
71
- const latestReleasedVersion = getTagVersionFromNpm(baseVersion, tagArgument) // e.g. 0.7.0-beta.12
72
-
73
- let publishTag
74
-
75
- if (latestReleasedVersion) {
76
- console.warn(`Latest published version for ${baseVersion} with tag ${tagArgument} is ${latestReleasedVersion}`)
77
- publishTag = latestReleasedVersion // set this released beta or alpha to be incremented
78
- } else {
79
- console.warn(`No published versions for ${baseVersion} with tag ${tagArgument}`)
80
- publishTag = baseVersion // start off with a new beta or alpha version
81
- }
82
-
83
- if (packageJSON.version !== publishTag) {
84
- // report the change for CI
85
- console.warn(`Changing version in package.json from ${packageJSON.version} to ${publishTag}`)
86
-
87
- // save the package.json
88
- packageJSON.version = publishTag
89
- fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2))
90
-
91
- // perform the same change to the package-lock.json
92
- const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
93
- packageLockJSON.version = publishTag
94
- fs.writeFileSync('package-lock.json', JSON.stringify(packageLockJSON, null, 2))
95
- } else {
96
- console.warn(`Leaving version in package.json at ${packageJSON.version}`)
97
- }
@@ -1,123 +0,0 @@
1
- name: "Build, Publish and Release"
2
-
3
- #
4
- # Automatically publish beta releases on pushes, require a manual workflow action for production releases
5
- #
6
- # Does the following
7
- # 1 - Run the documentation script against the package
8
- # 2 - Create the npm package using the package.json version tag ( or for beta releases, adds a beta tag and increments as needed )
9
- # 3 - Publish the npm package
10
- # 4 - For releases against the main branch, create a github release as well
11
-
12
- on:
13
- push:
14
- branches: [beta-*.*.*, beta]
15
- workflow_dispatch:
16
-
17
- jobs:
18
- get_tags:
19
- runs-on: ubuntu-latest
20
-
21
- steps:
22
- # checkout repo
23
- - uses: actions/checkout@v4
24
-
25
- # get branch / tag name
26
- - name: Get Branch / Tag Name
27
- id: get_branch
28
- run: |
29
- export BRANCH_NAME=$(if [[ ${GITHUB_REF} =~ "refs/tags/" ]]; then echo ${GITHUB_REF/refs\/tags\//}; else echo ${GITHUB_REF/refs\/heads\//}; fi)
30
- echo $BRANCH_NAME
31
- echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
32
-
33
- # generate the image tag
34
- - name: Get Image Tag
35
- id: get_tag
36
- run: |
37
- export TARGET_IMAGE_TAG=$(if [ "${{ steps.get_branch.outputs.BRANCH_NAME }}" = "main" ]; then echo "main"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}" | awk -F- '{ print $1 }'; fi)
38
- echo $TARGET_IMAGE_TAG
39
- echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_OUTPUT
40
-
41
- outputs:
42
- BRANCH_NAME: ${{ steps.get_branch.outputs.BRANCH_NAME }}
43
- TARGET_IMAGE_TAG: ${{ steps.get_tag.outputs.TARGET_IMAGE_TAG }}
44
-
45
- create_documentation:
46
- runs-on: ubuntu-latest
47
-
48
- steps:
49
- # checkout repo
50
- - uses: actions/checkout@v4
51
- with:
52
- persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
53
- fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
54
-
55
- - uses: actions/setup-node@v4
56
- with:
57
- node-version: lts/*
58
-
59
- - name: Retrieve github-markdown-toc
60
- run: |
61
- wget -q https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
62
- chmod a+x gh-md-toc
63
-
64
- - name: Create Table of Contents
65
- run: |
66
- npm run-script document
67
- rm gh-md-toc
68
-
69
- - name: Commit files
70
- run: |
71
- git config --local user.email "github-actions[bot]@users.noreply.github.com"
72
- git config --local user.name "github-actions[bot]"
73
- git add * || true
74
- git commit -a -m "Update TOC" || true
75
-
76
- - name: Push changes
77
- uses: ad-m/github-push-action@master
78
- with:
79
- github_token: ${{ secrets.GITHUB_TOKEN }}
80
- branch: ${{ github.ref }}
81
-
82
- publish_prod_release:
83
- permissions:
84
- id-token: write
85
- needs: [get_tags, create_documentation]
86
- name: Publish Release Version
87
- if: ${{ needs.get_tags.outputs.BRANCH_NAME == 'main' }}
88
- uses: homebridge/.github/.github/workflows/npm-publish-esm.yml@latest
89
- with:
90
- install_cmd: npm ci
91
- secrets:
92
- npm_auth_token: ${{ secrets.npm_token }}
93
-
94
- publish_test_release:
95
- permissions:
96
- id-token: write
97
- needs: [get_tags, create_documentation]
98
- name: Publish Test Version - ${{ needs.get_tags.outputs.BRANCH_NAME }}
99
- if: ${{ needs.get_tags.outputs.BRANCH_NAME != 'main' }}
100
- uses: homebridge/.github/.github/workflows/npm-publish-esm.yml@latest
101
- with:
102
- tag: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
103
- dynamically_adjust_version: true
104
- npm_version_command: 'pre'
105
- pre_id: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
106
- secrets:
107
- npm_auth_token: ${{ secrets.npm_token }}
108
-
109
- publish_github_release:
110
- needs: [publish_prod_release]
111
- runs-on: ubuntu-latest
112
- steps:
113
- - uses: actions/checkout@v4
114
- - name: Create Release
115
- uses: softprops/action-gh-release@v1
116
- env:
117
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118
- with:
119
- tag_name: ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
120
- name: Release ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
121
- generate_release_notes: true
122
- draft: false
123
- prerelease: false
@@ -1,31 +0,0 @@
1
- name: Build and Lint
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
-
9
- strategy:
10
- matrix:
11
- # the Node.js versions to build on
12
- node-version: [lts/*, latest]
13
-
14
- steps:
15
- - uses: actions/checkout@v4
16
-
17
- - name: Use Node.js ${{ matrix.node-version }}
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version: ${{ matrix.node-version }}
21
-
22
- - name: Install dependencies
23
- run: npm install
24
-
25
- - name: Lint the project
26
- run: npm run lint
27
-
28
- - name: Build the project
29
- run: npm run build
30
- env:
31
- CI: true
package/branding/icon.png DELETED
Binary file
@@ -1 +0,0 @@
1
- export {};
@@ -1,243 +0,0 @@
1
- import { findVal, normalizeMessage, renameKeys, replaceStringsInObject } from './utils';
2
- describe('normalizeMessage', () => {
3
- test('should handle fanFixed tasmotaType', () => {
4
- const message = {
5
- tasmotaType: 'fanFixed',
6
- payload_high_speed: '3',
7
- payload_medium_speed: '2',
8
- payload_low_speed: '1',
9
- pl_off: '0',
10
- pl_on: '1',
11
- val_tpl: '{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}1{%- endif %}',
12
- bri_val_tpl: '{{value_json.FanSpeed*1/3*100}}',
13
- speeds: ['off', 'low', 'medium', 'high'],
14
- cmd_t: 'POWER2',
15
- unique_id: '123',
16
- };
17
- const expectedMessage = {
18
- tasmotaType: 'fanFixed',
19
- pl_hi_spd: '3',
20
- pl_med_spd: '2',
21
- pl_lo_spd: '1',
22
- pl_off: '0',
23
- pl_on: '1',
24
- val_tpl: '{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}1{%- endif %}',
25
- bri_val_tpl: '{{value_json.FanSpeed*1/3*100}}',
26
- spds: ['off', 'low', 'medium', 'high'],
27
- cmd_t: 'FanSpeed',
28
- uniq_id: '123',
29
- };
30
- const normalizedMessage = normalizeMessage(message);
31
- expect(normalizedMessage).toEqual(expectedMessage);
32
- });
33
- test('should rename keys in the message', () => {
34
- const message = {
35
- unique_id: '123',
36
- device_class: 'light',
37
- payload_on: 'ON',
38
- payload_off: 'OFF',
39
- state_topic: 'topic',
40
- };
41
- const expectedMessage = {
42
- uniq_id: '123',
43
- dev_cla: 'light',
44
- pl_on: 'ON',
45
- pl_off: 'OFF',
46
- stat_t: 'topic',
47
- };
48
- const normalizedMessage = normalizeMessage(message);
49
- expect(normalizedMessage).toEqual(expectedMessage);
50
- });
51
- test('should handle additional properties', () => {
52
- const message = {
53
- tasmotaType: 'additional',
54
- payload_high_speed: '3',
55
- payload_medium_speed: '2',
56
- payload_low_speed: '1',
57
- pl_off: '0',
58
- pl_on: '1',
59
- val_tpl: '{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}1{%- endif %}',
60
- bri_val_tpl: '{{value_json.FanSpeed*1/3*100}}',
61
- speeds: ['off', 'low', 'medium', 'high'],
62
- cmd_t: 'POWER2',
63
- unique_id: '123',
64
- additionalProp: 'additionalValue',
65
- };
66
- const expectedMessage = {
67
- tasmotaType: 'additional',
68
- pl_hi_spd: '3',
69
- pl_med_spd: '2',
70
- pl_lo_spd: '1',
71
- pl_off: '0',
72
- pl_on: '1',
73
- val_tpl: '{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}1{%- endif %}',
74
- bri_val_tpl: '{{value_json.FanSpeed*1/3*100}}',
75
- spds: ['off', 'low', 'medium', 'high'],
76
- cmd_t: 'POWER2',
77
- uniq_id: '123',
78
- additionalProp: 'additionalValue',
79
- };
80
- const normalizedMessage = normalizeMessage(message);
81
- expect(normalizedMessage).toEqual(expectedMessage);
82
- });
83
- // Add more tests for other scenarios...
84
- });
85
- describe('renameKeys', () => {
86
- test('should rename keys in a single object', () => {
87
- const obj = {
88
- unique_id: '123',
89
- device_class: 'light',
90
- payload_on: 'ON',
91
- payload_off: 'OFF',
92
- state_topic: 'topic',
93
- };
94
- const mapShortToLong = {
95
- unique_id: 'uniq_id',
96
- device_class: 'dev_cla',
97
- payload_on: 'pl_on',
98
- payload_off: 'pl_off',
99
- state_topic: 'stat_t',
100
- };
101
- const expectedObj = {
102
- uniq_id: '123',
103
- dev_cla: 'light',
104
- pl_on: 'ON',
105
- pl_off: 'OFF',
106
- stat_t: 'topic',
107
- };
108
- const renamedObj = renameKeys(obj, mapShortToLong);
109
- expect(renamedObj).toEqual(expectedObj);
110
- });
111
- test('should rename keys in an array of objects', () => {
112
- const arr = [
113
- {
114
- unique_id: '123',
115
- device_class: 'light',
116
- payload_on: 'ON',
117
- payload_off: 'OFF',
118
- state_topic: 'topic',
119
- },
120
- {
121
- unique_id: '456',
122
- device_class: 'fan',
123
- payload_on: 'ON',
124
- payload_off: 'OFF',
125
- state_topic: 'topic',
126
- },
127
- ];
128
- const mapShortToLong = {
129
- unique_id: 'uniq_id',
130
- device_class: 'dev_cla',
131
- payload_on: 'pl_on',
132
- payload_off: 'pl_off',
133
- state_topic: 'stat_t',
134
- };
135
- const expectedArr = [
136
- {
137
- uniq_id: '123',
138
- dev_cla: 'light',
139
- pl_on: 'ON',
140
- pl_off: 'OFF',
141
- stat_t: 'topic',
142
- },
143
- {
144
- uniq_id: '456',
145
- dev_cla: 'fan',
146
- pl_on: 'ON',
147
- pl_off: 'OFF',
148
- stat_t: 'topic',
149
- },
150
- ];
151
- const renamedArr = renameKeys(arr, mapShortToLong);
152
- expect(renamedArr).toEqual(expectedArr);
153
- });
154
- // Add more tests for other scenarios...
155
- });
156
- describe('replaceStringsInObject', () => {
157
- test('should replace strings in a single object', () => {
158
- const obj = {
159
- name: 'John Doe',
160
- age: 30,
161
- address: '123 Main St',
162
- };
163
- const findStr = 'John';
164
- const replaceStr = 'Jane';
165
- const expectedObj = {
166
- name: 'Jane Doe',
167
- age: 30,
168
- address: '123 Main St',
169
- };
170
- const replacedObj = replaceStringsInObject(obj, findStr, replaceStr);
171
- expect(replacedObj).toEqual(expectedObj);
172
- });
173
- test('should replace strings in an array of objects', () => {
174
- const arr = [
175
- {
176
- name: 'John Doe',
177
- age: 30,
178
- address: '123 Main St',
179
- },
180
- {
181
- name: 'Jane Smith',
182
- age: 25,
183
- address: '456 Elm St',
184
- },
185
- ];
186
- const findStr = 'Doe';
187
- const replaceStr = 'Smith';
188
- const expectedArr = {
189
- '0': {
190
- name: 'John Smith',
191
- age: 30,
192
- address: '123 Main St',
193
- },
194
- '1': {
195
- name: 'Jane Smith',
196
- age: 25,
197
- address: '456 Elm St',
198
- },
199
- };
200
- const replacedArr = replaceStringsInObject(arr, findStr, replaceStr);
201
- expect(replacedArr).toEqual(expectedArr);
202
- });
203
- // Add more tests for other scenarios...
204
- });
205
- describe('findVal', () => {
206
- test('should find value in a flat object', () => {
207
- const object = {
208
- key1: 'value1',
209
- key2: 'value2',
210
- key3: 'value3',
211
- };
212
- const key = 'key2';
213
- const expectedValue = 'value2';
214
- const result = findVal(object, key);
215
- expect(result).toEqual(expectedValue);
216
- });
217
- test('should find value in a nested object', () => {
218
- const object = {
219
- key1: 'value1',
220
- key2: {
221
- key3: 'value3',
222
- key4: 'value4',
223
- },
224
- key5: 'value5',
225
- };
226
- const key = 'key4';
227
- const expectedValue = 'value4';
228
- const result = findVal(object, key);
229
- expect(result).toEqual(expectedValue);
230
- });
231
- test('should return undefined if key is not found', () => {
232
- const object = {
233
- key1: 'value1',
234
- key2: 'value2',
235
- key3: 'value3',
236
- };
237
- const key = 'key4';
238
- const result = findVal(object, key);
239
- expect(result).toBeUndefined();
240
- });
241
- // Add more tests for other scenarios...
242
- });
243
- //# sourceMappingURL=utils.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAExF,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC9C,MAAM,OAAO,GAAG;YACd,WAAW,EAAE,UAAU;YACvB,kBAAkB,EAAE,GAAG;YACvB,oBAAoB,EAAE,GAAG;YACzB,iBAAiB,EAAE,GAAG;YACtB,MAAM,EAAE,GAAG;YACX,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,sFAAsF;YAC/F,WAAW,EAAE,iCAAiC;YAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC;YACxC,KAAK,EAAE,QAAQ;YACf,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,MAAM,eAAe,GAAG;YACtB,WAAW,EAAE,UAAU;YAC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;IACjC,CAAC,CAAC,CAAC;IAEH,wCAAwC;AAE1C,CAAC,CAAC,CAAC"}
package/jest.config.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { JestConfigWithTsJest } from "ts-jest";
2
-
3
- const config: JestConfigWithTsJest = {
4
- verbose: true,
5
- transform: {
6
- "^.+\\.ts?$": [
7
- "ts-jest",
8
- {
9
- useESM: true,
10
- },
11
- ],
12
- },
13
- extensionsToTreatAsEsm: [".ts"],
14
- moduleNameMapper: {
15
- "^(\\.{1,2}/.*)\\.js$": "$1",
16
- },
17
- };
18
-
19
- export default config;