1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.DoorbellController = void 0;
|
4 | const Characteristic_1 = require("../Characteristic");
|
5 | const Service_1 = require("../Service");
|
6 | const CameraController_1 = require("./CameraController");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | class DoorbellController extends CameraController_1.CameraController {
|
20 | doorbellService;
|
21 | doorbellServiceExternallySupplied = false;
|
22 | |
23 |
|
24 |
|
25 | doorbellOptions;
|
26 | |
27 |
|
28 |
|
29 |
|
30 | constructor(options) {
|
31 | super(options);
|
32 | this.doorbellOptions = {
|
33 | name: options.name,
|
34 | externalDoorbellService: options.externalDoorbellService,
|
35 | };
|
36 | }
|
37 | |
38 |
|
39 |
|
40 | ringDoorbell() {
|
41 | this.doorbellService.updateCharacteristic(Characteristic_1.Characteristic.ProgrammableSwitchEvent, Characteristic_1.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
42 | }
|
43 | constructServices() {
|
44 | if (this.doorbellOptions?.externalDoorbellService) {
|
45 | this.doorbellService = this.doorbellOptions.externalDoorbellService;
|
46 | this.doorbellServiceExternallySupplied = true;
|
47 | }
|
48 | else {
|
49 | this.doorbellService = new Service_1.Service.Doorbell(this.doorbellOptions?.name ?? "", "");
|
50 | }
|
51 | this.doorbellService.setPrimaryService();
|
52 | const serviceMap = super.constructServices();
|
53 | if (!this.doorbellServiceExternallySupplied) {
|
54 | serviceMap.doorbell = this.doorbellService;
|
55 | }
|
56 | return serviceMap;
|
57 | }
|
58 | initWithServices(serviceMap) {
|
59 | const result = super._initWithServices(serviceMap);
|
60 | if (this.doorbellOptions?.externalDoorbellService) {
|
61 | this.doorbellService = this.doorbellOptions.externalDoorbellService;
|
62 | this.doorbellServiceExternallySupplied = true;
|
63 | if (result.serviceMap.doorbell) {
|
64 | delete result.serviceMap.doorbell;
|
65 | result.updated = true;
|
66 | }
|
67 | }
|
68 | else {
|
69 | this.doorbellService = result.serviceMap.doorbell;
|
70 | if (!this.doorbellService) {
|
71 | this.doorbellService = new Service_1.Service.Doorbell(this.doorbellOptions?.name ?? "", "");
|
72 | result.serviceMap.doorbell = this.doorbellService;
|
73 | result.updated = true;
|
74 | }
|
75 | }
|
76 | this.doorbellService.setPrimaryService();
|
77 | if (result.updated) {
|
78 | return result.serviceMap;
|
79 | }
|
80 | }
|
81 |
|
82 | migrateFromDoorbell(serviceMap) {
|
83 | return false;
|
84 | }
|
85 | retrieveEventTriggerOptions() {
|
86 | const result = super.retrieveEventTriggerOptions();
|
87 | result.add(2 );
|
88 | return result;
|
89 | }
|
90 | handleControllerRemoved() {
|
91 | super.handleControllerRemoved();
|
92 | this.doorbellService = undefined;
|
93 | }
|
94 | configureServices() {
|
95 | super.configureServices();
|
96 | this.doorbellService.getCharacteristic(Characteristic_1.Characteristic.ProgrammableSwitchEvent)
|
97 | .onGet(() => null);
|
98 | this.doorbellOptions = undefined;
|
99 | }
|
100 | }
|
101 | exports.DoorbellController = DoorbellController;
|
102 |
|
\ | No newline at end of file |