From d94fec276f8ae8bbc13bfa7fef1b3780e61cbd52 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 10 Dec 2023 11:13:08 +0700 Subject: [PATCH] feat: cleanup --- .eslintrc | 1 + src/accessory/accessory-controller.ts | 7 +++++ src/accessory/accessory.ts | 7 +++++ src/accessory/blind.ts | 8 ++++- src/accessory/contact-sensor.ts | 9 +++++- src/accessory/dimmable-switch.ts | 8 ++++- src/accessory/doorbell.ts | 7 +++++ src/accessory/fan.ts | 10 ++++-- src/accessory/garage-door.ts | 10 ++++-- src/accessory/light.ts | 7 +++++ src/accessory/lock.ts | 10 ++++-- src/accessory/motion-sensor.ts | 7 +++++ src/accessory/switch.ts | 7 +++++ src/accessory/temperature-sensor.ts | 10 ++++-- src/accessory/thermostat.ts | 7 +++++ src/accessory/tv.ts | 7 +++++ src/accessory/window-ac-unit.ts | 10 ++++-- src/api-client.ts | 10 +++--- src/constants.ts | 7 +++++ src/index.ts | 6 ++++ src/model/device-types.ts | 0 src/model/room.ts | 4 --- src/model/sinricpro-device.ts | 7 ++++- src/model/sse.ts | 44 +++++++++++++++------------ src/platform.ts | 7 ++++- src/settings.ts | 6 ++++ src/sse-client.ts | 8 ++++- src/utils/guid.ts | 22 +++++++++----- 28 files changed, 202 insertions(+), 51 deletions(-) delete mode 100644 src/model/device-types.ts delete mode 100644 src/model/room.ts diff --git a/.eslintrc b/.eslintrc index ddcd82a..d9f3095 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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" } } diff --git a/src/accessory/accessory-controller.ts b/src/accessory/accessory-controller.ts index 3703095..448435e 100644 --- a/src/accessory/accessory-controller.ts +++ b/src/accessory/accessory-controller.ts @@ -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'; diff --git a/src/accessory/accessory.ts b/src/accessory/accessory.ts index 5212ae3..9d107f6 100644 --- a/src/accessory/accessory.ts +++ b/src/accessory/accessory.ts @@ -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; diff --git a/src/accessory/blind.ts b/src/accessory/blind.ts index 299d696..5c726c0 100644 --- a/src/accessory/blind.ts +++ b/src/accessory/blind.ts @@ -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'; @@ -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); diff --git a/src/accessory/contact-sensor.ts b/src/accessory/contact-sensor.ts index 6099ed5..616d588 100644 --- a/src/accessory/contact-sensor.ts +++ b/src/accessory/contact-sensor.ts @@ -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 diff --git a/src/accessory/dimmable-switch.ts b/src/accessory/dimmable-switch.ts index 0bdfbc2..fc61f54 100644 --- a/src/accessory/dimmable-switch.ts +++ b/src/accessory/dimmable-switch.ts @@ -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'; @@ -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); diff --git a/src/accessory/doorbell.ts b/src/accessory/doorbell.ts index b2a3e83..62f41ab 100644 --- a/src/accessory/doorbell.ts +++ b/src/accessory/doorbell.ts @@ -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'; diff --git a/src/accessory/fan.ts b/src/accessory/fan.ts index 36414e0..7db4372 100644 --- a/src/accessory/fan.ts +++ b/src/accessory/fan.ts @@ -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 diff --git a/src/accessory/garage-door.ts b/src/accessory/garage-door.ts index 32f4b06..402ac35 100644 --- a/src/accessory/garage-door.ts +++ b/src/accessory/garage-door.ts @@ -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 diff --git a/src/accessory/light.ts b/src/accessory/light.ts index a42969f..cecfe93 100644 --- a/src/accessory/light.ts +++ b/src/accessory/light.ts @@ -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'; diff --git a/src/accessory/lock.ts b/src/accessory/lock.ts index c770348..6d7caf1 100644 --- a/src/accessory/lock.ts +++ b/src/accessory/lock.ts @@ -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 diff --git a/src/accessory/motion-sensor.ts b/src/accessory/motion-sensor.ts index ac93aa8..b0db507 100644 --- a/src/accessory/motion-sensor.ts +++ b/src/accessory/motion-sensor.ts @@ -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'; diff --git a/src/accessory/switch.ts b/src/accessory/switch.ts index fe39032..d8ed183 100644 --- a/src/accessory/switch.ts +++ b/src/accessory/switch.ts @@ -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'; diff --git a/src/accessory/temperature-sensor.ts b/src/accessory/temperature-sensor.ts index 6647779..0a2c9e3 100644 --- a/src/accessory/temperature-sensor.ts +++ b/src/accessory/temperature-sensor.ts @@ -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 diff --git a/src/accessory/thermostat.ts b/src/accessory/thermostat.ts index 18c8fc6..6bd8e81 100644 --- a/src/accessory/thermostat.ts +++ b/src/accessory/thermostat.ts @@ -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'; diff --git a/src/accessory/tv.ts b/src/accessory/tv.ts index 9266a26..98dac03 100644 --- a/src/accessory/tv.ts +++ b/src/accessory/tv.ts @@ -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'; diff --git a/src/accessory/window-ac-unit.ts b/src/accessory/window-ac-unit.ts index 5a8c42f..62630be 100644 --- a/src/accessory/window-ac-unit.ts +++ b/src/accessory/window-ac-unit.ts @@ -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 diff --git a/src/api-client.ts b/src/api-client.ts index 2133f47..c80e423 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -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'; @@ -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, @@ -140,7 +143,6 @@ export class SinricProApiClient { }; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private async execAction(deviceId: string, data: any): Promise { const deviceActionUrl = util.format('/devices/%s/action', deviceId); diff --git a/src/constants.ts b/src/constants.ts index 2f98cd0..b325b60 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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'; diff --git a/src/index.ts b/src/index.ts index 2a81d30..b6ffdc0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/model/device-types.ts b/src/model/device-types.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/model/room.ts b/src/model/room.ts deleted file mode 100644 index af379dd..0000000 --- a/src/model/room.ts +++ /dev/null @@ -1,4 +0,0 @@ -type Room = { - id: number; - name: string; -}; diff --git a/src/model/sinricpro-device.ts b/src/model/sinricpro-device.ts index 2dde110..3431dad 100644 --- a/src/model/sinricpro-device.ts +++ b/src/model/sinricpro-device.ts @@ -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; } @@ -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; diff --git a/src/model/sse.ts b/src/model/sse.ts index 714c361..5b78987 100644 --- a/src/model/sse.ts +++ b/src/model/sse.ts @@ -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; } \ No newline at end of file diff --git a/src/platform.ts b/src/platform.ts index 2b95478..c31c74b 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -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'; @@ -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); diff --git a/src/settings.ts b/src/settings.ts index 31e37d7..c7d1cea 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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) + */ /** * This is the name of the platform that users will use to register the plugin in the Homebridge config.json */ diff --git a/src/sse-client.ts b/src/sse-client.ts index 6a3fce3..33897e1 100644 --- a/src/sse-client.ts +++ b/src/sse-client.ts @@ -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 EventSource from 'eventsource'; import * as util from 'util'; @@ -8,7 +15,6 @@ import { SINRICPRO_SSE_ENDPOINT_BASE_URL } from './constants'; export class SinricProSseClient { private eventSource!: EventSource; - // eslint-disable-next-line @typescript-eslint/no-explicit-any public onDeviceStateChange?: (deviceId: string, action: string, value: any) => void; constructor( diff --git a/src/utils/guid.ts b/src/utils/guid.ts index 19db3a2..8df838b 100644 --- a/src/utils/guid.ts +++ b/src/utils/guid.ts @@ -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) + */ export class Guid { - static newGuid() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = Math.random() * 16 | 0, - v = c == 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); - } - } \ No newline at end of file + static newGuid() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = Math.random() * 16 | 0, + v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + } +} \ No newline at end of file