Skip to content

Commit

Permalink
feat(bluetooth-low-energy): individual devices per peripheral
Browse files Browse the repository at this point in the history
Tags are now sent to Home Assistant as individual devices.
  • Loading branch information
mKeRix committed Jan 31, 2020
1 parent 1a3c470 commit fadd9be
Showing 1 changed file with 14 additions and 2 deletions.
Expand Up @@ -18,6 +18,7 @@ import { RoomPresenceDistanceSensor } from '../room-presence/room-presence-dista
import { SchedulerRegistry } from '@nestjs/schedule';
import { KalmanFilterable } from '../../util/filters';
import { makeId } from '../../util/id';
import { DISTRIBUTED_DEVICE_ID } from '../home-assistant/home-assistant.const';

export const NEW_DISTANCE_CHANNEL = 'bluetooth-low-energy.new-distance';

Expand Down Expand Up @@ -103,7 +104,11 @@ export class BluetoothLowEnergyService extends KalmanFilterable(Object, 0.8, 15)
if (this.entitiesService.has(sensorId)) {
sensor = this.entitiesService.get(sensorId) as RoomPresenceDistanceSensor;
} else {
sensor = this.createRoomPresenceSensor(sensorId, event.tagName);
sensor = this.createRoomPresenceSensor(
sensorId,
event.tagId,
event.tagName
);
}

sensor.handleNewDistance(event.instanceName, event.distance);
Expand Down Expand Up @@ -167,19 +172,26 @@ export class BluetoothLowEnergyService extends KalmanFilterable(Object, 0.8, 15)
* Creates and registers a new room presence sensor.
*
* @param sensorId - Id that the sensor should receive
* @param deviceId - Id of the BLE peripheral
* @param deviceName - Name of the BLE peripheral
* @returns Registered room presence sensor
*/
protected createRoomPresenceSensor(
sensorId: string,
deviceId: string,
deviceName: string
): RoomPresenceDistanceSensor {
const sensorName = `${deviceName} Room Presence`;
const customizations: Array<EntityCustomization<any>> = [
{
for: SensorConfig,
overrides: {
icon: 'mdi:bluetooth'
icon: 'mdi:bluetooth',
device: {
identifiers: deviceId,
name: deviceName,
viaDevice: DISTRIBUTED_DEVICE_ID
}
}
}
];
Expand Down

0 comments on commit fadd9be

Please sign in to comment.