Skip to content

Commit

Permalink
reolink: add nvr flag (#1620)
Browse files Browse the repository at this point in the history
* Reolink - Fix name/model fetching if homehub

* Checks removed

* style change removed

* Change logic for earlier returns

---------

Co-authored-by: Gianluca Ruocco <gianluca.ruocco@xarvio.com>
  • Loading branch information
apocaliss92 and Gianluca Ruocco authored Oct 21, 2024
1 parent 80372b3 commit 446e8ed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
7 changes: 4 additions & 3 deletions plugins/reolink/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
}
const api = this.getClient();
const deviceInfo = await api.getDeviceInfo();
this.console.log('deviceInfo', JSON.stringify(deviceInfo));
this.storageSettings.values.deviceInfo = deviceInfo;
await this.updateAbilities();
await this.updateDevice();
Expand Down Expand Up @@ -319,7 +320,7 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
if (this.hasSiren())
interfaces.push(ScryptedInterface.DeviceProvider);

await this.provider.updateDevice(this.nativeId, name, interfaces, type);
await this.provider.updateDevice(this.nativeId, this.name ?? name, interfaces, type);
}

async reboot() {
Expand Down Expand Up @@ -625,7 +626,7 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
// 1: support main/extern/sub stream
// 2: support main/sub stream

const live = this.storageSettings.values.abilities?.value?.Ability?.abilityChn?.[0].live?.ver;
const live = this.storageSettings.values.abilities?.value?.Ability?.abilityChn?.[this.getRtspChannel()].live?.ver;
const [rtmpMain, rtmpExt, rtmpSub, rtspMain, rtspSub] = streams;
streams.splice(0, streams.length);

Expand All @@ -634,7 +635,7 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
// 1: main stream enc type is H265

// anecdotally, encoders of type h265 do not have a working RTMP main stream.
const mainEncType = this.storageSettings.values.abilities?.value?.Ability?.abilityChn?.[0].mainEncType?.ver;
const mainEncType = this.storageSettings.values.abilities?.value?.Ability?.abilityChn?.[this.getRtspChannel()].mainEncType?.ver;

if (live === 2) {
if (mainEncType === 1) {
Expand Down
41 changes: 40 additions & 1 deletion plugins/reolink/src/reolink-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,46 @@ export class ReolinkCameraClient {
this.console.error('error during call to getDeviceInfo', error);
throw new Error('error during call to getDeviceInfo');
}
return response.body?.[0]?.value?.DevInfo;

const deviceInfo: DevInfo = await response.body?.[0]?.value?.DevInfo;

// Will need to check if it's valid for NVR and NVR_WIFI
if (['HOMEHUB'].includes(deviceInfo.exactType)) {
return deviceInfo;
}

// If the device is listed as homehub, fetch the channel specific information
url.search = '';
const body = [
{ cmd: "GetChnTypeInfo", action: 0, param: { channel: this.channelId } },
{ cmd: "GetChannelstatus", action: 0, param: {} },
]

const additionalInfoResponse = await this.requestWithLogin({
url,
method: 'POST',
responseType: 'json'
}, this.createReadable(body));

const chnTypeInfo = additionalInfoResponse?.body?.find(elem => elem.cmd === 'GetChnTypeInfo');
const chnStatus = additionalInfoResponse?.body?.find(elem => elem.cmd === 'GetChannelstatus');

if (chnTypeInfo?.value) {
deviceInfo.firmVer = chnTypeInfo.value.firmVer;
deviceInfo.model = chnTypeInfo.value.typeInfo;
deviceInfo.pakSuffix = chnTypeInfo.value.pakSuffix;
}

if (chnStatus?.value) {
const specificChannelStatus = chnStatus.value?.status?.find(elem => elem.channel === this.channelId);

if (specificChannelStatus) {
deviceInfo.name = specificChannelStatus.name;
}
}


return deviceInfo;
}

async getPtzPresets(): Promise<PtzPreset[]> {
Expand Down

0 comments on commit 446e8ed

Please sign in to comment.