diff --git a/src/energy-socket-api.ts b/src/energy-socket-api.ts index 622a0b8..badfb37 100644 --- a/src/energy-socket-api.ts +++ b/src/energy-socket-api.ts @@ -21,15 +21,15 @@ export class EnergySocketApi extends BaseApi { getData(): Promise { return super.getData(); } - startPolling( + protected startPolling( method: 'getData', apiMethod: () => Promise, ): Promise; - startPolling( + protected startPolling( method: 'getState', apiMethod: () => Promise, ): Promise; - startPolling(method: string, apiMethod: () => Promise): Promise { + protected startPolling(method: string, apiMethod: () => Promise): Promise { return super.startPolling(method, apiMethod); } diff --git a/src/kwh-meter-1-phase-api.ts b/src/kwh-meter-1-phase-api.ts index 58d614d..a3de7c0 100644 --- a/src/kwh-meter-1-phase-api.ts +++ b/src/kwh-meter-1-phase-api.ts @@ -10,7 +10,7 @@ export class KwhMeter1PhaseApi extends BaseApi { getData(): Promise { return super.getData(); } - startPolling( + protected startPolling( method: 'getData', apiMethod: () => Promise, ): Promise { diff --git a/src/kwh-meter-3-phase-api.ts b/src/kwh-meter-3-phase-api.ts index 2fe7874..8cf6f40 100644 --- a/src/kwh-meter-3-phase-api.ts +++ b/src/kwh-meter-3-phase-api.ts @@ -10,7 +10,7 @@ export class KwhMeter3PhaseApi extends BaseApi { getData(): Promise { return super.getData(); } - startPolling( + protected startPolling( method: 'getData', apiMethod: () => Promise, ): Promise { diff --git a/src/p1-meter-api.ts b/src/p1-meter-api.ts index a95cb4f..e61702f 100644 --- a/src/p1-meter-api.ts +++ b/src/p1-meter-api.ts @@ -2,9 +2,12 @@ import { BaseApi, BaseApiOptions, BasePolling, PollMethod } from '@/base-api'; import { BasicInformationResponse, P1MeterDataResponse, TelegramResponse } from '@/types'; import { ParsedTelegram, parseTelegram } from './utils/telegram'; -export interface P1MeterPolling - extends BasePolling { +export interface P1MeterPolling< + TTelegramResponse extends TelegramResponse, + TParsedTelegram extends ParsedTelegram, +> extends BasePolling { getTelegram: PollMethod; + getParsedTelegram: PollMethod; } export class P1MeterApi extends BaseApi { @@ -14,15 +17,19 @@ export class P1MeterApi extends BaseApi { getData(): Promise { return super.getData(); } - startPolling( + protected startPolling( method: 'getData', apiMethod: () => Promise, ): Promise; - startPolling( + protected startPolling( method: 'getTelegram', apiMethod: () => Promise, ): Promise; - startPolling(method: string, apiMethod: () => Promise): Promise { + protected startPolling( + method: 'getParsedTelegram', + apiMethod: () => Promise, + ): Promise; + protected startPolling(method: string, apiMethod: () => Promise): Promise { return super.startPolling(method, apiMethod); } @@ -45,12 +52,11 @@ export class P1MeterApi extends BaseApi { * To start polling, call the `start()` method on the returned object. * The polling can be stopped by calling the `stop()` method. * - * Supported methods: `getData`, `getTelegram` + * Supported methods: `getData`, `getTelegram` and `getParsedTelegram` */ - get polling(): P1MeterPolling { + get polling(): P1MeterPolling { const getTelegram = 'getTelegram'; - - // TODO: add getParsedTelegram + const getParsedTelegram = 'getParsedTelegram'; return { ...super.polling, @@ -59,6 +65,11 @@ export class P1MeterApi extends BaseApi { stop: () => super.stopPolling(getTelegram), on: super.on.bind(this), }, + [getParsedTelegram]: { + start: () => super.startPolling(getParsedTelegram, this.getParsedTelegram.bind(this)), + stop: () => super.stopPolling(getParsedTelegram), + on: super.on.bind(this), + }, }; } diff --git a/src/water-meter-api.ts b/src/water-meter-api.ts index 91a8b6c..95e615e 100644 --- a/src/water-meter-api.ts +++ b/src/water-meter-api.ts @@ -10,7 +10,7 @@ export class WaterMeterApi extends BaseApi { getData(): Promise { return super.getData(); } - startPolling( + protected startPolling( method: 'getData', apiMethod: () => Promise, ): Promise {