Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reworked the integration loading mechanism
Integration files are now only imported if they are configured. Publishers are now also integrations. Communication for entity updates is now done loosely coupled via the NodeJS event bus.
- Loading branch information
Showing
46 changed files
with
190 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import { Module, Type } from '@nestjs/common'; | ||
import { BluetoothLowEnergyModule } from './bluetooth-low-energy/bluetooth-low-energy.module'; | ||
import { Module } from '@nestjs/common'; | ||
import c from 'config'; | ||
import { resolveClasses } from './util/resolver'; | ||
import { OmronD6tModule } from './omron-d6t/omron-d6t.module'; | ||
import { IntegrationsModule } from './integrations/integrations.module'; | ||
import { EntitiesModule } from './entities/entities.module'; | ||
import { ConfigModule } from './config/config.module'; | ||
import { ClusterModule } from './cluster/cluster.module'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
import _ from 'lodash'; | ||
import { NestEmitterModule } from 'nest-emitter'; | ||
import { EventEmitter } from 'events'; | ||
|
||
export const CONFIGURED_INTEGRATIONS = c.get<string[]>('global.integrations'); | ||
export const INTEGRATION_MAPPING: { [key: string]: Type<any> } = { | ||
bluetoothLowEnergy: BluetoothLowEnergyModule, | ||
omronD6t: OmronD6tModule | ||
}; | ||
export const CONFIGURED_INTEGRATIONS = c | ||
.get<string[]>('global.integrations') | ||
.map(id => _.kebabCase(id)); | ||
|
||
@Module({ | ||
imports: [ | ||
...resolveClasses(CONFIGURED_INTEGRATIONS, INTEGRATION_MAPPING), | ||
OmronD6tModule | ||
EntitiesModule, | ||
ConfigModule, | ||
ClusterModule, | ||
ScheduleModule.forRoot(), | ||
NestEmitterModule.forRoot(new EventEmitter()), | ||
IntegrationsModule.register(CONFIGURED_INTEGRATIONS) | ||
] | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Entity } from './entity.entity'; | ||
import { EntityOptions } from './entity-options.entity'; | ||
import { StrictEventEmitter } from 'nest-emitter'; | ||
import EventEmitter = NodeJS.EventEmitter; | ||
|
||
interface EntitiesEvents { | ||
newEntity: (entity: Entity, publisherOptions?: EntityOptions) => void; | ||
|
||
stateUpdate: ( | ||
id: string, | ||
state: boolean | string | number, | ||
distributed?: boolean | ||
) => void; | ||
|
||
attributesUpdate: ( | ||
entityId: string, | ||
attributes: { [key: string]: any }, | ||
distributed?: boolean | ||
) => void; | ||
} | ||
|
||
export type EntitiesEventEmitter = StrictEventEmitter< | ||
EventEmitter, | ||
EntitiesEvents | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/publishers/entity-options.entity.ts → src/entities/entity-options.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...luetooth-low-energy-distributed.sensor.ts → ...luetooth-low-energy-distributed.sensor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...uetooth-low-energy-distributed.service.ts → ...uetooth-low-energy-distributed.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
src/integrations/bluetooth-low-energy/bluetooth-low-energy.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { DynamicModule, Module } from '@nestjs/common'; | ||
import { BluetoothLowEnergyService } from './bluetooth-low-energy.service'; | ||
import { EntitiesModule } from '../../entities/entities.module'; | ||
import { ConfigModule } from '../../config/config.module'; | ||
import { ClusterModule } from '../../cluster/cluster.module'; | ||
import { BluetoothLowEnergyDistributedService } from './bluetooth-low-energy-distributed.service'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
|
||
@Module({}) | ||
export default class BluetoothLowEnergyModule { | ||
static forRoot(): DynamicModule { | ||
return { | ||
module: BluetoothLowEnergyModule, | ||
imports: [ | ||
EntitiesModule, | ||
ConfigModule, | ||
ClusterModule, | ||
ScheduleModule.forRoot() | ||
], | ||
providers: [ | ||
BluetoothLowEnergyService, | ||
BluetoothLowEnergyDistributedService | ||
] | ||
}; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/home-assistant/device.ts → src/integrations/home-assistant/device.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DynamicModule, Module } from '@nestjs/common'; | ||
import { HomeAssistantService } from './home-assistant.service'; | ||
import { ConfigModule } from '../../config/config.module'; | ||
|
||
@Module({}) | ||
export default class HomeAssistantModule { | ||
static forRoot(): DynamicModule { | ||
return { | ||
module: HomeAssistantModule, | ||
imports: [ConfigModule], | ||
providers: [HomeAssistantService] | ||
}; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.