Skip to content

Commit 304742c

Browse files
committed
Migrated to typescript
1 parent 896fbed commit 304742c

21 files changed

+2412
-2891
lines changed

.github/copilot-instructions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ This is an ioBroker adapter for Sonoff/Tasmota devices that enables MQTT communi
2222
**Repository Structure:**
2323
- `admin/` - Admin UI configuration files and translations
2424
- `lib/` - Core library files
25-
- `datapoints.js` - Defines all supported Tasmota datapoints and their properties
26-
- `server.js` - Main MQTT server implementation
27-
- `main.js` - Adapter entry point
25+
- `datapoints.ts` - Defines all supported Tasmota datapoints and their properties
26+
- `server.ts` - Main MQTT server implementation
27+
- `main.ts` - Adapter entry point
2828
- `test/` - Test files
2929
- `integration.js` - Integration tests for MQTT message processing
3030
- `testPackageFiles.js` - Validates package.json and io-package.json
3131

3232
**Key Concepts:**
3333

3434
#### Datapoints
35-
Datapoints in `lib/datapoints.js` define how Tasmota device parameters are mapped to ioBroker states. Each datapoint has:
35+
Datapoints in `lib/datapoints.ts` define how Tasmota device parameters are mapped to ioBroker states. Each datapoint has:
3636
- `type` - Data type (string, number, boolean)
3737
- `role` - ioBroker role (state, level, switch, etc.)
3838
- `read/write` - Access permissions
@@ -46,7 +46,7 @@ The adapter processes MQTT messages from Tasmota devices:
4646
- `cmnd/*` - Commands to devices
4747

4848
**Development Guidelines:**
49-
1. **Adding New Datapoints**: Update `lib/datapoints.js` with proper type definitions
49+
1. **Adding New Datapoints**: Update `lib/datapoints.ts` with proper type definitions
5050
2. **Testing**: Add corresponding test cases in `test/integration.js` with real MQTT message examples
5151
3. **Translations**: When adding new UI elements to admin configuration:
5252
- Add all English text entries to `admin/i18n/en/translations.json`
@@ -212,7 +212,7 @@ tests.integration(path.join(__dirname, '..'), {
212212
## Core Development Principles
213213

214214
### Adapter Structure
215-
- Main adapter code goes in `main.js` (entry point) or a modular structure with `lib/` directory
215+
- Main adapter code goes in `main.ts` (entry point) or a modular structure with `lib/` directory
216216
- Admin UI configuration in `admin/` directory
217217
- Adapter metadata in `io-package.json`
218218
- npm package information in `package.json`

.github/workflows/test-and-release.yml

Lines changed: 39 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ on:
1111
- '*'
1212
tags:
1313
# normal versions
14-
- "v?[0-9]+.[0-9]+.[0-9]+"
14+
- 'v?[0-9]+.[0-9]+.[0-9]+'
1515
# pre-releases
16-
- "v?[0-9]+.[0-9]+.[0-9]+-**"
16+
- 'v?[0-9]+.[0-9]+.[0-9]+-**'
1717
pull_request: {}
1818

19-
permissions:
20-
id-token: write # Required for OIDC
21-
contents: read
19+
# Cancel previous PR/branch runs when a new commit is pushed
20+
concurrency:
21+
group: ${{ github.ref }}
22+
cancel-in-progress: true
2223

2324
jobs:
2425
# Performs quick checks before the expensive test runs
@@ -28,127 +29,61 @@ jobs:
2829
runs-on: ubuntu-latest
2930

3031
steps:
31-
- uses: actions/checkout@v6
32-
- name: Use Node.js 22.x
33-
uses: actions/setup-node@v6
32+
- uses: ioBroker/testing-action-check@v1
3433
with:
35-
node-version: 22.x
36-
37-
38-
- name: Install Dependencies
39-
run: npm ci
40-
41-
# - name: Perform a type check
42-
# run: npm run check:ts
43-
# env:
44-
# CI: true
45-
- name: Lint code
46-
run: npm run lint
47-
# - name: Test package files
48-
# run: npm run test:package
34+
node-version: '22.x'
35+
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
36+
# install-command: 'npm install'
37+
lint: true
4938

5039
# Runs adapter tests on all supported node versions and OSes
5140
adapter-tests:
5241
if: contains(github.event.head_commit.message, '[skip ci]') == false
5342

5443
needs: [check-and-lint]
5544

56-
runs-on: ${{ matrix.os }}
45+
runs-on: ubuntu-latest
5746
strategy:
5847
matrix:
59-
node-version: [18.x, 20.x, 22.x, 24.x]
60-
os: [ubuntu-latest, windows-latest, macos-latest]
48+
node-version: [20.x, 22.x, 24.x]
6149

6250
steps:
63-
- uses: actions/checkout@v6
64-
- name: Use Node.js ${{ matrix.node-version }}
65-
uses: actions/setup-node@v6
51+
- uses: ioBroker/testing-action-adapter@v1
6652
with:
53+
build: true
54+
os: 'ubuntu-latest'
6755
node-version: ${{ matrix.node-version }}
6856

69-
- name: Install Dependencies
70-
run: npm ci
71-
72-
- name: Run local tests
73-
run: npm test
74-
# - name: Run unit tests
75-
# run: npm run test:unit
76-
# - name: Run integration tests # (linux/osx)
77-
# if: startsWith(runner.OS, 'windows') == false
78-
# run: DEBUG=testing:* npm run test:integration
79-
# - name: Run integration tests # (windows)
80-
# if: startsWith(runner.OS, 'windows')
81-
# run: set DEBUG=testing:* & npm run test:integration
82-
8357
# Deploys the final package to NPM
8458
deploy:
85-
needs: [adapter-tests]
59+
needs: [check-and-lint, adapter-tests]
8660

87-
# Trigger this step only when a commit on master is tagged with a version number
61+
# Permissions are required to create GitHub releases and npm trusted publishing
62+
permissions:
63+
contents: write
64+
id-token: write
65+
66+
# Trigger this step only when a commit on any branch is tagged with a version number
8867
if: |
8968
contains(github.event.head_commit.message, '[skip ci]') == false &&
9069
github.event_name == 'push' &&
91-
startsWith(github.ref, 'refs/tags/')
70+
startsWith(github.ref, 'refs/tags/v')
71+
9272
runs-on: ubuntu-latest
9373

9474
steps:
95-
- name: Checkout code
96-
uses: actions/checkout@v6
97-
98-
- name: Use Node.js 22.x
99-
uses: actions/setup-node@v6
100-
with:
101-
node-version: 22.x
102-
103-
- name: Extract the version and commit body from the tag
104-
id: extract_release
105-
# The body may be multiline, therefore we need to escape some characters
106-
run: |
107-
VERSION="${{ github.ref }}"
108-
VERSION=${VERSION##*/}
109-
VERSION=${VERSION##*v}
110-
echo "::set-output name=VERSION::$VERSION"
111-
BODY=$(git show -s --format=%b)
112-
BODY="${BODY//'%'/'%25'}"
113-
BODY="${BODY//$'\n'/'%0A'}"
114-
BODY="${BODY//$'\r'/'%0D'}"
115-
echo "::set-output name=BODY::$BODY"
116-
117-
- name: Install Dependencies
118-
run: npm ci
119-
120-
# - name: Create a clean build
121-
# run: npm run build
122-
- name: Publish package to npm
123-
run: |
124-
npm install -g npm@latest
125-
npm -v
126-
npm whoami
127-
npm publish
128-
129-
- name: Create Github Release
130-
uses: actions/create-release@v1
131-
env:
132-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
- uses: ioBroker/testing-action-deploy@v1
13376
with:
134-
tag_name: ${{ github.ref }}
135-
release_name: Release v${{ steps.extract_release.outputs.VERSION }}
136-
draft: false
137-
# Prerelease versions create pre-releases on GitHub
138-
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
139-
body: ${{ steps.extract_release.outputs.BODY }}
140-
141-
- name: Notify Sentry.io about the release
142-
run: |
143-
npm i -g @sentry/cli
144-
export SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
145-
export SENTRY_URL=https://sentry.iobroker.net
146-
export SENTRY_ORG=iobroker
147-
export SENTRY_PROJECT=iobroker-sonoff
148-
export SENTRY_VERSION=iobroker.sonoff@${{ steps.extract_release.outputs.VERSION }}
149-
sentry-cli releases new $SENTRY_VERSION
150-
sentry-cli releases set-commits $SENTRY_VERSION --auto
151-
sentry-cli releases finalize $SENTRY_VERSION
152-
153-
# Add the following line BEFORE finalize if sourcemap uploads are needed
154-
# sentry-cli releases files $SENTRY_VERSION upload-sourcemaps build/
77+
node-version: '22.x'
78+
build: true
79+
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
80+
# install-command: 'npm install'
81+
# npm-token: ${{ secrets.NPM_TOKEN }}
82+
github-token: ${{ secrets.GITHUB_TOKEN }}
83+
sentry: true
84+
sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
85+
sentry-url: https://sentry.iobroker.net
86+
sentry-org: iobroker
87+
sentry-project: iobroker-sonoff
88+
sentry-version-prefix: iobroker.sonoff
89+
sentry-sourcemap-paths: build/

.mocharc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2025 bluefox <dogafox@gmail.com>
3+
Copyright (c) 2014-2026 bluefox <dogafox@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ States:
302302

303303
The MIT License (MIT)
304304

305-
Copyright (c) 2017-2025, bluefox <dogafox@gmail.com>
305+
Copyright (c) 2017-2026, bluefox <dogafox@gmail.com>
306306

307307
Permission is hereby granted, free of charge, to any person obtaining a copy
308308
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)