Skip to content

Commit

Permalink
"Enhanced Device Information and Serial Number Handling
Browse files Browse the repository at this point in the history
- Added functionality to parse and set the model name based on serial numbers.
- Included method to set 'V-Zug' as the manufacturer for all devices.
- Refined JSON parsing for improved model data management.
- Enhanced serial number handling for device identification in HomeKit."
  • Loading branch information
rtuszik committed Dec 2, 2023
1 parent cb59d06 commit aa73f55
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 17 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Integrate your V-ZUG appliances into Apple HomeKit using this Homebridge plugin, which currently supports status monitoring via an unofficial REST API. This plugin provides a HomeKit switch to reflect the operational status of your V-ZUG appliance, allowing you to check if the device is active.


## Features

- **Status Monitoring**: Exposes the operational status of your V-ZUG appliances as a switch in HomeKit, showing if the device is active.

## Installation

1. **Install Homebridge**:
Expand All @@ -25,7 +30,6 @@ Add your V-ZUG appliances to your Homebridge `config.json`:
"name": "DEVICE_NAME",
"ip": "DEVICE_IP_ADDRESS"
}
// Add more devices as needed
]
}
```
Expand All @@ -48,16 +52,15 @@ Add your V-ZUG appliances to your Homebridge `config.json`:
}
```

## Current Functionality

- **Status Monitoring**: The plugin currently exposes the operational status of your V-ZUG appliances as a switch in HomeKit, showing if the device is active.

## Supported Models

- Currently tested with:
- V-Zug CombairSteamer V6000 60
- V-Zug CombairSteamer V6000 60Y
- V-Zug CombairSteamer V6000 45F

The plugin will automatically find the Model and Serial Number of your Device and populate the relevant fields for HomeKit

## Developer's Note

This is my first Homebridge plugin, primarily aimed at status monitoring for V-ZUG appliances. It's pretty basic – mainly showing the on/off status. Since it's my initial release, there might be some room for improvement. I'm open to feedback and suggestions!
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge-vzug",
"name": "homebridge-vzug",
"version": "1.1.1",
"version": "1.2.0",
"description": "Integration of V-ZUG Appliances using unofficial python API",
"license": "Apache-2.0",
"repository": {
Expand Down
51 changes: 43 additions & 8 deletions src/VZugAccessory.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
import { Service, PlatformAccessory, Logger, API } from 'homebridge';
import axios from 'axios';
import { DeviceConfig } from './VZugPlatform';

import * as fs from 'fs';
import * as path from 'path';

export class VZugAccessory {
private service: Service;
private models: any; // To store the model data

Check warning on line 9 in src/VZugAccessory.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 9 in src/VZugAccessory.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

constructor(
private readonly log: Logger,
private readonly api: API,
private readonly accessory: PlatformAccessory,
private readonly config: DeviceConfig,
) {
// Assuming a Switch Service for demonstration
this.service = new this.api.hap.Service.Switch(accessory.displayName);

// Register handlers for the On/Off Characteristic
this.service.getCharacteristic(this.api.hap.Characteristic.On)
.on('get', this.handleOnGet.bind(this))
.on('set', this.handleOnSet.bind(this));

// Add the service to the accessory
this.accessory.addService(this.service);

// Set up polling to periodically fetch device status
// Load model data
this.models = JSON.parse(fs.readFileSync(path.join(__dirname, 'vzugmodel.json'), 'utf8'));

this.setSerialNumber();
this.setManufacturer();

setInterval(() => {
this.fetchDeviceStatus();
}, 10000); // Poll every 10 seconds (10000 milliseconds)
}, 10000);
}

async setSerialNumber() {
try {
const url = `http://${this.config.ip}/ai?command=getDeviceStatus`;
const response = await axios.get(url);
if (response.status === 200) {
const serialNumber = response.data.Serial;
const modelNumber = serialNumber.substring(0, 5);
const modelName = this.findModelName(modelNumber);

this.accessory.getService(this.api.hap.Service.AccessoryInformation)
.setCharacteristic(this.api.hap.Characteristic.SerialNumber, serialNumber)
.setCharacteristic(this.api.hap.Characteristic.Model, modelName);
}
} catch (error) {
this.log.error('Error fetching serial number:', error instanceof Error ? error.message : 'Unknown error');
}
}

findModelName(modelNumber: string): string {
for (const model of this.models) {
if (model.Model.includes(modelNumber)) {
return model.Name;
}
}
return 'Unknown Model';
}

private setManufacturer() {
this.accessory.getService(this.api.hap.Service.AccessoryInformation)
.setCharacteristic(this.api.hap.Characteristic.Manufacturer, 'V-Zug');
}


async fetchDeviceStatus() {
try {
const url = `http://${this.config.ip}/ai?command=getDeviceStatus`;
Expand Down Expand Up @@ -62,8 +99,6 @@ export class VZugAccessory {

handleOnSet(value, callback) {
// Implement logic to set the new state
// This part is device-specific and depends on available API commands
// Handle errors appropriately, similar to handleOnGet
callback(null);
}
}
1 change: 0 additions & 1 deletion src/VZugPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class VZugPlatform implements DynamicPlatformPlugin {

this.api.on('didFinishLaunching', () => {
this.log.debug('Executed didFinishLaunching callback');
// Perform further operations here if necessary
});
}

Expand Down
Loading

0 comments on commit aa73f55

Please sign in to comment.