Skip to content

Commit

Permalink
Add zd Vibration Sensor support. (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5e authored Mar 16, 2023
1 parent 97781d1 commit 2fb159a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Add Fingerbot support (`szjqr`).
- Add Smart Lock support (`ms`, `jtmspro`). (#120) Thanks @pfgimutao for the contribution
- Add Alarm Host support (`mal`). (#246) Thanks @bFollon for the contribution
- Add Vibration Sensor support (`zd`).


### Fixed
Expand Down
2 changes: 1 addition & 1 deletion SUPPORTED_DEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Most category code is pinyin abbreviation of Chinese name.
| Smoke Alarm | 烟雾报警传感器 | ywbj | Smoke Sensor || [Documentation](https://developer.tuya.com/en/docs/iot/categoryywbj?id=Kaiuz3f6sf952) |
| Temperature and Humidity Sensor | 温湿度传感器 | wsdcg | Temperature Sensor<br> Humidity Sensor || [Documentation](https://developer.tuya.com/en/docs/iot/categorywsdcg?id=Kaiuz3hinij34) |
| Contact Sensor | 门磁传感器 | mcs | Contact Sensor || [Documentation](https://developer.tuya.com/en/docs/iot/categorymcs?id=Kaiuz3bnflmh2) |
| Vibration Sensor | 震动传感器 | zd | | | [Documentation](https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno) |
| Vibration Sensor | 震动传感器 | zd | Motion Sensor | | [Documentation](https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno) |
| Water Detector | 水浸传感器 | sj | Leak Sensor || [Documentation](https://developer.tuya.com/en/docs/iot/categorysj?id=Kaiuz3iub2sli) |
| Luminance Sensor | 亮度传感器 | ldcg | Light Sensor || [Documentation](https://developer.tuya.com/en/docs/iot/categoryldcg?id=Kaiuz3n7u69l8) |
| Pressure Sensor | 压力传感器 | ylcg<br> ylcgq | | | [Documentation](https://developer.tuya.com/en/docs/iot/categoryylcg?id=Kaiuz3kc2e4gm) |
Expand Down
4 changes: 4 additions & 0 deletions src/accessory/AccessoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import IRControlHubAccessory from './IRControlHubAccessory';
import IRGenericAccessory from './IRGenericAccessory';
import IRAirConditionerAccessory from './IRAirConditionerAccessory';
import SecuritySystemAccessory from './SecuritySystemAccessory';
import VibrationSensorAccessory from './VibrationSensorAccessory';


export default class AccessoryFactory {
Expand Down Expand Up @@ -142,6 +143,9 @@ export default class AccessoryFactory {
case 'mcs':
handler = new ContactSensorAccessory(platform, accessory);
break;
case 'zd':
handler = new VibrationSensorAccessory(platform, accessory);
break;
case 'rqbj':
case 'jwbj':
case 'sj':
Expand Down
25 changes: 25 additions & 0 deletions src/accessory/VibrationSensorAccessory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import BaseAccessory from './BaseAccessory';

const SCHEMA_CODE = {
STATE: ['shock_state'],
};

export default class VibrationSensorAccessory extends BaseAccessory {

requiredSchema() {
return [SCHEMA_CODE.STATE];
}

configureServices() {
const service = this.accessory.getService(this.Service.MotionSensor)
|| this.accessory.addService(this.Service.MotionSensor);

const schema = this.getSchema(...SCHEMA_CODE.STATE)!;
service.getCharacteristic(this.Characteristic.MotionDetected)
.onGet(() => {
const status = this.getStatus(schema.code)!;
return status.value !== 'normal';
});
}

}

0 comments on commit 2fb159a

Please sign in to comment.