Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kakopappa committed Dec 10, 2023
1 parent ddb4a09 commit d94fec2
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 51 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
"@typescript-eslint/semi": ["warn"],
"@typescript-eslint/member-delimiter-style": ["warn"],
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
7 changes: 7 additions & 0 deletions src/accessory/accessory-controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { CharacteristicValue, PlatformAccessory } from 'homebridge';
import { SinricProPlatform } from '../platform';

Expand Down
7 changes: 7 additions & 0 deletions src/accessory/accessory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

export interface SinricProAccessory {
sinricProDeviceId: string;
updateState(action: string, value: any): void;
Expand Down
8 changes: 7 additions & 1 deletion src/accessory/blind.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

/* eslint-disable max-len */
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
Expand Down Expand Up @@ -52,7 +59,6 @@ export class SinricProBlind extends AccessoryController implements SinricProAcce
* @param action - setRangeValue
* @param value - {"rangeValue":100}
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public updateState(action: string, value: any): void {
this.platform.log.debug('[updateState()]:', this.accessory.displayName, 'action=', action, 'value=', value);

Expand Down
9 changes: 8 additions & 1 deletion src/accessory/contact-sensor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants, ModelConstants } from '../constants';

/**
* Sinric Pro - Contact Sensor
Expand Down
8 changes: 7 additions & 1 deletion src/accessory/dimmable-switch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down Expand Up @@ -57,7 +64,6 @@ export class SinricProDimmableSwitch extends AccessoryController implements Sinr

}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public updateState(action: string, value: any): void {
this.platform.log.debug('[updateState()]:', this.accessory.displayName, 'action=', action, 'value=', value);

Expand Down
7 changes: 7 additions & 0 deletions src/accessory/doorbell.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down
10 changes: 8 additions & 2 deletions src/accessory/fan.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants } from '../constants';
import { ActionConstants, ModelConstants } from '../constants';

/**
* Sinric Pro - Fan
Expand Down
10 changes: 8 additions & 2 deletions src/accessory/garage-door.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants } from '../constants';
import { ModelConstants, ActionConstants } from '../constants';

/**
* Sinric Pro - Garage Door
Expand Down
7 changes: 7 additions & 0 deletions src/accessory/light.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down
10 changes: 8 additions & 2 deletions src/accessory/lock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants } from '../constants';
import { ModelConstants, ActionConstants } from '../constants';

/**
* Sinric Pro - Lock
Expand Down
7 changes: 7 additions & 0 deletions src/accessory/motion-sensor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down
7 changes: 7 additions & 0 deletions src/accessory/switch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down
10 changes: 8 additions & 2 deletions src/accessory/temperature-sensor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants } from '../constants';
import { ModelConstants, ActionConstants } from '../constants';

/**
* Sinric Pro - Temperature Sensor
Expand Down
7 changes: 7 additions & 0 deletions src/accessory/thermostat.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

/* eslint-disable max-len */
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
Expand Down
7 changes: 7 additions & 0 deletions src/accessory/tv.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
Expand Down
10 changes: 8 additions & 2 deletions src/accessory/window-ac-unit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

/* eslint-disable max-len */
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { SinricProPlatform } from '../platform';
import { SinricProAccessory } from './accessory';
import { AccessoryController } from './accessory-controller';
import { ModelConstants } from '../constants';
import { ActionConstants } from '../constants';
import { ModelConstants, ActionConstants } from '../constants';

/**
* Sinric Pro - WindowACUnit
Expand Down
10 changes: 6 additions & 4 deletions src/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/
import { Logger } from 'homebridge';
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import https from 'https';
Expand Down Expand Up @@ -43,14 +49,11 @@ export class SinricProApiClient {
this.log.debug(`${initData[0].data.devices.length} device(s) found!`);

for (const device of initData[0].data.devices) {
//console.log('device:', device);

const sinricproDevice: SinricProDevice = {
id: device.id,
name: device.name,
deviceType: { code: device.product.code },
powerState: device.powerState || null,
room: device.room,
rangeValue: device.rangeValue,
garageDoorState: device.garageDoorState,
brightness: device.brightness,
Expand Down Expand Up @@ -140,7 +143,6 @@ export class SinricProApiClient {
};
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async execAction(deviceId: string, data: any): Promise<boolean> {
const deviceActionUrl = util.format('/devices/%s/action', deviceId);

Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/

export const SINRICPRO_HOMEBRIDGE_CLIENT_ID = 'api_interaction';
export const SINRICPRO_API_ENDPOINT_BASE_URL = 'https://api.sinric.pro/api/v1';
export const SINRICPRO_SSE_ENDPOINT_BASE_URL = 'https://sse.sinric.pro/sse/stream?accessToken=%s';
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/
import { API } from 'homebridge';

import { PLATFORM_NAME } from './settings';
Expand Down
Empty file removed src/model/device-types.ts
Empty file.
4 changes: 0 additions & 4 deletions src/model/room.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/model/sinricpro-device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/
export interface SinricProDeviceType {
code: string;
}
Expand All @@ -6,7 +12,6 @@ export interface SinricProDevice {
id: number;
name: string;
deviceType: SinricProDeviceType;
room: Room;
powerState: string | undefined; // On or Off
rangeValue: number | undefined;
garageDoorState: number | undefined;
Expand Down
44 changes: 25 additions & 19 deletions src/model/sse.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/
export interface SSEMessage {
event: string;
device: Device;
event: string;
device: Device;
message: Message;
}

export interface Device {
name: string;
powerState: string;
isOnline: boolean;
id: string;
name: string;
powerState: string;
isOnline: boolean;
id: string;
}

export interface Message {
name: string;
channel: string;
userId: string;
deviceId: string;
payload: Payload;
name: string;
channel: string;
userId: string;
deviceId: string;
payload: Payload;
}

export interface Payload {
action: string;
clientId: string;
createdAt: number;
deviceId: string;
message: string;
action: string;
clientId: string;
createdAt: number;
deviceId: string;
message: string;
replyToken: string;
success: boolean;
type: string;
value: any;
success: boolean;
type: string;
value: any;
}
7 changes: 6 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2019-2023 Sinric. All rights reserved.
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
*
* This file is part of the Sinric Pro - Homebridge Plugin (https://github.com/sinricpro/homebridge-sinricpro)
*/
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';

import { PLATFORM_NAME, PLUGIN_NAME } from './settings';
Expand Down Expand Up @@ -84,7 +90,6 @@ export class SinricProPlatform implements DynamicPlatformPlugin {
this.log.info('[didFinishLaunching()]: init SSE Client..');
this.sinricProSseClient = new SinricProSseClient(this.log, this.sinricProApiClient.authToken);
// listen to device state changes
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.sinricProSseClient.onDeviceStateChange = (deviceId: string, action: string, value: any) => {
this.sinricproDevices.filter(spd => spd.sinricProDeviceId === deviceId).map((device) => {
this.log.info('[onDeviceStateChange()]: Update device id: %s with %s', device.sinricProDeviceId, value);
Expand Down
Loading

0 comments on commit d94fec2

Please sign in to comment.