Skip to content

Commit

Permalink
chore: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandenaardweg committed Dec 16, 2022
1 parent e83c324 commit 29f8162
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Base, HomeWizardEnergyApiOptions } from './base';
import { Base, BaseApiOptions } from './base';
import { EnergySocketApi } from './energy-socket-api';
import { P1MeterApi } from './p1-meter-api';
import { WaterMeterApi } from './water-meter-api';
Expand All @@ -13,11 +13,16 @@ export class HomeWizardEnergyApi extends Base {
public p1Meter: P1MeterApi;
public waterMeter: WaterMeterApi;

constructor(baseUrl: string, options?: HomeWizardEnergyApiOptions) {
constructor(baseUrl: string, options?: BaseApiOptions) {
super(baseUrl, options);

// TODO: Add support for multiple energy sockets
this.energySocket = new EnergySocketApi(baseUrl, options);

// TODO: add support for multiple P1 meters
this.p1Meter = new P1MeterApi(baseUrl, options);

// TODO: add support for multiple water meters
this.waterMeter = new WaterMeterApi(baseUrl, options);
}
}
10 changes: 5 additions & 5 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class HomeWizardEnergyApiResponseError extends HomeWizardEnergyApiError {
}
}

export interface HomeWizardEnergyApiOptions {
export interface BaseApiOptions {
/** The API version to be used. Defaults to `v1` */
apiVersion?: 'v1' | undefined;
/** Request options to be used in the HTTP request to the API. */
Expand All @@ -33,11 +33,11 @@ export interface HomeWizardEnergyApiOptions {

export class Base {
protected readonly baseUrl: string;
protected readonly apiVersion: HomeWizardEnergyApiOptions['apiVersion'];
protected requestOptions: HomeWizardEnergyApiOptions['requestOptions'];
protected logger: HomeWizardEnergyApiOptions['logger'];
protected readonly apiVersion: BaseApiOptions['apiVersion'];
protected requestOptions: BaseApiOptions['requestOptions'];
protected logger: BaseApiOptions['logger'];

constructor(baseUrl: string, options?: HomeWizardEnergyApiOptions) {
constructor(baseUrl: string, options?: BaseApiOptions) {
this.baseUrl = baseUrl;
this.apiVersion = options?.apiVersion || 'v1';
this.requestOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/energy-socket-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Base, HomeWizardEnergyApiError, HomeWizardEnergyApiOptions } from './base';
import { Base, HomeWizardEnergyApiError, BaseApiOptions } from './base';
import {
BasicInformationResponse,
EnergySocketDataResponse,
Expand All @@ -13,7 +13,7 @@ export class EnergySocketApi extends Base {
public getBasicInformation: () => Promise<BasicInformationResponse>;
public getData: <T extends EnergySocketDataResponse>() => Promise<T>;

constructor(baseUrl: string, options?: HomeWizardEnergyApiOptions) {
constructor(baseUrl: string, options?: BaseApiOptions) {
super(baseUrl, options);

this.getBasicInformation = super.getBasicInformation;
Expand Down
4 changes: 2 additions & 2 deletions src/p1-meter-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Base, HomeWizardEnergyApiOptions } from './base';
import { Base, BaseApiOptions } from './base';
import { BasicInformationResponse, P1MeterDataResponse } from './types';

export class P1MeterApi extends Base {
public getBasicInformation: () => Promise<BasicInformationResponse>;
public getData: <T extends P1MeterDataResponse>() => Promise<T>;

constructor(baseUrl: string, options?: HomeWizardEnergyApiOptions) {
constructor(baseUrl: string, options?: BaseApiOptions) {
super(baseUrl, options);

this.getBasicInformation = super.getBasicInformation;
Expand Down
4 changes: 2 additions & 2 deletions src/water-meter-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Base, HomeWizardEnergyApiOptions } from './base';
import { Base, BaseApiOptions } from './base';
import { BasicInformationResponse, WaterMeterDataResponse } from './types';

export class WaterMeterApi extends Base {
public getBasicInformation: () => Promise<BasicInformationResponse>;
public getData: <T extends WaterMeterDataResponse>() => Promise<T>;

constructor(baseUrl: string, options?: HomeWizardEnergyApiOptions) {
constructor(baseUrl: string, options?: BaseApiOptions) {
super(baseUrl, options);

this.getBasicInformation = super.getBasicInformation;
Expand Down

0 comments on commit 29f8162

Please sign in to comment.