diff --git a/src/converters/basic_sensors.ts b/src/converters/basic_sensors.ts index cf171397..f83429a4 100644 --- a/src/converters/basic_sensors.ts +++ b/src/converters/basic_sensors.ts @@ -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'; @@ -52,6 +53,7 @@ export class BasicSensorCreator implements ServiceCreator { OccupancySensorHandler, PresenceSensorHandler, VibrationSensorHandler, + MovingSensorHandler, SmokeSensorHandler, CarbonMonoxideSensorHandler, WaterLeakSensorHandler, diff --git a/src/converters/basic_sensors/moving.ts b/src/converters/basic_sensors/moving.ts new file mode 100644 index 00000000..6c66d3a9 --- /dev/null +++ b/src/converters/basic_sensors/moving.ts @@ -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; + } +}