homebridge-easy-mqtt 1.4.1-beta.1 → 1.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +86 -5
  3. package/config.schema.json +76 -1
  4. package/dist/accessory/abstract/base.d.ts +2 -2
  5. package/dist/accessory/abstract/base.js +5 -25
  6. package/dist/accessory/abstract/base.js.map +1 -1
  7. package/dist/accessory/abstract/common.d.ts +17 -6
  8. package/dist/accessory/abstract/common.js +136 -28
  9. package/dist/accessory/abstract/common.js.map +1 -1
  10. package/dist/accessory/abstract/mqtt.d.ts +2 -0
  11. package/dist/accessory/abstract/mqtt.js +13 -12
  12. package/dist/accessory/abstract/mqtt.js.map +1 -1
  13. package/dist/accessory/addons/filter.d.ts +0 -1
  14. package/dist/accessory/addons/filter.js +1 -13
  15. package/dist/accessory/addons/filter.js.map +1 -1
  16. package/dist/accessory/characteristic/characteristic.d.ts +3 -0
  17. package/dist/accessory/characteristic/characteristic.js +23 -0
  18. package/dist/accessory/characteristic/characteristic.js.map +1 -0
  19. package/dist/accessory/characteristic/custom.d.ts +1 -0
  20. package/dist/accessory/characteristic/custom.js +3 -0
  21. package/dist/accessory/characteristic/custom.js.map +1 -1
  22. package/dist/accessory/characteristic/eve.d.ts +6 -0
  23. package/dist/accessory/characteristic/eve.js +24 -0
  24. package/dist/accessory/characteristic/eve.js.map +1 -0
  25. package/dist/accessory/climate/active.d.ts +0 -4
  26. package/dist/accessory/climate/active.js +4 -36
  27. package/dist/accessory/climate/active.js.map +1 -1
  28. package/dist/accessory/climate/fan2.d.ts +1 -12
  29. package/dist/accessory/climate/fan2.js +22 -101
  30. package/dist/accessory/climate/fan2.js.map +1 -1
  31. package/dist/accessory/climate/heaterCooler.d.ts +1 -11
  32. package/dist/accessory/climate/heaterCooler.js +24 -100
  33. package/dist/accessory/climate/heaterCooler.js.map +1 -1
  34. package/dist/accessory/climate/purifier.d.ts +1 -11
  35. package/dist/accessory/climate/purifier.js +20 -90
  36. package/dist/accessory/climate/purifier.js.map +1 -1
  37. package/dist/accessory/climate/temperatureControl.d.ts +2 -1
  38. package/dist/accessory/climate/temperatureControl.js +3 -3
  39. package/dist/accessory/climate/temperatureControl.js.map +1 -1
  40. package/dist/accessory/climate/thermostat.d.ts +1 -9
  41. package/dist/accessory/climate/thermostat.js +24 -77
  42. package/dist/accessory/climate/thermostat.js.map +1 -1
  43. package/dist/accessory/garage.d.ts +1 -9
  44. package/dist/accessory/garage.js +19 -85
  45. package/dist/accessory/garage.js.map +1 -1
  46. package/dist/accessory/lock.d.ts +1 -5
  47. package/dist/accessory/lock.js +23 -57
  48. package/dist/accessory/lock.js.map +1 -1
  49. package/dist/accessory/onoff/lightbulb.d.ts +1 -2
  50. package/dist/accessory/onoff/lightbulb.js +7 -13
  51. package/dist/accessory/onoff/lightbulb.js.map +1 -1
  52. package/dist/accessory/onoff/onoff.d.ts +2 -4
  53. package/dist/accessory/onoff/onoff.js +28 -32
  54. package/dist/accessory/onoff/onoff.js.map +1 -1
  55. package/dist/accessory/onoff/outlet.d.ts +1 -1
  56. package/dist/accessory/onoff/outlet.js +3 -3
  57. package/dist/accessory/onoff/outlet.js.map +1 -1
  58. package/dist/accessory/onoff/switch.d.ts +1 -2
  59. package/dist/accessory/onoff/switch.js +0 -3
  60. package/dist/accessory/onoff/switch.js.map +1 -1
  61. package/dist/accessory/position/blind.d.ts +1 -2
  62. package/dist/accessory/position/blind.js +5 -11
  63. package/dist/accessory/position/blind.js.map +1 -1
  64. package/dist/accessory/position/position.d.ts +0 -7
  65. package/dist/accessory/position/position.js +11 -62
  66. package/dist/accessory/position/position.js.map +1 -1
  67. package/dist/accessory/security.d.ts +3 -7
  68. package/dist/accessory/security.js +37 -69
  69. package/dist/accessory/security.js.map +1 -1
  70. package/dist/accessory/sensor/air.d.ts +1 -5
  71. package/dist/accessory/sensor/air.js +14 -46
  72. package/dist/accessory/sensor/air.js.map +1 -1
  73. package/dist/accessory/sensor/carbonDioxide.d.ts +1 -1
  74. package/dist/accessory/sensor/carbonDioxide.js +3 -3
  75. package/dist/accessory/sensor/carbonDioxide.js.map +1 -1
  76. package/dist/accessory/sensor/carbonMonoxide.d.ts +1 -1
  77. package/dist/accessory/sensor/carbonMonoxide.js +3 -3
  78. package/dist/accessory/sensor/carbonMonoxide.js.map +1 -1
  79. package/dist/accessory/sensor/contact.d.ts +1 -1
  80. package/dist/accessory/sensor/contact.js +18 -5
  81. package/dist/accessory/sensor/contact.js.map +1 -1
  82. package/dist/accessory/sensor/humidity.d.ts +1 -1
  83. package/dist/accessory/sensor/humidity.js +7 -4
  84. package/dist/accessory/sensor/humidity.js.map +1 -1
  85. package/dist/accessory/sensor/leak.d.ts +1 -1
  86. package/dist/accessory/sensor/leak.js +3 -3
  87. package/dist/accessory/sensor/leak.js.map +1 -1
  88. package/dist/accessory/sensor/light.d.ts +1 -1
  89. package/dist/accessory/sensor/light.js +3 -3
  90. package/dist/accessory/sensor/light.js.map +1 -1
  91. package/dist/accessory/sensor/motion.d.ts +1 -1
  92. package/dist/accessory/sensor/motion.js +7 -4
  93. package/dist/accessory/sensor/motion.js.map +1 -1
  94. package/dist/accessory/sensor/occupancy.d.ts +1 -1
  95. package/dist/accessory/sensor/occupancy.js +3 -3
  96. package/dist/accessory/sensor/occupancy.js.map +1 -1
  97. package/dist/accessory/sensor/sensor.d.ts +0 -2
  98. package/dist/accessory/sensor/sensor.js +2 -26
  99. package/dist/accessory/sensor/sensor.js.map +1 -1
  100. package/dist/accessory/sensor/smoke.d.ts +1 -1
  101. package/dist/accessory/sensor/smoke.js +3 -3
  102. package/dist/accessory/sensor/smoke.js.map +1 -1
  103. package/dist/accessory/sensor/temperature.d.ts +1 -1
  104. package/dist/accessory/sensor/temperature.js +7 -4
  105. package/dist/accessory/sensor/temperature.js.map +1 -1
  106. package/dist/accessory/valve.d.ts +1 -5
  107. package/dist/accessory/valve.js +7 -41
  108. package/dist/accessory/valve.js.map +1 -1
  109. package/dist/homebridge/platform.js +8 -4
  110. package/dist/homebridge/platform.js.map +1 -1
  111. package/dist/homebridge-ui/public/index.html +1 -1
  112. package/dist/homebridge-ui/public/ui.js +1 -1
  113. package/dist/i18n/en.d.ts +19 -5
  114. package/dist/i18n/en.js +20 -6
  115. package/dist/i18n/en.js.map +1 -1
  116. package/dist/i18n/fr.d.ts +19 -5
  117. package/dist/i18n/i18n.d.ts +19 -5
  118. package/dist/i18n/it.d.ts +19 -5
  119. package/dist/i18n/ro.d.ts +19 -5
  120. package/dist/i18n/template.d.ts +19 -5
  121. package/dist/i18n/vi.d.ts +19 -5
  122. package/dist/model/enums.d.ts +12 -1
  123. package/dist/model/enums.js +12 -0
  124. package/dist/model/enums.js.map +1 -1
  125. package/dist/model/history.d.ts +32 -0
  126. package/dist/model/history.js +128 -0
  127. package/dist/model/history.js.map +1 -0
  128. package/dist/model/mqtt.d.ts +1 -0
  129. package/dist/model/mqtt.js +37 -11
  130. package/dist/model/mqtt.js.map +1 -1
  131. package/dist/model/types.d.ts +15 -3
  132. package/lib/fakegato-history/fakegato-history.js +887 -0
  133. package/lib/fakegato-history/fakegato-storage.js +178 -0
  134. package/lib/fakegato-history/fakegato-timer.js +133 -0
  135. package/lib/fakegato-history/lib/uuid.js +25 -0
  136. package/lib/fakegato-history/package.json +5 -0
  137. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -2,10 +2,17 @@
2
2
 
3
3
  All notable changes to homebridge-dummy will be documented in this file.
4
4
 
5
- ## 1.4.1-beta.1 (2025-10-10)
5
+ ## 1.5.0-beta.1 (2025-10-20)
6
6
 
7
7
  ### Added
8
+ - [Value Transformers](https://github.com/mpatfield/homebridge-easy-mqtt#history) (Thank you [@nehmeroumani](https://github.com/sponsors/nehmeroumani) for the code contribution!)
8
9
  - `Doorbell` accessory type
10
+ - History and additional characteristics for for [Eve app](https://apps.apple.com/us/app/eve-for-matter-homekit/id917695792) users ([documentation](https://github.com/mpatfield/homebridge-easy-mqtt#history))
11
+ - Opened/closed history, and times opened count with option to reset for `ContactSensor`
12
+ - `MotionSensor` history
13
+ - Temperature history for `HeaterCooler`, `TemperatureSensor`, and `Thermostat`
14
+ - Humidity history for `HumiditySensor` and `Thermostat`
15
+ - On/off history and watts/amps/volts/kWh history for `Lightbulb`, `Outlet`, and `Switch`
9
16
  - Traduzioni in italiano. Grazie, [@Shikaban](https://github.com/sponsors/Shikaban)!
10
17
 
11
18
  ### Notes
package/README.md CHANGED
@@ -83,6 +83,11 @@ Using the Homebridge Config UI is the easiest way to set up this plugin. However
83
83
 
84
84
  ]
85
85
  },
86
+ "history": {
87
+ "enabled": true,
88
+ "disableRepeatLastData": false,
89
+ "size": 4032,
90
+ },
86
91
  "customCharacteristics": [
87
92
  {
88
93
  "uuid": "string",
@@ -135,7 +140,7 @@ Note that setting the this information in the JSON config will override the envi
135
140
 
136
141
  You will need to make sure to populate the appropriate topics based on the accessory type defined below.
137
142
 
138
- You may define topics using a JSONPath dot notation to assist the parser in finding the right value within the message. See [JSONPaths](#jsonpaths) below for more details.
143
+ You may define topics using a JSONPath dot notation to assist the parser in finding the right value within the message. You can also add a value transformer to alter the incoming or outgoing value. See [Advanced Topic Notation](#advanced-topic-notation) below for more details.
139
144
 
140
145
  As with topics, you will also need to populate the appropriate values based on the type. Note that while they are defined as strings, they will be auto-converted to the appropriate primitives (e.g. boolean or number) where appropriate.
141
146
 
@@ -164,18 +169,30 @@ These values are used for both determining current state and, where appropriate,
164
169
  - `topicSetHue` - For setting the lightbulb's current hue
165
170
  - `topicGetSaturation` - The current saturation setting of the lightbulb
166
171
  - `topicSetSaturation` - For setting the saturation setting of the lightbulb
172
+ - `topicGetCurrentConsumption` - Get the current power rate in watts ([Eve only](#eve-app-support))
173
+ - `topicGetElectricCurrent` - Get the electrical current in amps ([Eve only](#eve-app-support))
174
+ - `topicGetTotalConsumption` - Get the total energy use in kWh ([Eve only](#eve-app-support))
175
+ - `topicGetVoltage` - Get the current voltage ([Eve only](#eve-app-support))
167
176
 
168
177
  #### Outlet
169
178
  - `topicGetOn*` - The current state of the outlet, i.e. on/off
170
179
  - `topicSetOn*` - For setting the state of the outlet
180
+ - `topicGetOutletInUse` - Whether or not the outlet is
171
181
  - `valueOn*` - Turned on, e.g. "true", or "1", or "On"
172
182
  - `valueOff*` - Turned off, e.g. "false", or "0", or "Off"
173
- - `topicGetOutletInUse` - Whether or not the outlet is currently being used
174
183
  - `valueOutletInUse` - Currently being used, e.g. "true", or "1", or "On"
184
+ - `topicGetCurrentConsumption` - Get the current power rate in watts ([Eve only](#eve-app-support))
185
+ - `topicGetElectricCurrent` - Get the electrical current in amps ([Eve only](#eve-app-support))
186
+ - `topicGetTotalConsumption` - Get the total energy use in kWh ([Eve only](#eve-app-support))
187
+ - `topicGetVoltage` - Get the current voltage ([Eve only](#eve-app-support))
175
188
 
176
189
  #### Switch
177
190
  - `topicGetOn*` - The current state of the outlet, i.e. on/off
178
191
  - `topicSetOn*` - For setting the state of the outlet
192
+ - `topicGetCurrentConsumption` - Get the current power rate in watts ([Eve only](#eve-app-support))
193
+ - `topicGetElectricCurrent` - Get the electrical current in amps ([Eve only](#eve-app-support))
194
+ - `topicGetTotalConsumption` - Get the total energy use in kWh ([Eve only](#eve-app-support))
195
+ - `topicGetVoltage` - Get the current voltage ([Eve only](#eve-app-support))
179
196
  - `valueOn*` - Turned on, e.g. "true", or "1", or "On"
180
197
  - `valueOff*` - Turned off, e.g. "false", or "0", or "Off"
181
198
 
@@ -545,7 +562,9 @@ Each entry should have a topic and a message:
545
562
  ]
546
563
  ```
547
564
 
548
- ## JSONPaths
565
+ ## Advanced Topic Notation
566
+
567
+ ### JSONPaths
549
568
 
550
569
  For some devices, the desired values in the MQTT messages are embedded within a JSON object. For example, here is the MQTT message for my door lock that is received when the door is locked:
551
570
 
@@ -610,9 +629,69 @@ then you would use the topic
610
629
 
611
630
  `zwave/4/security/set$.target.mode.value`
612
631
 
613
- ## Custom Characteristics
632
+ ### Value Transformers
633
+
634
+ There are other situations where the value needs to be adjusted or altered entirely.
635
+
636
+ For example, you may have an Air Quality Sensor that measures Nitrogen Dioxide in ppm (parts per million) instead of µg/m³ (micrograms per cubic meter) which HomeKit expects. In this case, you need to multiply by the arbitrary number 1883 to get the correct result.
637
+
638
+ Using the pipe (`|`) notation, you may add a transformer:
639
+
640
+ `airquality/no2|value * 1883`
641
+
642
+ This will multiply the value by `1883` to get the desired result.
643
+
644
+ Note that `value` is a reserved keyword here to indicate the incoming value you'd like to transform.
645
+
646
+ You can also do the same thing on the publish side to transfer it back to ppm. In this case, you would need to divide by 1883.
647
+
648
+ `airquality/no2|value / 1883`
649
+
650
+ ### Both JSONPath + Transformer
651
+
652
+ You can also combine JSONPath and Transformer notation into a single entity
653
+
654
+ `airquality$.no2|value * 1883`
655
+
656
+ ## Eve App Support
657
+
658
+ If you use [Eve](https://apps.apple.com/us/app/eve-for-matter-homekit/id917695792), then there are some additional features available:
659
+ - Opened/closed history, and times opened count with option to reset for `ContactSensor`
660
+ - `MotionSensor` history
661
+ - Temperature history for `HeaterCooler`, `TemperatureSensor`, and `Thermostat`
662
+ - Humidity history for `HumiditySensor` and `Thermostat`
663
+ - On/off history for `Lightbulb`, `Outlet`, and `Switch`
614
664
 
615
- If you use a more advanced HomeKit app like [Eve](https://apps.apple.com/us/app/eve-for-matter-homekit/id917695792) or [Controller for Homekit](https://apps.apple.com/us/app/controller-for-homekit/id1198176727), you can add custom characteristics to display any arbitrary numeric information. Unfortunately, Apple currently doesn't offer a way to display this in the Home app.
665
+ You can also add get topics for watts/amps/volts/kWh for `Lightbulb`, `Outlet`, and `Switch`:
666
+ - `topicGetCurrentConsumption` - Get the current power rate in watts
667
+ - `topicGetElectricCurrent` - Get the electrical current in amps
668
+ - `topicGetTotalConsumption` - Get the total energy use in kWh
669
+ - `topicGetVoltage` - Get the current voltage
670
+
671
+ To enable history, choose the `History Enabled` option in the config UI.
672
+
673
+ There are a couple of advanced options if configuring via JSON:
674
+
675
+ ```json
676
+ {
677
+ "info": …
678
+ "mqtt": …
679
+ "history": {
680
+ "enabled": true,
681
+ "disableRepeatLastData": false,
682
+ "size": 4032,
683
+ },
684
+ … // Topic & Values
685
+ }
686
+ ```
687
+
688
+ - `enabled` — used to enable/disable history
689
+ - `disableRepeatLastData` — See [fakegato-history](https://github.com/simont77/fakegato-history?tab=readme-ov-file#fakegato-history) for info
690
+ - `size` - The maximum number of history entries. Default is 4032 (1 entry every 10 minutes for 28 days)
691
+
692
+ ### Custom Characteristics
693
+
694
+ Eve users can also add custom characteristics to display any arbitrary numeric information.
616
695
 
617
696
  <img src="https://raw.githubusercontent.com/mpatfield/homebridge-easy-mqtt/refs/heads/latest/img/screenshot_1.png">
618
697
 
@@ -653,4 +732,6 @@ By default, all accessory values are saved and reloaded when the plugin restarts
653
732
 
654
733
  [Keryan Belahcene](https://www.instagram.com/keryan.me) for creating the [Flume](https://github.com/homebridge-plugins/homebridge-flume) header logo which I adapted for this plugin
655
734
 
735
+ [fakegato-history](https://github.com/simont77/fakegato-history) by [@simont77](https://github.com/sponsors/simont77) *Copyright © 2017*
736
+
656
737
  And to the amazing creators/contributors of [Homebridge](https://homebridge.io) who made this plugin possible!
@@ -88,6 +88,15 @@
88
88
  }
89
89
  }
90
90
  },
91
+ "history": {
92
+ "type": "object",
93
+ "properties": {
94
+ "enabled": {
95
+ "type": "boolean",
96
+ "title": "${config.title.historyEnabled}"
97
+ }
98
+ }
99
+ },
91
100
  "customCharacteristic": {
92
101
  "type": "object",
93
102
  "properties": {
@@ -118,6 +127,7 @@
118
127
  "properties": {
119
128
  "info": { "$ref": "#/definitions/info" },
120
129
  "mqtt": { "$ref": "#/definitions/mqtt" },
130
+ "history": { "$ref": "#/definitions/history" },
121
131
  "customCharacteristics": {
122
132
  "type": "array",
123
133
  "items": { "$ref": "#/definitions/customCharacteristic" }
@@ -566,6 +576,22 @@
566
576
  "type": "string",
567
577
  "title": "${config.title.topicSetVolume}"
568
578
  },
579
+ "topicGetCurrentConsumption": {
580
+ "type": "string",
581
+ "title": "${config.title.topicGetCurrentConsumption}"
582
+ },
583
+ "topicGetElectricCurrent": {
584
+ "type": "string",
585
+ "title": "${config.title.topicGetElectricCurrent}"
586
+ },
587
+ "topicGetTotalConsumption": {
588
+ "type": "string",
589
+ "title": "${config.title.topicGetTotalConsumption}"
590
+ },
591
+ "topicGetVoltage": {
592
+ "type": "string",
593
+ "title": "${config.title.topicGetVoltage}"
594
+ },
569
595
  "valueBatteryLow": {
570
596
  "type": "string",
571
597
  "title": "${config.title.valueBatteryLow}"
@@ -1603,7 +1629,10 @@
1603
1629
  "required": ["topicGetObstructionDetected"]
1604
1630
  },
1605
1631
  "then": {
1606
- "required": ["valuePositionObstructed"]
1632
+ "anyOf": [
1633
+ { "required": ["valuePositionObstructed"] },
1634
+ { "required": ["valueDoorObstructed"] }
1635
+ ]
1607
1636
  }
1608
1637
  },
1609
1638
  {
@@ -1773,6 +1802,13 @@
1773
1802
  {
1774
1803
  "key": "accessories[].disableLogging",
1775
1804
  "flex": "0 0 25%"
1805
+ },
1806
+ {
1807
+ "key": "accessories[].history.enabled",
1808
+ "flex": "0 0 25%",
1809
+ "condition": {
1810
+ "functionBody": "return ['ContactSensor', 'HeaterCooler', 'HumiditySensor', 'Lightbulb', 'MotionSensor', 'Outlet', 'Switch', 'TemperatureSensor', 'Thermostat'].includes(model.accessories?.[arguments[1]]?.info?.type);"
1811
+ }
1776
1812
  }
1777
1813
  ]
1778
1814
  },
@@ -2173,6 +2209,45 @@
2173
2209
  }
2174
2210
  ]
2175
2211
  },
2212
+ {
2213
+ "type": "fieldset",
2214
+ "notitle": true,
2215
+ "condition": {
2216
+ "functionBody": "return ['Lightbulb', 'Outlet', 'Switch'].includes(model.accessories?.[arguments[1]]?.info?.type);"
2217
+ },
2218
+ "items": [
2219
+ {
2220
+ "type": "div",
2221
+ "displayFlex": true,
2222
+ "flex-direction": "row",
2223
+ "items": [
2224
+ {
2225
+ "key": "accessories[].topicGetCurrentConsumption",
2226
+ "flex": "0 0 50%"
2227
+ },
2228
+ {
2229
+ "key": "accessories[].topicGetTotalConsumption",
2230
+ "flex": "0 0 50%"
2231
+ }
2232
+ ]
2233
+ },
2234
+ {
2235
+ "type": "div",
2236
+ "displayFlex": true,
2237
+ "flex-direction": "row",
2238
+ "items": [
2239
+ {
2240
+ "key": "accessories[].topicGetElectricCurrent",
2241
+ "flex": "0 0 50%"
2242
+ },
2243
+ {
2244
+ "key": "accessories[].topicGetVoltage",
2245
+ "flex": "0 0 50%"
2246
+ }
2247
+ ]
2248
+ }
2249
+ ]
2250
+ },
2176
2251
  {
2177
2252
  "type": "fieldset",
2178
2253
  "notitle": true,
@@ -1,7 +1,7 @@
1
1
  import { MQTTAccessory } from './mqtt.js';
2
+ import { CharacteristicKey } from '../../model/enums.js';
2
3
  import { BaseAccessoryConfig, MQTTAccessoryDependency } from '../../model/types.js';
3
4
  export declare abstract class BaseAccessory<C extends BaseAccessoryConfig = BaseAccessoryConfig> extends MQTTAccessory<C> {
4
5
  constructor(dependency: MQTTAccessoryDependency<C>);
5
- private onBatteryLowUpdate;
6
- private onStatusActiveUpdate;
6
+ isOptionalCharacteristic(key: CharacteristicKey): boolean;
7
7
  }
@@ -1,5 +1,6 @@
1
1
  import { MQTTAccessory } from './mqtt.js';
2
2
  import { PLATFORM_NAME } from '../../homebridge/settings.js';
3
+ import { isOptionalHKCharacteristic } from '../characteristic/characteristic.js';
3
4
  import { strings } from '../../i18n/i18n.js';
4
5
  import { HKCharacteristicKey } from '../../model/enums.js';
5
6
  import { LogType } from '../../tools/log.js';
@@ -17,32 +18,11 @@ export class BaseAccessory extends MQTTAccessory {
17
18
  .setCharacteristic(dependency.Characteristic.FirmwareRevision, dependency.config.info.version ?? getVersion());
18
19
  }
19
20
  this.setup(HKCharacteristicKey.BatteryLevel, 100, 'topicGetBatteryLevel', this.bindOnUpdateNumeric(HKCharacteristicKey.BatteryLevel, strings.accessory.batteryLevel), false);
20
- this.setup(HKCharacteristicKey.StatusLowBattery, dependency.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL, 'topicGetBatteryLow', this.onBatteryLowUpdate.bind(this), false);
21
- this.setup(HKCharacteristicKey.StatusActive, true, 'topicGetStatusActive', this.onStatusActiveUpdate.bind(this), false);
21
+ this.setup(HKCharacteristicKey.StatusLowBattery, dependency.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL, 'topicGetBatteryLow', this.bindOnUpdateBooleanSingle(HKCharacteristicKey.StatusLowBattery, 'valueBatteryLow', strings.accessory.batteryLow, strings.accessory.batteryNotLow, LogType.WARNING), false);
22
+ this.setup(HKCharacteristicKey.StatusActive, true, 'topicGetStatusActive', this.bindOnUpdateBooleanSingle(HKCharacteristicKey.StatusActive, 'valueStatusActive', strings.accessory.statusActive, strings.accessory.statusInactive, LogType.ALWAYS, LogType.WARNING), false);
22
23
  }
23
- async onBatteryLowUpdate(topic, value) {
24
- const batteryLow = value === this.getPrimitiveValue('valueBatteryLow') ? 1 : 0;
25
- if (!this.onUpdate(HKCharacteristicKey.StatusLowBattery, batteryLow)) {
26
- return;
27
- }
28
- if (batteryLow) {
29
- this.logIfDesired(LogType.WARNING, strings.accessory.batteryLow);
30
- }
31
- else {
32
- this.logIfDesired(strings.accessory.batteryNotLow);
33
- }
34
- }
35
- async onStatusActiveUpdate(topic, value) {
36
- const statusActive = value === this.getPrimitiveValue('valueStatusActive');
37
- if (!this.onUpdate(HKCharacteristicKey.StatusActive, statusActive)) {
38
- return;
39
- }
40
- if (statusActive) {
41
- this.logIfDesired(strings.accessory.statusActive);
42
- }
43
- else {
44
- this.logIfDesired(LogType.WARNING, strings.accessory.statusInactive);
45
- }
24
+ isOptionalCharacteristic(key) {
25
+ return super.isOptionalCharacteristic(key) || isOptionalHKCharacteristic(key, this.config.info.type);
46
26
  }
47
27
  }
48
28
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/accessory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AI,EAC/C,sBAAsB,EACtB,IAAI,CAAC,yBAAyB,CAAC,mBAAmB,CAAC,YAAY,EAAE,mBAAmB,EAClF,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,EACpG,KAAK,CAAC,CAAC;IACX,CAAC;IAEQ,wBAAwB,CAAC,GAAsB;QACtD,OAAO,KAAK,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvG,CAAC;CACF"}
@@ -10,6 +10,8 @@ export type TopicHandler = {
10
10
  handler: OnUpdateHandler;
11
11
  };
12
12
  export type PublishHandler = (topic: string, value: PrimitiveTypes) => void;
13
+ type NumberCallback = (value: number) => void;
14
+ type BooleanCallback = (value: boolean) => void;
13
15
  export declare abstract class Common<C extends Assertable> {
14
16
  readonly name: string;
15
17
  private _properties;
@@ -23,23 +25,32 @@ export declare abstract class Common<C extends Assertable> {
23
25
  protected abstract get identifier(): string;
24
26
  protected abstract get useStoredProperties(): boolean;
25
27
  protected abstract publish(rawTopic: string, value: PrimitiveTypes): void;
26
- protected get properties(): Properties;
28
+ get properties(): Properties;
27
29
  protected assert(...keys: (keyof C)[]): boolean;
28
30
  protected assertType(expectedType: Type, ...keys: (keyof C)[]): boolean;
29
31
  protected getRawValue(property: keyof C, assert?: boolean): string | undefined;
30
32
  protected getPrimitiveValue(property: keyof C, assert?: boolean): PrimitiveTypes | undefined;
31
33
  protected addTopicHandlers(topicHandlers: TopicHandler[]): void;
34
+ protected isOptionalCharacteristic(key: CharacteristicKey): boolean;
32
35
  protected setup(characteristicKey: CharacteristicKey, defaultValue: CharacteristicValue, getTopicKey: keyof C, onUpdateHandler: OnUpdateHandler, assertGetTopic: boolean, setTopicKey?: keyof C | undefined, onSetHandler?: CharacteristicSetHandler | undefined): Characteristic | undefined;
33
36
  private setupGet;
34
37
  protected setupSet(characteristicKey: CharacteristicKey, setTopicKey?: keyof C | undefined, onSetHandler?: CharacteristicSetHandler | undefined): void;
35
- protected bindOnUpdateNumeric(key: CharacteristicKey, logTemplate: string): OnUpdateHandler;
36
- protected bindOnUpdateBoolean(key: CharacteristicKey, positiveKey: keyof C, negativeKey: keyof C, logTrue: string, logFalse: string): OnUpdateHandler;
37
- protected bindOnUpdateNumericBoolean(charKey: CharacteristicKey, valueKey: keyof C, logTrue: string, logFalse: string): OnUpdateHandler;
38
- protected bindOnUpdateTemperature<C extends TemperatureConfig>(config: C, charKey: CharacteristicKey, logTemplate: string): OnUpdateHandler;
38
+ protected setupTopicless(characteristicKey: CharacteristicKey, defaultValue: CharacteristicValue, onSetCallback?: (value: CharacteristicValue) => (void)): Characteristic | undefined;
39
+ protected bindOnUpdateNumeric(key: CharacteristicKey, logTemplate: string, callback?: NumberCallback): OnUpdateHandler;
40
+ protected bindOnUpdateBoolean(key: CharacteristicKey, trueKey: keyof C, falseKey: keyof C, logTrue: string, logFalse: string, callback?: BooleanCallback): OnUpdateHandler;
41
+ protected bindOnUpdateBooleanSingle(key: CharacteristicKey, valueKey: keyof C, trueLog: string, falseLog: string, trueLogType?: LogType, falseLogType?: LogType): (_topic: string, value: PrimitiveTypes) => Promise<void>;
42
+ protected bindOnUpdateNumericBoolean(charKey: CharacteristicKey, valueKey: keyof C, logTrue: string, logFalse: string, callback?: NumberCallback): OnUpdateHandler;
43
+ protected bindOnUpdateTemperature<C extends TemperatureConfig>(config: C, charKey: CharacteristicKey, logTemplate: string, callback?: NumberCallback): OnUpdateHandler;
44
+ protected bindOnUpdateState(key: CharacteristicKey, states: Map<keyof C, CharacteristicValue>, strings: Map<CharacteristicValue, string>, unknownLog: string): (_topic: string, value: PrimitiveTypes) => Promise<void>;
45
+ private onSetNumeric;
39
46
  protected bindOnSetNumeric(key: CharacteristicKey, topic: keyof C, logTemplate: string): (value: CharacteristicValue) => Promise<void>;
40
- protected bindOnSetBoolean(key: CharacteristicKey, setTopicKey: keyof C, positiveKey: keyof C, negativeKey: keyof C, positiveValue: CharacteristicValue, positiveLogString: string, negativeLogString: string): (value: CharacteristicValue) => Promise<void>;
47
+ protected bindOnSetPercentOrValue(key: CharacteristicKey, topic: keyof C, maximum: number | undefined, logPercent: string, logValue: string): (value: CharacteristicValue) => Promise<void>;
48
+ protected bindOnSetBoolean(key: CharacteristicKey, setTopicKey: keyof C, trueValueKey: keyof C, falseValueKey: keyof C, trueValue: CharacteristicValue, trueLog: string, falseLog: string, callback?: BooleanCallback): (value: CharacteristicValue) => Promise<void>;
49
+ protected bindOnSetState(key: CharacteristicKey, setTopicKey: keyof C, states: Map<keyof C, CharacteristicValue>, strings: Map<CharacteristicValue, string>, badValueLog: string): (value: CharacteristicValue) => Promise<void>;
41
50
  protected onUpdate(key: CharacteristicKey, value: CharacteristicValue, logString?: string | undefined): boolean;
42
51
  protected onSet(key: CharacteristicKey, value: CharacteristicValue, publish: PrimitiveTypes, topic: keyof C, logString: string | undefined): void;
52
+ protected updateNumericValue(key: CharacteristicKey, delta: number): void;
53
+ protected characteristicFromKey(key: CharacteristicKey): any;
43
54
  protected logIfDesired(message: string, ...parameters: string[]): void;
44
55
  protected logIfDesired(level: LogType, message: string, ...parameters: string[]): void;
45
56
  }