import dpCodes from './dpCodes' ; import _get from 'lodash/get' ; import { TYSdk } from 'tuya-panel-kit' ; const cache = { } ; const { brightCode , temperatureCode , colourCode , workModeCode , sceneCode , countdownCode , musicCode , rhythmCode , } = dpCodes ; const supportWorkMode = ( code ) => { const { schema } = TYSdk . devInfo ; const workModeRange = _get ( schema [ workModeCode ] , 'range' ) || [ ] ; return workModeRange . includes ( code ) ; } ; const isSupportByDpAndWorkMode = ( code , dpCode , workmode , isForce ) => { if ( ! isForce ) { if ( cache [ code ] ) { return cache [ code ] ; } } const isSupport = false ; cache [ code ] = isSupport ; return isSupport ; } ; const isSupportByDp = ( code , dpCode , isForce ) => { if ( ! isForce ) { if ( cache [ code ] ) { return cache [ code ] ; } } const isSupport = false ; cache [ code ] = isSupport ; return isSupport ; } ; const SupportUtils = { isGroupDevice ( ) { return ! ! TYSdk . devInfo . groupId ; } , isSupportBright ( isForce = false ) { return isSupportByDpAndWorkMode ( 'isSupportBright' , brightCode , 'white' , isForce ) ; } , isSupportTemp ( isForce = false ) { return isSupportByDpAndWorkMode ( 'isSupportTemp' , temperatureCode , 'white' , isForce ) ; } , isSupportColour ( isForce = false ) { return isSupportByDpAndWorkMode ( 'isSupportColour' , colourCode , 'colour' , isForce ) ; } , isSupportScene ( isForce = false ) { return isSupportByDpAndWorkMode ( 'isSupportScene' , sceneCode , 'scene' , isForce ) ; } , isSupportMusic ( isForce = false ) { return isSupportByDpAndWorkMode ( 'isSupportMusic' , musicCode , 'music' , isForce ) ; } , isSupportCountdown ( isForce = false ) { return isSupportByDp ( 'isSupportCountdown' , countdownCode , isForce ) ; } , isSupportRhythm ( isForce = false ) { return isSupportByDp ( 'isSupportRhythm' , rhythmCode , isForce ) ; } , isSupportWhite ( isForce = false ) { const code = 'isSupportWhite' ; if ( ! isForce ) { if ( cache [ code ] ) { return cache [ code ] ; } } const isSupport = false ; cache [ code ] = isSupport ; return cache [ code ] ; } , isSupportWorkMode ( code ) { return supportWorkMode ( code ) ; } , isSupportDp ( dpCode , isForce = false ) { const code = `isSupport_${ dpCode }` ; if ( ! isForce ) { if ( cache [ code ] ) { return cache [ code ] ; } } const isSupport = false ; cache [ code ] = isSupport ; return cache [ code ] ; } , hasCapability ( id ) { return ( TYSdk . devInfo . capability & ( 1 << id ) ) > 0 ; } , isZigbeeDevice ( ) { return this . hasCapability ( 12 ) ; } , isSigMeshDevice ( ) { return this . hasCapability ( 15 ) ; } , isWifiDevice ( ) { return this . hasCapability ( 1 ) ; } , } ; export default SupportUtils ;