Skip to content

Commit

Permalink
Added documentation, test and created changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
torandreroland committed Nov 20, 2024
1 parent bf4b05f commit a117ab6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ inspectionProfiles/
# Other things
reports/
_*.json
**/_*.ts
**/_*.ts
.DS_Store
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
44 changes: 44 additions & 0 deletions test/basic_sensors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
36 changes: 36 additions & 0 deletions test/exposes/smartthings/im6001-mpp01.json
Original file line number Diff line number Diff line change
@@ -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
}
]

0 comments on commit a117ab6

Please sign in to comment.