Reolink - Fix get ability (#1616)

* Reolink - Fix get ability

* getAbility current behavior kept

---------

Co-authored-by: Gianluca Ruocco <gianluca.ruocco@xarvio.com>
This commit is contained in:
apocaliss92
2024-10-21 00:20:26 +02:00
committed by GitHub
parent 51732d0dcd
commit 04be70019b
2 changed files with 39 additions and 6 deletions

View File

@@ -218,7 +218,13 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
async updateAbilities() {
const api = this.getClient();
const abilities = await api.getAbility();
const apiWithToken = this.getClientWithToken();
let abilities;
try {
abilities = await api.getAbility();
} catch(e) {
abilities = await apiWithToken.getAbility();
}
this.storageSettings.values.abilities = abilities;
this.console.log('getAbility', JSON.stringify(abilities));
}
@@ -797,6 +803,7 @@ class ReolinkProvider extends RtspProvider {
const rtspChannel = parseInt(settings.rtspChannel?.toString()) || 0;
if (!skipValidate) {
const api = new ReolinkCameraClient(httpAddress, username, password, rtspChannel, this.console);
const apiWithToken = new ReolinkCameraClient(httpAddress, username, password, rtspChannel, this.console, true);
try {
await api.jpegSnapshot();
}
@@ -810,7 +817,11 @@ class ReolinkProvider extends RtspProvider {
doorbell = deviceInfo.type === 'BELL';
name = deviceInfo.name ?? 'Reolink Camera';
ai = await api.getAiState();
abilities = await api.getAbility();
try {
abilities = await api.getAbility();
} catch(e) {
abilities = await apiWithToken.getAbility();
}
}
catch (e) {
this.console.error('Reolink camera does not support AI events', e);

View File

@@ -153,15 +153,37 @@ export class ReolinkCameraClient {
const params = url.searchParams;
params.set('cmd', 'GetAbility');
params.set('channel', this.channelId.toString());
const response = await this.requestWithLogin({
let response = await this.requestWithLogin({
url,
responseType: 'json',
});
const error = response.body?.[0]?.error;
let error = response.body?.[0]?.error;
if (error) {
this.console.error('error during call to getAbility', error);
throw new Error('error during call to getAbility');
this.console.error('error during call to getAbility GET, Trying with POST', error);
url.search = '';
const body = [
{
cmd: "GetAbility",
action: 0,
param: { User: { userName: this.username } }
}
];
response = await this.requestWithLogin({
url,
responseType: 'json',
method: 'POST',
}, this.createReadable(body));
error = response.body?.[0]?.error;
if (error) {
this.console.error('error during call to getAbility GET, Trying with POST', error);
throw new Error('error during call to getAbility');
}
}
return {
value: response.body?.[0]?.value || response.body?.value,
data: response.body,