Skip to content

Commit

Permalink
Tweaked the setup flow for Homebridge to resolve issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
nberardi committed Dec 4, 2022
1 parent 62c8247 commit a7b28de
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# scrypted-dyson

The Cloud Setup is recommend if this is your first time setting up Dyson. If you have previously setup Dyson with Homebridge the Manual Setup will be quicker to get up and running with your existing config file.
The Cloud Setup is recommend if this is your first time setting up Dyson. If you have previously setup Dyson with Homebridge the Homebridge Setup will be quicker to get up and running with your existing config file.

## Cloud Setup

Expand All @@ -20,17 +20,29 @@ A value will appear in the `Token` field.

The Dyson API prevents multiple login's at the same time. However once the `Token` code has been retreived and `Local Password` has been downloaded for each device the cloud connection is no longer needed. If you are running into trouble log out of your Dyson App, and wait for 15 minutes before clicking `Release Plugin`. At that time you should receive a new email code.

## Manual Setup
## Homebridge Setup

*This is recommended if you have previous setup the homebridge config, and already have the `ipAddress`, `serialNumber`, and `credentials` from the config file.*

1. Click `Add Device`
2. Copy the `ipAddress` and `credentials` from the config file into the setup screen.

### FAQ's

#### Why do you only need the `credentials`?

That is because all the information that is required is encoded into the `credentials` string in a base64 format. If you are curious you can take the credentials and paste it into [this website](https://www.base64decode.org) to see all the data contained in that string.

## Manual Setup

1. Look up your `Product Type` before starting to add the device.
2. Click `Add Device`
3. Provide a `Name` for your device.
4. Copy the `ipAddress`, `serialNumber`, and `credentials` from the config file into the setup screen.
5. Select the `Product Type` that you found in step 1.
3. Provide a `Name`, `IP Address`, `Serial Number`, and `Credentials` for your device.
4. Select the `Product Type` that you found in step 1.

### FAQ's

### How do I find my `Product Type`?
#### How do I find my `Product Type`?

To find your product type, you need to know your model of the device:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrypted-dyson",
"version": "0.2.0",
"version": "0.2.1",
"description": "Scrypted plugin for Dyson",
"author": "nberardi",
"license": "MIT",
Expand Down
58 changes: 43 additions & 15 deletions src/DysonPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,73 @@ export class DysonPlugin extends ScryptedDeviceBase implements DeviceDiscovery,

async getCreateDeviceSettings(): Promise<Setting[]> {
return [
{
key: 'name',
title: 'Name',
description: 'The name of the fan.',
},
{
key: 'ipAddress',
title: "IP Address",
type: "string",
placeholder: "192.168.1.XX",
description: "The IP Address of the fan on your local network."
},
{
key: 'homebridgeCredentials',
title: 'Homebridge Credentials (optional)',
type: "string",
description: "The credentials entered into Homebridge Dyson Plugin, if you enter this, you won't need anything else besides the IP Address. This is a base64 string of the below data."
},
{
key: 'name',
title: 'Name (optional)',
description: 'The name of the fan.',
},
{
key: "serialNumber",
title: "Serial Number",
title: "Serial Number (optional)",
type: "string",
description: "The Serial Number of the Dyson fan.",
description: "(required if Homebridge Credentials not entered) The Serial Number of the Dyson fan.",
},
{
key: "localPassword",
title: "Credentials",
title: "Credentials (optional)",
type: "string",
description: "Local credentials for accessing the device.",
description: "(required if Homebridge Credentials not entered) Local credentials for accessing the device.",
},
{
key: "productType",
title: "Product Type",
title: "Product Type (optional)",
type: "string",
description: "The numberical product type provided by Dyson.",
description: "(required if Homebridge Credentials not entered) The numberical product type provided by Dyson.",
choices: ['358', '358E', '438', '438E', '455', '469', '475', '520', '527', '527E']
}
];
}

async createDevice(settings: DeviceCreatorSettings): Promise<string> {
const name = settings.name.toString();
const ipAddress = settings.ipAddress.toString();
const serialNumber = settings.serialNumber.toString();
const productType = settings.productType.toString();
const localPassword = settings.localPassword.toString();

/// TEST: eyJTZXJpYWwiOiJON1ItRVUtUEpBWFhYMEEiLCJOYW1lIjoiTXkgT2ZmaWNlIiwiVmVyc2lvbiI6IkVDRzJQRi4zMC4wNi4wMDMuMDAwMiIsIkxvY2FsQ3JlZGVudGlhbHMiOiJob21lYnJpZGdlLi4udGVzdCIsIkF1dG9VcGRhdGUiOnRydWUsIk5ld1ZlcnNpb25BdmFpbGFibGUiOmZhbHNlLCJQcm9kdWN0VHlwZSI6IjUyNyIsIkNvbm5lY3Rpb25UeXBlIjoid3NzIiwicGFzc3dvcmQiOiJob21lYnJpZGdlLi4udGVzdD09In0=
const homebridgeCredentials = settings.homebridgeCredentials?.toString();

let name = settings.name?.toString();
let serialNumber = settings.serialNumber?.toString();
let productType = settings.productType?.toString();
let localPassword = settings.localPassword?.toString();
let firmware = undefined;

if (homebridgeCredentials !== undefined && homebridgeCredentials.length > 0) {
const homebridgeCredentialsJson = JSON.parse(Buffer.from(homebridgeCredentials.trim(), 'base64').toString('utf8'));

name = homebridgeCredentialsJson.Name;
serialNumber = homebridgeCredentialsJson.Serial;
productType = homebridgeCredentialsJson.ProductType;
firmware = homebridgeCredentialsJson.Version;
localPassword = homebridgeCredentialsJson.password;
}

if (!name || !serialNumber || !productType || !localPassword) {
this.log.e('Could not complete manual creation of Dyson Fan, aborting creation due to missing value that is required.');
return;
}

const product = ProductInfo.get(productType);

const d: Device = {
Expand All @@ -113,6 +140,7 @@ export class DysonPlugin extends ScryptedDeviceBase implements DeviceDiscovery,
model: product.model,
manufacturer: 'Dyson',
serialNumber: serialNumber,
firmware: firmware,
version: productType,
metadata: {
localPasswordHash: localPassword,
Expand Down

0 comments on commit a7b28de

Please sign in to comment.