mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
fix: improve device retrieval logic in addDeviceStatusToFirebase method
This commit is contained in:
@ -131,10 +131,19 @@ export class DeviceStatusFirebaseService {
|
||||
|
||||
async addDeviceStatusToFirebase(
|
||||
addDeviceStatusDto: AddDeviceStatusDto,
|
||||
deviceCache: Map<string, any>,
|
||||
deviceCache?: Map<string, any>,
|
||||
): Promise<AddDeviceStatusDto | null> {
|
||||
try {
|
||||
const device = deviceCache.get(addDeviceStatusDto.deviceTuyaUuid);
|
||||
let device;
|
||||
|
||||
if (deviceCache) {
|
||||
device = deviceCache.get(addDeviceStatusDto.deviceTuyaUuid);
|
||||
} else {
|
||||
device = await this.getDeviceByDeviceTuyaUuid(
|
||||
addDeviceStatusDto.deviceTuyaUuid,
|
||||
);
|
||||
}
|
||||
|
||||
if (!device?.uuid) {
|
||||
console.log(
|
||||
`⛔ Skipping Firebase update for unknown device: ${addDeviceStatusDto.deviceTuyaUuid}`,
|
||||
@ -142,7 +151,6 @@ export class DeviceStatusFirebaseService {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ensure product info and uuid are attached
|
||||
addDeviceStatusDto.deviceUuid = device.uuid;
|
||||
addDeviceStatusDto.productUuid = device.productDevice?.uuid;
|
||||
addDeviceStatusDto.productType = device.productDevice?.prodType;
|
||||
|
Reference in New Issue
Block a user