Skip to content

Commit

Permalink
Fix outlet device type as a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ilcato committed Oct 16, 2024
1 parent 076aa56 commit e1dbcfb
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions src/deviceAuto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,55 @@ export class DeviceConfigurations {
@DeviceType(/^com\.fibaro\.FGWOEF/)
private static variousSwitches(Service, Characteristic, device) {
const { deviceControlType } = device.properties || {};

const isLightingDevice =
deviceControlType === constants.CONTROL_TYPE_LIGHTING ||
deviceControlType === constants.CONTROL_TYPE_BEDSIDE_LAMP ||
deviceControlType === constants.CONTROL_TYPE_WALL_LAMP;

const isOtherDevice =
deviceControlType === constants.CONTROL_TYPE_OTHER_DEVICE ||
deviceControlType === constants.CONTROL_TYPE_OTHER_DEVICE_ALT;

const isLockDevice =
deviceControlType === constants.CONTROL_TYPE_VIDEO_INTERCOM ||
deviceControlType === constants.CONTROL_TYPE_VIDEO_GATE_OPEN;

const isValveDevice =
deviceControlType === constants.CONTROL_TYPE_SPRINKLER ||
deviceControlType === constants.CONTROL_TYPE_VALVE;

if (isLightingDevice) {
return [{
service: Service.Lightbulb,
characteristics: [Characteristic.On],
subtype: device.id + '----',
}];
} else if (isOtherDevice) {
return [{
service: Service.Switch,
characteristics: [Characteristic.On],
subtype: device.id + '----',
}];
} else if (isLockDevice) {
return [{
service: Service.LockMechanism,
characteristics: [Characteristic.LockCurrentState, Characteristic.LockTargetState],
subtype: `${device.id}--${constants.SUBTYPE_LOCK}`,
}];
} else if (isValveDevice) {
return [{
service: Service.Valve,
characteristics: [Characteristic.Active, Characteristic.InUse, Characteristic.ValveType],
subtype: device.id + '----',
}];
} else {
return [{
service: Service.Outlet,
characteristics: [Characteristic.On, Characteristic.OutletInUse],
subtype: device.id + '----',
}];
const controlType = typeof deviceControlType === 'string'
? parseInt(deviceControlType, 10)
: (deviceControlType || constants.CONTROL_TYPE_OTHER_DEVICE);

switch (controlType) {
// Lighting devices
case constants.CONTROL_TYPE_LIGHTING:
case constants.CONTROL_TYPE_BEDSIDE_LAMP:
case constants.CONTROL_TYPE_WALL_LAMP:
return [{
service: Service.Lightbulb,
characteristics: [Characteristic.On],
subtype: `${device.id}----`,
}];

// Other devices
case constants.CONTROL_TYPE_OTHER_DEVICE:
case constants.CONTROL_TYPE_OTHER_DEVICE_ALT:
return [{
service: Service.Switch,
characteristics: [Characteristic.On],
subtype: `${device.id}----`,
}];

// Lock devices
case constants.CONTROL_TYPE_VIDEO_INTERCOM:
case constants.CONTROL_TYPE_VIDEO_GATE_OPEN:
return [{
service: Service.LockMechanism,
characteristics: [Characteristic.LockCurrentState, Characteristic.LockTargetState],
subtype: `${device.id}--${constants.SUBTYPE_LOCK}`,
}];

// Valve devices
case constants.CONTROL_TYPE_SPRINKLER:
case constants.CONTROL_TYPE_VALVE:
return [{
service: Service.Valve,
characteristics: [Characteristic.Active, Characteristic.InUse, Characteristic.ValveType],
subtype: `${device.id}----`,
}];

// Default case
default:
return [{
service: Service.Outlet,
characteristics: [Characteristic.On, Characteristic.OutletInUse],
subtype: `${device.id}----`,
}];
}
}

Expand Down Expand Up @@ -473,4 +474,4 @@ export class DeviceConfigurations {
}
}

export { autoDeviceConfigs };
export { autoDeviceConfigs };

0 comments on commit e1dbcfb

Please sign in to comment.