diff --git a/src/deviceAuto.ts b/src/deviceAuto.ts index a51c764..b098f30 100644 --- a/src/deviceAuto.ts +++ b/src/deviceAuto.ts @@ -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}----`, + }]; } } @@ -473,4 +474,4 @@ export class DeviceConfigurations { } } -export { autoDeviceConfigs }; \ No newline at end of file +export { autoDeviceConfigs };