Skip to content

Commit

Permalink
Merge pull request #13 from baranwang/feat/1.3
Browse files Browse the repository at this point in the history
feat: 新增支持过滤设备配置
  • Loading branch information
baranwang authored Feb 13, 2024
2 parents 2736c13 + 2216719 commit 9645abd
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 59 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
"eslint.enable": true,
"cSpell.words": [
"Haier"
],
"json.schemas": [
{
"fileMatch": [
"lerna.json"
],
"url": "../node_modules/lerna/schemas/lerna-schema.json"
}
]
}
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"$schema": "./node_modules/lerna/schemas/lerna-schema.json",
"version": "1.2.3",
"packages": ["packages/*"],
"command": {
Expand Down
125 changes: 123 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "root",
"name": "hb-haier",
"private": true,
"scripts": {
"build": "lerna run build"
"build": "lerna run build",
"dev": "lerna watch -- lerna run build --scope=\\$LERNA_PACKAGE_NAME"
},
"workspaces": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "海尔智家 Homebridge 插件",
"scripts": {
"postinstall": "node ./scripts/postinstall.js",
"build": "rimraf ./dist && tsc",
"watch": "nodemon"
"dev": "nodemon",
"build": "rimraf ./dist && tsc"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/accessories/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class BaseAccessory {
this.onDevDigitalModelUpdate();
return devDigitalModel;
} catch (error) {
this.platform.log.error('获取设备数据失败', error);
return this.accessory.context.devDigitalModel;
} finally {
this.devDigitalModelPromise = undefined;
Expand Down
29 changes: 21 additions & 8 deletions packages/plugin/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export class HaierHomebridgePlatform implements DynamicPlatformPlugin {

private discoveryInterval?: NodeJS.Timeout;

constructor(public readonly log: Logger, public readonly config: PlatformConfig, public readonly api: API) {
constructor(
public readonly log: Logger,
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.debug('平台初始化完成', this.config.name);

this.api.on('didFinishLaunching', () => {
Expand All @@ -40,15 +44,18 @@ export class HaierHomebridgePlatform implements DynamicPlatformPlugin {
}

discoverDevices() {
const { familyId } = this.config;

const { familyId, disabledDevices = [] } = this.config;
if (!familyId) {
this.log.error('请在 config.json 中配置 familyId');
return;
}

this.haierApi.getDevicesByFamilyId(familyId).then(devices => {
devices.forEach(device => this.handleDevice(device));
devices.forEach(device => {
if (!disabledDevices.includes(device.baseInfo.deviceId)) {
this.handleDevice(device);
}
});
});
}

Expand Down Expand Up @@ -77,8 +84,9 @@ export class HaierHomebridgePlatform implements DynamicPlatformPlugin {
this.api.updatePlatformAccessories([existingAccessory]);
new AccessoryClass(this, existingAccessory);
} else {
this.log.info('Adding new accessory:', device.baseInfo.deviceName);
const accessory = new this.api.platformAccessory<HaierPlatformAccessoryContext>(device.baseInfo.deviceName, uuid);
const displayName = this.getDeviceName(device);
this.log.info('Adding new accessory:', displayName);
const accessory = new this.api.platformAccessory<HaierPlatformAccessoryContext>(displayName, uuid);
accessory.context = {
deviceInfo: device,
};
Expand All @@ -88,12 +96,13 @@ export class HaierHomebridgePlatform implements DynamicPlatformPlugin {
}

private isDeviceIneligible(device: DeviceInfo): boolean {
const displayName = this.getDeviceName(device);
if (!device.baseInfo.permission.auth.control) {
this.log.warn('设备', device.baseInfo.deviceName, '没有控制权限');
this.log.warn('设备', displayName, '没有控制权限');
return true;
}
if (!device.extendedInfo.bindType) {
this.log.warn('设备', device.baseInfo.deviceName, '不支持云端控制');
this.log.warn('设备', displayName, '不支持云端控制');
return true;
}
return false;
Expand All @@ -108,4 +117,8 @@ export class HaierHomebridgePlatform implements DynamicPlatformPlugin {
return undefined;
}
}

private getDeviceName(device: DeviceInfo) {
return `${device.extendedInfo.room} - ${device.baseInfo.deviceName}`;
}
}
17 changes: 2 additions & 15 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@
"types": "./dist/types/index.d.ts",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/es/index.js",
"require": "./dist/lib/index.js",
"types": "./dist/types/index.d.ts"
},
"./dist/*": {
"import": "./dist/es/*",
"require": "./dist/lib/*",
"types": "./dist/types/*"
}
},
"scripts": {
"build": "modern build",
"build:watch": "modern build -w"
"dev": "modern build -w",
"build": "modern build"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class HaierApi {
const body = config.data ? JSON.stringify(config.data) : '';
const signStr = `${url.pathname}${url.search}${body}${APP_ID}${APP_KEY}${timestamp}`;
config.headers.sign = sha256(signStr);
this.logger.debug('request:', url.toString(), JSON.stringify(config.data));
this.logger.debug('request:', url.toString(), config.data ? JSON.stringify(config.data) : undefined);
return config;
});
this.axios.interceptors.response.use(
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "@hb-haier/ui-renderer",
"version": "1.2.3",
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview"
"dev": "rsbuild dev",
"build": "rsbuild build"
},
"dependencies": {
"@hb-haier/shared": "1.2.3",
"ahooks": "^3.7.10",
"rc-field-form": "^1.41.0",
"rc-select": "^14.11.0",
"react": "^18.2.0",
"react-bootstrap": "^2.10.1",
"react-dom": "^18.2.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/ui-renderer/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
plugins: [pluginReact()],
html: {
inject: 'body',
template: './static/index.html',
title: '',
},
output: {
assetPrefix: './',
legalComments: 'none',
}
});
Loading

0 comments on commit 9645abd

Please sign in to comment.