Skip to content

Commit

Permalink
feat: Add backup and restore functionality
Browse files Browse the repository at this point in the history
- Update dependencies
- Update mocha setup due to latest changes
- Drop nyc and use c8
- Add backup and restore functionality
- Update readme
  • Loading branch information
holomekc committed Jan 5, 2025
1 parent b065c9e commit 4b54dc0
Show file tree
Hide file tree
Showing 20 changed files with 917 additions and 892 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Pull Request Labeler"
name: 'Pull Request Labeler'
on:
- pull_request

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

env:
NODE_VERSION: 20
NODE_VERSION: 22
FORCE_COLOR: 1
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
node-version: [ 18.x, 20.x ]
node-version: [ 20.x, 22.x ]

steps:
- name: Checkout code
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ typings/
.nyc_output

.yarn

# some test relevant files
coverage
*.home
*.backup
5 changes: 1 addition & 4 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"extension": ["ts"],
"spec": "test/**/*.spec.ts",
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm"],
"require": ["ts-node/register"],
"recursive": true
}
2 changes: 1 addition & 1 deletion .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
branches: [ 'master' ]
branches: ['master']
repositoryUrl: 'git@github.com:holomekc/bosch-smart-home-bridge.git'
tagFormat: ${version}
plugins:
Expand Down
1 change: 1 addition & 0 deletions .run/Tests E2E Template.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<env name="BSHC_CERT" value="" />
<env name="BSHC_HOST" value="" />
<env name="BSHC_PRIV" value="" />
<env name="TS_NODE_PROJECT" value="./tsconfig.spec.json" />
</envs>
<ui>bdd</ui>
<extra-mocha-options>--grep e2e --exit</extra-mocha-options>
Expand Down
3 changes: 3 additions & 0 deletions .run/Tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
<working-directory>$PROJECT_DIR$</working-directory>
<pass-parent-env>true</pass-parent-env>
<envs>
<env name="TS_NODE_PROJECT" value="./tsconfig.spec.json" />
</envs>
<ui>bdd</ui>
<extra-mocha-options>--grep should --exit</extra-mocha-options>
<test-kind>DIRECTORY</test-kind>
Expand Down
6 changes: 3 additions & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ cacheFolder: ./.yarn/cache

enableGlobalCache: false

httpProxy: "${http_proxy:-}"
httpProxy: '${http_proxy:-}'

httpsProxy: "${https_proxy:-}"
httpsProxy: '${https_proxy:-}'

nodeLinker: node-modules

npmAuthToken: "${NPM_TOKEN:-}"
npmAuthToken: '${NPM_TOKEN:-}'
119 changes: 100 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Allows communication to Bosch Smart Home Controller (BSHC)

## Getting started

You need to create a new instance of BoschSmartHomeBridge (BSHB). Therefore, you need to use BoschSmartHomeBridgeBuilder.
You need to create a new instance of BoschSmartHomeBridge (BSHB). Therefore, you need to use
BoschSmartHomeBridgeBuilder.
The builder will force you to set every mandatory properties:

- host name / ip address of BSHC
Expand All @@ -28,10 +29,10 @@ The builder will force you to set every mandatory properties:
```typescript
const certificate = BshbUtils.generateClientCertificate();
const bshb = BoschSmartHomeBridgeBuilder.builder()
.withHost('192.168.0.10')
.withClientCert(certificate.cert)
.withClientPrivateKey(certificate.private)
.build();
.withHost('192.168.0.10')
.withClientCert(certificate.cert)
.withClientPrivateKey(certificate.private)
.build();
```

## Pairing
Expand Down Expand Up @@ -62,28 +63,108 @@ If you are interested in updates from bshc you can use long polling. Therefore,

```typescript
bshb
.getBshcClient()
.subscribe()
.subscribe(response => {
bshb
.getBshcClient()
.longPolling(response.parsedResponse.result)
.subscribe(info => {
// do something with the information
// also you need to call longPolling again after connection close
});
});
.getBshcClient()
.subscribe()
.subscribe(response => {
bshb
.getBshcClient()
.longPolling(response.parsedResponse.result)
.subscribe(info => {
// do something with the information
// also you need to call longPolling again after connection close
});
});
```

Do not forget to unsubscribe. E.g. in error case or on application end.

```typescript
bshb
.getBshcClient()
.unsubscribe(response.parsedResponse.result)
.subscribe(() => {});
.getBshcClient()
.unsubscribe(response.parsedResponse.result)
.subscribe(() => {
});
```

## Backup & Restore

With this new feature provided by bosch you can automate the backup process.

Example can be found in the e2e test of the test folder.

The workflow is:

1. Create a backup
```typescript
bshb.getBshcClient().createBackup('SystemPassword', 'encryptionPassword')
```
2. Wait for backup status READY
```typescript
bshb.getBshcClient().getBackupStatus()
```
3. Download backup file
```typescript
bshb.getBshcClient().getBackup()
```
4. Upload restore file
```typescript
bshb.getBshcClient().uploadRestoreFile(binaryData)
```
5. Wait for restore status BACKUP_UPLOADED
```typescript
bshb.getBshcClient().getRestoreStatus()
```
6. Press pairing button on controller. Once for Controller II and 3s for Controller I
7. Wait for restore status RESTORE_AUTHORIZED
```typescript
bshb.getBshcClient().getRestoreStatus()
```
8. Start restore process
```typescript
bshb.getBshcClient().startRestoreProcess('encryptionPassword')
```
9. Wait for restore status RESTORED. The status might be in RESTORING for a while,
and due to the restart the controller might not be available for some time as well.
```typescript
bshb.getBshcClient().getRestoreStatus()
```
10. Check partner restore status (Only possible if status is in RESTORED*)
```typescript
bshb.getBshcClient().getPartnerRestoreStatus()
```
11. Complete the process or cancel the process (except if in RESTORING) via
```typescript
bshb.getBshcClient().deleteRestoreFile()
bshb.getBshcClient().deleteBackup()
```

See api documentation for further details.

Uploading incomplete files might end up in a timeout, where the Controller appears to be stuck
in RESTORING. If this is the case wait until the controller is changing the status to ERROR,
and then restart the controller. During my tests without the restart the complete backup
and restore feature is not working properly anymore.

## Examples

You can find an example in test directory. Npm arguments must be set manually.

## Disclaimer

By using this software, you acknowledge and accept the following terms:

1. **Bosch Smart Home Controller**:

The use of this software with the Bosch Smart Home Controller I and II is at your own risk. The developer is not
liable for any damage to the hardware, including but not limited to physical damage, malfunction, or failure of the
Bosch Smart Home Controller. Users are advised to handle the devices with care and follow all manufacturer guidelines
and recommendations.

2. **Data Loss**:

While efforts have been made to ensure the reliability of the backup and restore functionality, the developer cannot
guarantee the safety of your data. By using the backup and restore features, you understand and accept that there is
a risk of data loss. This may include, but is not limited to, loss of settings, configurations, or other user data
stored on the Bosch Smart Home Controller. It is strongly recommended that users perform regular backups and store
them in a secure location. The developer shall not be held responsible for any data loss or corruption arising from
the use of these features.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.4.2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"postinstall": "husky && node disable-publish-semantic-release-github.js",
"prepack": "pinst --disable",
Expand All @@ -13,7 +14,8 @@
"lint": "eslint --max-warnings 0 .",
"lint:fix": "eslint --max-warnings 0 --fix .",
"prettier": "prettier --write .",
"test": "cross-env TS_NODE_PROJECT='./tsconfig.spec.json' nyc mocha --grep should --exit",
"test": "cross-env TS_NODE_PROJECT='./tsconfig.spec.json' c8 mocha --grep should --exit",
"test:watch": "cross-env TS_NODE_PROJECT='./tsconfig.spec.json' c8 mocha --grep should",
"release": "semantic-release"
},
"keywords": [
Expand Down Expand Up @@ -55,6 +57,7 @@
"@types/uuid": "10.0.0",
"@typescript-eslint/eslint-plugin": "8.19.0",
"@typescript-eslint/parser": "8.19.0",
"c8": "10.1.3",
"chai": "5.1.2",
"conventional-changelog-conventionalcommits": "8.0.0",
"cross-env": "7.0.3",
Expand All @@ -66,7 +69,6 @@
"express": "4.21.2",
"husky": "9.1.7",
"mocha": "11.0.1",
"nyc": "17.1.0",
"pinst": "3.0.0",
"prettier": "3.4.2",
"prettier-eslint": "16.3.0",
Expand Down
Loading

0 comments on commit 4b54dc0

Please sign in to comment.