Skip to content

Commit

Permalink
* (bluefox) used library @iobroker/type-detector
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 24, 2023
1 parent 2c86105 commit dabc96c
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 177 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- Get login & pass from iot (new js-controller version) may be

## Changelog
### **WORK IN PROGRESS**
* (bluefox) used library `@iobroker/type-detector`

### 0.0.2 (2023-10-23)
* (bluefox) Initial commit

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@iobroker/adapter-core": "^3.0.4",
"@project-chip/matter.js": "^0.6.0",
"@project-chip/matter-node.js": "^0.6.0",
"iobroker.type-detector": "^2.0.6",
"@iobroker/type-detector": "^3.0.5",
"axios": "^1.5.1",
"jsonwebtoken": "^9.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"iobroker.type-detector": "^2.0.6",
"iobroker.type-detector": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
Expand Down
37 changes: 0 additions & 37 deletions src/iobroker.type-detector.d.ts

This file was deleted.

81 changes: 41 additions & 40 deletions src/lib/deviceFabric.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GenericDevice, { DetectedDevice, DeviceOptions, DeviceType } from './devices/GenericDevice';
import GenericDevice, { DetectedDevice, DeviceOptions } from './devices/GenericDevice';
import { Types } from '@iobroker/type-detector';

import AirCondition from './devices/AirCondition';
import Blind from './devices/Blind';
Expand Down Expand Up @@ -40,48 +41,48 @@ import WeatherForecast from './devices/WeatherForecast';
import Warning from './devices/Warning';

const types = {
[DeviceType.AirCondition]: AirCondition,
[DeviceType.Blind]: Blind,
[DeviceType.BlindButtons]: BlindButtons,
[DeviceType.Button]: Button,
[DeviceType.ButtonSensor]: ButtonSensor,
[DeviceType.Camera]: Camera,
[DeviceType.Url]: Image,
[DeviceType.Chart]: Chart,
[DeviceType.Image]: Image,
[DeviceType.Dimmer]: Dimmer,
[DeviceType.Door]: Door,
[DeviceType.FireAlarm]: FireAlarm,
[DeviceType.FloodAlarm]: FloodAlarm,
[DeviceType.Gate]: Gate,
[DeviceType.Humidity]: Humidity,
[DeviceType.Info]: Info,
[DeviceType.Light]: Light,
[DeviceType.Lock]: Lock,
[DeviceType.Location]: Location,
[DeviceType.Media]: Media,
[DeviceType.Motion]: Motion,
[DeviceType.Rgb]: Rgb,
[DeviceType.Ct]: Ct,
[DeviceType.RgbSingle]: RgbSingle,
[DeviceType.RgbwSingle]: RgbwSingle,
[DeviceType.Hue]: Hue,
[DeviceType.Cie]: Cie,
[DeviceType.Slider]: Slider,
[DeviceType.Socket]: Socket,
[DeviceType.Temperature]: Temperature,
[DeviceType.Thermostat]: Thermostat,
[DeviceType.Volume]: Volume,
[DeviceType.VacuumCleaner]: VacuumCleaner,
[DeviceType.VolumeGroup]: VolumeGroup,
[DeviceType.Window]: Window,
[DeviceType.WindowTilt]: WindowTilt,
[DeviceType.WeatherCurrent]: WeatherCurrent,
[DeviceType.WeatherForecast]: WeatherForecast,
[DeviceType.Warning]: Warning,
[Types.airCondition]: AirCondition,
[Types.blind]: Blind,
[Types.blindButtons]: BlindButtons,
[Types.button]: Button,
[Types.buttonSensor]: ButtonSensor,
[Types.camera]: Camera,
[Types.image]: Image,
[Types.chart]: Chart,
[Types.dimmer]: Dimmer,
[Types.door]: Door,
[Types.fireAlarm]: FireAlarm,
[Types.floodAlarm]: FloodAlarm,
[Types.gate]: Gate,
[Types.humidity]: Humidity,
[Types.info]: Info,
[Types.light]: Light,
[Types.lock]: Lock,
[Types.location]: Location,
[Types.media]: Media,
[Types.motion]: Motion,
[Types.rgb]: Rgb,
[Types.ct]: Ct,
[Types.rgbSingle]: RgbSingle,
[Types.rgbwSingle]: RgbwSingle,
[Types.hue]: Hue,
[Types.cie]: Cie,
[Types.slider]: Slider,
[Types.socket]: Socket,
[Types.temperature]: Temperature,
[Types.thermostat]: Thermostat,
[Types.volume]: Volume,
[Types.vacuumCleaner]: VacuumCleaner,
[Types.volumeGroup]: VolumeGroup,
[Types.window]: Window,
[Types.windowTilt]: WindowTilt,
[Types.weatherCurrent]: WeatherCurrent,
[Types.weatherForecast]: WeatherForecast,
[Types.warning]: Warning,
};

async function deviceFabric(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter, options: DeviceOptions): Promise<GenericDevice | undefined> {
// @ts-ignore
const type = types[detectedDevice.type];
if (type) {
const deviceObject = new type(detectedDevice, adapter, options);
Expand Down
98 changes: 49 additions & 49 deletions src/lib/devices/GenericDevice.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
// @iobroker/device-types

import { DeviceState } from '../../iobroker.type-detector';
import { DetectorState, Types } from '@iobroker/type-detector';
import SubscribeManager from '../SubscribeManager';

// take here https://github.com/ioBroker/ioBroker.type-detector/blob/master/DEVICES.md#temperature-temperature
export enum DeviceType {
AirCondition = 'airCondition',
Blind = 'blind',
BlindButtons = 'blindButtons',
Button = 'button',
ButtonSensor = 'buttonSensor',
Camera = 'camera',
Url = 'url',
Chart = 'chart',
Image = 'image',
Dimmer = 'dimmer',
Door = 'door',
FireAlarm = 'fireAlarm',
FloodAlarm = 'floodAlarm',
Gate = 'gate',
Humidity = 'humidity',
Info = 'info',
Light = 'light',
Lock = 'lock',
Location = 'location',
Media = 'media',
Motion = 'motion',
Rgb = 'rgb',
Ct = 'ct',
RgbSingle = 'rgbSingle',
RgbwSingle = 'rgbwSingle',
Hue = 'hue',
Cie = 'cie',
Slider = 'slider',
Socket = 'socket',
Temperature = 'temperature',
Thermostat = 'thermostat',
Volume = 'volume',
VacuumCleaner = 'vacuumCleaner',
VolumeGroup = 'volumeGroup',
Window = 'window',
WindowTilt = 'windowTilt',
WeatherCurrent = 'weatherCurrent',
WeatherForecast = 'weatherForecast',
Warning = 'warning',
}
// export enum DeviceType {
// AirCondition = 'airCondition',
// Blind = 'blind',
// BlindButtons = 'blindButtons',
// Button = 'button',
// ButtonSensor = 'buttonSensor',
// Camera = 'camera',
// Url = 'url',
// Chart = 'chart',
// Image = 'image',
// Dimmer = 'dimmer',
// Door = 'door',
// FireAlarm = 'fireAlarm',
// FloodAlarm = 'floodAlarm',
// Gate = 'gate',
// Humidity = 'humidity',
// Info = 'info',
// Light = 'light',
// Lock = 'lock',
// Location = 'location',
// Media = 'media',
// Motion = 'motion',
// Rgb = 'rgb',
// Ct = 'ct',
// RgbSingle = 'rgbSingle',
// RgbwSingle = 'rgbwSingle',
// Hue = 'hue',
// Cie = 'cie',
// Slider = 'slider',
// Socket = 'socket',
// Temperature = 'temperature',
// Thermostat = 'thermostat',
// Volume = 'volume',
// VacuumCleaner = 'vacuumCleaner',
// VolumeGroup = 'volumeGroup',
// Window = 'window',
// WindowTilt = 'windowTilt',
// WeatherCurrent = 'weatherCurrent',
// WeatherForecast = 'weatherForecast',
// Warning = 'warning',
// }

export enum ValueType {
String = 'string',
Expand Down Expand Up @@ -197,7 +197,7 @@ export class DeviceStateObject<T> {

constructor(
protected adapter: ioBroker.Adapter,
public state: DeviceState,
public state: DetectorState,
public propertyType: PropertyType,
valueType: ValueType,
) {
Expand Down Expand Up @@ -378,14 +378,14 @@ export class DeviceStateObject<T> {
await SubscribeManager.unsubscribe(this.state.id, this.updateState);
}

public getIoBrokerState(): DeviceState {
public getIoBrokerState(): DetectorState {
return this.state;
}
}

export interface DetectedDevice {
type: DeviceType;
states: DeviceState[];
type: Types;
states: DetectorState[];
}

export interface DeviceStateDescription {
Expand Down Expand Up @@ -419,7 +419,7 @@ abstract class GenericDevice {
protected _possibleProperties: { [id: string]: StateDescription } = {};
protected adapter: ioBroker.Adapter;
protected _subscribeObjects: DeviceStateObject<any>[] = [];
protected _deviceType: DeviceType;
protected _deviceType: Types;
protected _detectedDevice: DetectedDevice;
protected handlers: ((event: {
property: PropertyType
Expand Down Expand Up @@ -537,7 +537,7 @@ abstract class GenericDevice {
callback(object);
}

getDeviceState(name: string): DeviceState | undefined {
getDeviceState(name: string): DetectorState | undefined {
return this._detectedDevice.states.find(state => state.name === name && state.id);
}

Expand Down Expand Up @@ -577,7 +577,7 @@ abstract class GenericDevice {
}
}

getDeviceType(): DeviceType | undefined {
getDeviceType(): Types | undefined {
return this._deviceType;
}

Expand Down
Loading

0 comments on commit dabc96c

Please sign in to comment.