diff --git a/.gitignore b/.gitignore index e52bf75d..45212a99 100644 --- a/.gitignore +++ b/.gitignore @@ -138,4 +138,5 @@ inspectionProfiles/ # Other things reports/ _*.json -**/_*.ts \ No newline at end of file +**/_*.ts +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index c2c7fc4a..e0aab16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Since version 1.0.0, we try to follow the [Semantic Versioning](https://semver.o ## [Unreleased] +### Added + +- Expose moving as motion sensor. + ## [1.11.0-beta.6] - 2024-06-30 ### Changed diff --git a/docs/sensors.md b/docs/sensors.md index 4ab83c63..ea782a80 100644 --- a/docs/sensors.md +++ b/docs/sensors.md @@ -21,6 +21,7 @@ The following table shows the possible exposes entries and the services and char | `contact` | published | [Contact Sensor](https://developers.homebridge.io/#/service/ContactSensor) | [Contact Sensor State](https://developers.homebridge.io/#/characteristic/ContactSensorState) | | | `occupancy` | published | [Occupancy Sensor](https://developers.homebridge.io/#/service/OccupancySensor) | [Occupancy Detected](https://developers.homebridge.io/#/characteristic/OccupancyDetected) | | | `vibration` | published | [Motion Sensor](https://developers.homebridge.io/#/service/MotionSensor) | [Motion Detected](https://developers.homebridge.io/#/characteristic/MotionDetected) | | +| `moving` | published | [Motion Sensor](https://developers.homebridge.io/#/service/MotionSensor) | [Motion Detected](https://developers.homebridge.io/#/characteristic/MotionDetected) | | | `smoke` | published | [Smoke Sensor](https://developers.homebridge.io/#/service/SmokeSensor) | [Smoke Detected](https://developers.homebridge.io/#/characteristic/SmokeDetected) | | | `carbon_monoxide` | published | [Carbon Monoxide Sensor](https://developers.homebridge.io/#/service/CarbonMonoxideSensor) | [Carbon Monoxide Detected](https://developers.homebridge.io/#/characteristic/CarbonMonoxideDetected) | | | `co2` | published | [Carbon Dioxide Sensor](https://developers.homebridge.io/#/service/CarbonDioxideSensor) | [Carbon Dioxide Detected](https://developers.homebridge.io/#/characteristic/CarbonDioxideDetected) / [Carbon Dioxide Level](https://developers.homebridge.io/#/characteristic/CarbonDioxideLevel) | Detection threshold is currently fixed at 1200 ppm | diff --git a/test/basic_sensors.spec.ts b/test/basic_sensors.spec.ts index 403edbf9..88983cfd 100644 --- a/test/basic_sensors.spec.ts +++ b/test/basic_sensors.spec.ts @@ -645,4 +645,48 @@ describe('Basic Sensors', () => { ); }); }); + + describe('SmartThings IM6001-MPP01', () => { + // Shared "state" + let deviceExposes: ExposesEntry[] = []; + let harness: ServiceHandlersTestHarness; + let movingSensorId: string; + + beforeEach(() => { + // Only test service creation for first test case and reuse harness afterwards + if (deviceExposes.length === 0 && harness === undefined) { + // Load exposes from JSON + deviceExposes = loadExposesFromFile('smartthings/im6001-mpp01.json'); + expect(deviceExposes.length).toBeGreaterThan(0); + const newHarness = new ServiceHandlersTestHarness(); + + // Check service creation + movingSensorId = 'moving_' + hap.Service.MotionSensor.UUID; + newHarness + .getOrAddHandler(hap.Service.MotionSensor, 'moving', movingSensorId) + .addExpectedCharacteristic('moving', hap.Characteristic.MotionDetected); + newHarness.prepareCreationMocks(); + + newHarness.callCreators(deviceExposes); + + newHarness.checkCreationExpectations(); + newHarness.checkHasMainCharacteristics(); + newHarness.checkExpectedGetableKeys([]); + harness = newHarness; + } + harness?.clearMocks(); + }); + + afterEach(() => { + verifyAllWhenMocksCalled(); + resetAllWhenMocks(); + }); + + test('Update moving', (): void => { + expect(harness).toBeDefined(); + harness.checkSingleUpdateState('{"moving":false}', movingSensorId, hap.Characteristic.MotionDetected, false); + harness.clearMocks(); + harness.checkSingleUpdateState('{"moving":true}', movingSensorId, hap.Characteristic.MotionDetected, true); + }); + }); }); diff --git a/test/exposes/smartthings/im6001-mpp01.json b/test/exposes/smartthings/im6001-mpp01.json new file mode 100644 index 00000000..1d28736f --- /dev/null +++ b/test/exposes/smartthings/im6001-mpp01.json @@ -0,0 +1,36 @@ +[ + { + "name": "battery", + "label": "Battery", + "access": 1, + "type": "numeric", + "property": "battery", + "description": "Remaining battery in %, can take up to 24 hours before reported", + "category": "diagnostic", + "unit": "%", + "value_max": 100, + "value_min": 0 + }, + { + "name": "moving", + "label": "Moving", + "access": 1, + "type": "binary", + "property": "moving", + "description": "Indicates whether the device is moving", + "value_on": true, + "value_off": false + }, + { + "name": "linkquality", + "label": "Linkquality", + "access": 1, + "type": "numeric", + "property": "linkquality", + "description": "Link quality (signal strength)", + "category": "diagnostic", + "unit": "lqi", + "value_max": 255, + "value_min": 0 + } +]