commonMain.com.huawei.hilink.c2c.integration.helper.model.DeviceDiscoveryTranslation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helper-jvm Show documentation
Show all versions of helper-jvm Show documentation
The helper library streamlines the HiLink C2C integration and exposes a simple API.
package com.huawei.hilink.c2c.integration.helper.model
import com.huawei.hilink.c2c.integration.helper.LengthLimits
import com.huawei.hilink.c2c.integration.helper.ParamLenViolationException
import com.huawei.hilink.c2c.integration.helper.api.DeviceConversion
import com.huawei.hilink.c2c.integration.helper.api.DeviceInformation
import com.huawei.hilink.c2c.integration.helper.api.UserInfo
import com.huawei.hilink.c2c.integration.helper.callbackAdapters.discoverSuspending
import com.huawei.hilink.c2c.integration.helper.dto.common.DeviceServiceDeclaration
import com.huawei.hilink.c2c.integration.helper.dto.common.HiLinkDeviceDeclaration
import com.huawei.hilink.c2c.integration.helper.dto.common.HiLinkDeviceInfo
import com.huawei.hilink.c2c.integration.helper.dto.common.HiLinkExtendData
import com.huawei.hilink.c2c.integration.helper.prepareExceptionIfViolatedBy
internal fun DeviceInformation.toHiLinkDeviceDiscovery(): HiLinkDeviceDeclaration {
return HiLinkDeviceDeclaration(
thirdPartyDevId = deviceId,
devName = deviceName,
extendData = roomName?.let { HiLinkExtendData(it) },
devInfo = HiLinkDeviceInfo(
model = model,
devType = devType,
manu = manu,
protType = 1,
prodId = prodId
),
services = serviceIdsMapping.map {
DeviceServiceDeclaration(
st = it.serviceIdInHiLink,
sid = it.serviceIdInPartnerSystem
)
}
)
}
internal suspend fun DeviceConversion.hiLinkDiscoveryBlockOf(userInfo: UserInfo, deviceId: String) =
discoverSuspending(userInfo, deviceId).toHiLinkDeviceDiscovery()
internal fun DeviceInformation.firstParamViolationOrNull(siteName: String): ParamLenViolationException? {
LengthLimits.DEVICE_ID.prepareExceptionIfViolatedBy(deviceId, siteName)
?.let { exception -> return exception }
LengthLimits.DEVICE_NAME.prepareExceptionIfViolatedBy(deviceName, siteName)
?.let { exception -> return exception }
LengthLimits.PROD_ID.prepareExceptionIfViolatedBy(prodId, siteName)
?.let { exception -> return exception }
LengthLimits.DEVICE_MODEL.prepareExceptionIfViolatedBy(model, siteName)
?.let { exception -> return exception }
LengthLimits.DEVICE_TYPE.prepareExceptionIfViolatedBy(devType, siteName)
?.let { exception -> return exception }
LengthLimits.MANU.prepareExceptionIfViolatedBy(manu, siteName)
?.let { exception -> return exception }
serviceIdsMapping.forEach { mapping ->
LengthLimits.HILINK_SERVICE_ID.prepareExceptionIfViolatedBy(
mapping.serviceIdInHiLink,
siteName
)?.let { exception -> return exception }
LengthLimits.PARTNER_SERVICE_ID.prepareExceptionIfViolatedBy(
mapping.serviceIdInPartnerSystem,
siteName
)?.let { exception -> return exception }
}
return null
}