Skip to content

Commit

Permalink
Expose moving as motion sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
torandreroland committed Nov 16, 2024
1 parent 46dbd07 commit bf4b05f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/converters/basic_sensors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { WaterLeakSensorHandler, GasLeakSensorHandler } from './basic_sensors/le
import { CarbonMonoxideSensorHandler } from './basic_sensors/carbon_monoxide';
import { SmokeSensorHandler } from './basic_sensors/smoke';
import { VibrationSensorHandler } from './basic_sensors/vibration';
import { MovingSensorHandler } from './basic_sensors/moving';
import { PresenceSensorHandler } from './basic_sensors/presence';
import { OccupancySensorHandler } from './basic_sensors/occupancy';
import { IdentifierGenerator } from './basic_sensors/basic';
Expand Down Expand Up @@ -52,6 +53,7 @@ export class BasicSensorCreator implements ServiceCreator {
OccupancySensorHandler,
PresenceSensorHandler,
VibrationSensorHandler,
MovingSensorHandler,
SmokeSensorHandler,
CarbonMonoxideSensorHandler,
WaterLeakSensorHandler,
Expand Down
30 changes: 30 additions & 0 deletions src/converters/basic_sensors/moving.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { BasicAccessory } from '../interfaces';
import { ExposesEntryWithBinaryProperty, ExposesEntryWithProperty } from '../../z2mModels';
import { hap } from '../../hap';
import { BinarySensorHandler } from './binary';

export class MovingSensorHandler extends BinarySensorHandler {
public static readonly exposesName: string = 'moving';

constructor(expose: ExposesEntryWithProperty, otherExposes: ExposesEntryWithBinaryProperty[], accessory: BasicAccessory) {
super(
accessory,
expose as ExposesEntryWithBinaryProperty,
otherExposes,
MovingSensorHandler.generateIdentifier,
'Motion Sensor (moving)',
(n, t) => new hap.Service.MotionSensor(n, (MovingSensorHandler.exposesName + ' ' + (t ?? '')).trim()),
hap.Characteristic.MotionDetected,
true,
false
);
}

static generateIdentifier(endpoint: string | undefined) {
let identifier = MovingSensorHandler.exposesName + '_' + hap.Service.MotionSensor.UUID;
if (endpoint !== undefined) {
identifier += '_' + endpoint.trim();
}
return identifier;
}
}

0 comments on commit bf4b05f

Please sign in to comment.