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