@digital-alchemy/core 0.1.0

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 (303) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/automation/automation.module.d.ts +61 -0
  4. package/dist/automation/automation.module.js +70 -0
  5. package/dist/automation/automation.module.js.map +1 -0
  6. package/dist/automation/extensions/aggressive-scenes.extension.d.ts +22 -0
  7. package/dist/automation/extensions/aggressive-scenes.extension.js +125 -0
  8. package/dist/automation/extensions/aggressive-scenes.extension.js.map +1 -0
  9. package/dist/automation/extensions/circadian.extension.d.ts +11 -0
  10. package/dist/automation/extensions/circadian.extension.js +87 -0
  11. package/dist/automation/extensions/circadian.extension.js.map +1 -0
  12. package/dist/automation/extensions/index.d.ts +7 -0
  13. package/dist/automation/extensions/index.js +11 -0
  14. package/dist/automation/extensions/index.js.map +1 -0
  15. package/dist/automation/extensions/light-manager.extension.d.ts +26 -0
  16. package/dist/automation/extensions/light-manager.extension.js +260 -0
  17. package/dist/automation/extensions/light-manager.extension.js.map +1 -0
  18. package/dist/automation/extensions/managed-switch.extension.d.ts +3 -0
  19. package/dist/automation/extensions/managed-switch.extension.js +73 -0
  20. package/dist/automation/extensions/managed-switch.extension.js.map +1 -0
  21. package/dist/automation/extensions/room.extension.d.ts +11 -0
  22. package/dist/automation/extensions/room.extension.js +179 -0
  23. package/dist/automation/extensions/room.extension.js.map +1 -0
  24. package/dist/automation/extensions/sequence-matcher.extension.d.ts +3 -0
  25. package/dist/automation/extensions/sequence-matcher.extension.js +126 -0
  26. package/dist/automation/extensions/sequence-matcher.extension.js.map +1 -0
  27. package/dist/automation/extensions/solar-calc.extension.d.ts +20 -0
  28. package/dist/automation/extensions/solar-calc.extension.js +105 -0
  29. package/dist/automation/extensions/solar-calc.extension.js.map +1 -0
  30. package/dist/automation/helpers/events.helper.d.ts +33 -0
  31. package/dist/automation/helpers/events.helper.js +14 -0
  32. package/dist/automation/helpers/events.helper.js.map +1 -0
  33. package/dist/automation/helpers/index.d.ts +7 -0
  34. package/dist/automation/helpers/index.js +11 -0
  35. package/dist/automation/helpers/index.js.map +1 -0
  36. package/dist/automation/helpers/managed-switch.helper.d.ts +41 -0
  37. package/dist/automation/helpers/managed-switch.helper.js +3 -0
  38. package/dist/automation/helpers/managed-switch.helper.js.map +1 -0
  39. package/dist/automation/helpers/metrics.helper.d.ts +13 -0
  40. package/dist/automation/helpers/metrics.helper.js +30 -0
  41. package/dist/automation/helpers/metrics.helper.js.map +1 -0
  42. package/dist/automation/helpers/reftimes.helper.d.ts +54 -0
  43. package/dist/automation/helpers/reftimes.helper.js +33 -0
  44. package/dist/automation/helpers/reftimes.helper.js.map +1 -0
  45. package/dist/automation/helpers/scene.helper.d.ts +97 -0
  46. package/dist/automation/helpers/scene.helper.js +5 -0
  47. package/dist/automation/helpers/scene.helper.js.map +1 -0
  48. package/dist/automation/helpers/sequence.helper.d.ts +55 -0
  49. package/dist/automation/helpers/sequence.helper.js +3 -0
  50. package/dist/automation/helpers/sequence.helper.js.map +1 -0
  51. package/dist/automation/helpers/solar.helper.d.ts +3 -0
  52. package/dist/automation/helpers/solar.helper.js +262 -0
  53. package/dist/automation/helpers/solar.helper.js.map +1 -0
  54. package/dist/automation/index.d.ts +3 -0
  55. package/dist/automation/index.js +10 -0
  56. package/dist/automation/index.js.map +1 -0
  57. package/dist/boilerplate/extensions/cache.extension.d.ts +24 -0
  58. package/dist/boilerplate/extensions/cache.extension.js +96 -0
  59. package/dist/boilerplate/extensions/cache.extension.js.map +1 -0
  60. package/dist/boilerplate/extensions/configuration.extension.d.ts +23 -0
  61. package/dist/boilerplate/extensions/configuration.extension.js +98 -0
  62. package/dist/boilerplate/extensions/configuration.extension.js.map +1 -0
  63. package/dist/boilerplate/extensions/fetch.extension.d.ts +20 -0
  64. package/dist/boilerplate/extensions/fetch.extension.js +154 -0
  65. package/dist/boilerplate/extensions/fetch.extension.js.map +1 -0
  66. package/dist/boilerplate/extensions/index.d.ts +6 -0
  67. package/dist/boilerplate/extensions/index.js +10 -0
  68. package/dist/boilerplate/extensions/index.js.map +1 -0
  69. package/dist/boilerplate/extensions/logger.extension.d.ts +39 -0
  70. package/dist/boilerplate/extensions/logger.extension.js +159 -0
  71. package/dist/boilerplate/extensions/logger.extension.js.map +1 -0
  72. package/dist/boilerplate/extensions/scheduler.extension.d.ts +21 -0
  73. package/dist/boilerplate/extensions/scheduler.extension.js +117 -0
  74. package/dist/boilerplate/extensions/scheduler.extension.js.map +1 -0
  75. package/dist/boilerplate/extensions/wiring.extension.d.ts +101 -0
  76. package/dist/boilerplate/extensions/wiring.extension.js +452 -0
  77. package/dist/boilerplate/extensions/wiring.extension.js.map +1 -0
  78. package/dist/boilerplate/helpers/cache-memory.helper.d.ts +7 -0
  79. package/dist/boilerplate/helpers/cache-memory.helper.js +65 -0
  80. package/dist/boilerplate/helpers/cache-memory.helper.js.map +1 -0
  81. package/dist/boilerplate/helpers/cache-redis.helper.d.ts +7 -0
  82. package/dist/boilerplate/helpers/cache-redis.helper.js +69 -0
  83. package/dist/boilerplate/helpers/cache-redis.helper.js.map +1 -0
  84. package/dist/boilerplate/helpers/config-environment-loader.helper.d.ts +2 -0
  85. package/dist/boilerplate/helpers/config-environment-loader.helper.js +56 -0
  86. package/dist/boilerplate/helpers/config-environment-loader.helper.js.map +1 -0
  87. package/dist/boilerplate/helpers/config-file-loader.helper.d.ts +4 -0
  88. package/dist/boilerplate/helpers/config-file-loader.helper.js +87 -0
  89. package/dist/boilerplate/helpers/config-file-loader.helper.js.map +1 -0
  90. package/dist/boilerplate/helpers/config.helper.d.ts +102 -0
  91. package/dist/boilerplate/helpers/config.helper.js +32 -0
  92. package/dist/boilerplate/helpers/config.helper.js.map +1 -0
  93. package/dist/boilerplate/helpers/errors.helper.d.ts +39 -0
  94. package/dist/boilerplate/helpers/errors.helper.js +76 -0
  95. package/dist/boilerplate/helpers/errors.helper.js.map +1 -0
  96. package/dist/boilerplate/helpers/events.helper.d.ts +3 -0
  97. package/dist/boilerplate/helpers/events.helper.js +11 -0
  98. package/dist/boilerplate/helpers/events.helper.js.map +1 -0
  99. package/dist/boilerplate/helpers/fetch.helper.d.ts +170 -0
  100. package/dist/boilerplate/helpers/fetch.helper.js +173 -0
  101. package/dist/boilerplate/helpers/fetch.helper.js.map +1 -0
  102. package/dist/boilerplate/helpers/index.d.ts +12 -0
  103. package/dist/boilerplate/helpers/index.js +16 -0
  104. package/dist/boilerplate/helpers/index.js.map +1 -0
  105. package/dist/boilerplate/helpers/lifecycle.helper.d.ts +43 -0
  106. package/dist/boilerplate/helpers/lifecycle.helper.js +13 -0
  107. package/dist/boilerplate/helpers/lifecycle.helper.js.map +1 -0
  108. package/dist/boilerplate/helpers/metrics.helper.d.ts +73 -0
  109. package/dist/boilerplate/helpers/metrics.helper.js +141 -0
  110. package/dist/boilerplate/helpers/metrics.helper.js.map +1 -0
  111. package/dist/boilerplate/helpers/testing.helper.d.ts +13 -0
  112. package/dist/boilerplate/helpers/testing.helper.js +91 -0
  113. package/dist/boilerplate/helpers/testing.helper.js.map +1 -0
  114. package/dist/boilerplate/helpers/wiring.helper.d.ts +155 -0
  115. package/dist/boilerplate/helpers/wiring.helper.js +5 -0
  116. package/dist/boilerplate/helpers/wiring.helper.js.map +1 -0
  117. package/dist/boilerplate/index.d.ts +2 -0
  118. package/dist/boilerplate/index.js +6 -0
  119. package/dist/boilerplate/index.js.map +1 -0
  120. package/dist/gotify/extensions/application.extension.d.ts +13 -0
  121. package/dist/gotify/extensions/application.extension.js +52 -0
  122. package/dist/gotify/extensions/application.extension.js.map +1 -0
  123. package/dist/gotify/extensions/client.extension.d.ts +8 -0
  124. package/dist/gotify/extensions/client.extension.js +38 -0
  125. package/dist/gotify/extensions/client.extension.js.map +1 -0
  126. package/dist/gotify/extensions/fetch.extension.d.ts +2 -0
  127. package/dist/gotify/extensions/fetch.extension.js +14 -0
  128. package/dist/gotify/extensions/fetch.extension.js.map +1 -0
  129. package/dist/gotify/extensions/index.d.ts +4 -0
  130. package/dist/gotify/extensions/index.js +8 -0
  131. package/dist/gotify/extensions/index.js.map +1 -0
  132. package/dist/gotify/extensions/message.extension.d.ts +8 -0
  133. package/dist/gotify/extensions/message.extension.js +37 -0
  134. package/dist/gotify/extensions/message.extension.js.map +1 -0
  135. package/dist/gotify/gotify.module.d.ts +29 -0
  136. package/dist/gotify/gotify.module.js +33 -0
  137. package/dist/gotify/gotify.module.js.map +1 -0
  138. package/dist/gotify/helpers/api.d.ts +346 -0
  139. package/dist/gotify/helpers/api.js +14 -0
  140. package/dist/gotify/helpers/api.js.map +1 -0
  141. package/dist/gotify/helpers/events.helper.d.ts +6 -0
  142. package/dist/gotify/helpers/events.helper.js +5 -0
  143. package/dist/gotify/helpers/events.helper.js.map +1 -0
  144. package/dist/gotify/helpers/index.d.ts +2 -0
  145. package/dist/gotify/helpers/index.js +6 -0
  146. package/dist/gotify/helpers/index.js.map +1 -0
  147. package/dist/gotify/index.d.ts +3 -0
  148. package/dist/gotify/index.js +7 -0
  149. package/dist/gotify/index.js.map +1 -0
  150. package/dist/hass/dynamic.d.ts +1126 -0
  151. package/dist/hass/dynamic.js +153 -0
  152. package/dist/hass/dynamic.js.map +1 -0
  153. package/dist/hass/extensions/call-proxy.extension.d.ts +4 -0
  154. package/dist/hass/extensions/call-proxy.extension.js +88 -0
  155. package/dist/hass/extensions/call-proxy.extension.js.map +1 -0
  156. package/dist/hass/extensions/entity-manager.extension.d.ts +61 -0
  157. package/dist/hass/extensions/entity-manager.extension.js +214 -0
  158. package/dist/hass/extensions/entity-manager.extension.js.map +1 -0
  159. package/dist/hass/extensions/fetch-api.extension.d.ts +26 -0
  160. package/dist/hass/extensions/fetch-api.extension.js +166 -0
  161. package/dist/hass/extensions/fetch-api.extension.js.map +1 -0
  162. package/dist/hass/extensions/index.d.ts +5 -0
  163. package/dist/hass/extensions/index.js +9 -0
  164. package/dist/hass/extensions/index.js.map +1 -0
  165. package/dist/hass/extensions/utilities.extension.d.ts +9 -0
  166. package/dist/hass/extensions/utilities.extension.js +43 -0
  167. package/dist/hass/extensions/utilities.extension.js.map +1 -0
  168. package/dist/hass/extensions/websocket-api.extension.d.ts +39 -0
  169. package/dist/hass/extensions/websocket-api.extension.js +363 -0
  170. package/dist/hass/extensions/websocket-api.extension.js.map +1 -0
  171. package/dist/hass/hass.module.d.ts +53 -0
  172. package/dist/hass/hass.module.js +59 -0
  173. package/dist/hass/hass.module.js.map +1 -0
  174. package/dist/hass/helpers/backup.helper.d.ts +11 -0
  175. package/dist/hass/helpers/backup.helper.js +3 -0
  176. package/dist/hass/helpers/backup.helper.js.map +1 -0
  177. package/dist/hass/helpers/constants.helper.d.ts +54 -0
  178. package/dist/hass/helpers/constants.helper.js +63 -0
  179. package/dist/hass/helpers/constants.helper.js.map +1 -0
  180. package/dist/hass/helpers/entity-state.helper.d.ts +45 -0
  181. package/dist/hass/helpers/entity-state.helper.js +9 -0
  182. package/dist/hass/helpers/entity-state.helper.js.map +1 -0
  183. package/dist/hass/helpers/fetch/calendar.d.ts +54 -0
  184. package/dist/hass/helpers/fetch/calendar.js +3 -0
  185. package/dist/hass/helpers/fetch/calendar.js.map +1 -0
  186. package/dist/hass/helpers/fetch/configuration.d.ts +34 -0
  187. package/dist/hass/helpers/fetch/configuration.js +3 -0
  188. package/dist/hass/helpers/fetch/configuration.js.map +1 -0
  189. package/dist/hass/helpers/fetch/index.d.ts +4 -0
  190. package/dist/hass/helpers/fetch/index.js +8 -0
  191. package/dist/hass/helpers/fetch/index.js.map +1 -0
  192. package/dist/hass/helpers/fetch/server-log.d.ts +10 -0
  193. package/dist/hass/helpers/fetch/server-log.js +20 -0
  194. package/dist/hass/helpers/fetch/server-log.js.map +1 -0
  195. package/dist/hass/helpers/fetch/service-list.d.ts +51 -0
  196. package/dist/hass/helpers/fetch/service-list.js +3 -0
  197. package/dist/hass/helpers/fetch/service-list.js.map +1 -0
  198. package/dist/hass/helpers/index.d.ts +7 -0
  199. package/dist/hass/helpers/index.js +11 -0
  200. package/dist/hass/helpers/index.js.map +1 -0
  201. package/dist/hass/helpers/metrics.helper.d.ts +13 -0
  202. package/dist/hass/helpers/metrics.helper.js +30 -0
  203. package/dist/hass/helpers/metrics.helper.js.map +1 -0
  204. package/dist/hass/helpers/utility.helper.d.ts +57 -0
  205. package/dist/hass/helpers/utility.helper.js +34 -0
  206. package/dist/hass/helpers/utility.helper.js.map +1 -0
  207. package/dist/hass/helpers/websocket.helper.d.ts +129 -0
  208. package/dist/hass/helpers/websocket.helper.js +3 -0
  209. package/dist/hass/helpers/websocket.helper.js.map +1 -0
  210. package/dist/hass/index.d.ts +4 -0
  211. package/dist/hass/index.js +8 -0
  212. package/dist/hass/index.js.map +1 -0
  213. package/dist/index.d.ts +2 -0
  214. package/dist/index.js +8 -0
  215. package/dist/index.js.map +1 -0
  216. package/dist/nexus/entities.extension.d.ts +2 -0
  217. package/dist/nexus/entities.extension.js +51 -0
  218. package/dist/nexus/entities.extension.js.map +1 -0
  219. package/dist/nexus/main.d.ts +9 -0
  220. package/dist/nexus/main.js +28 -0
  221. package/dist/nexus/main.js.map +1 -0
  222. package/dist/synapse/extensions/binary-sensor.extension.d.ts +19 -0
  223. package/dist/synapse/extensions/binary-sensor.extension.js +84 -0
  224. package/dist/synapse/extensions/binary-sensor.extension.js.map +1 -0
  225. package/dist/synapse/extensions/button.extension.d.ts +10 -0
  226. package/dist/synapse/extensions/button.extension.js +46 -0
  227. package/dist/synapse/extensions/button.extension.js.map +1 -0
  228. package/dist/synapse/extensions/index.d.ts +6 -0
  229. package/dist/synapse/extensions/index.js +10 -0
  230. package/dist/synapse/extensions/index.js.map +1 -0
  231. package/dist/synapse/extensions/registry.extension.d.ts +21 -0
  232. package/dist/synapse/extensions/registry.extension.js +207 -0
  233. package/dist/synapse/extensions/registry.extension.js.map +1 -0
  234. package/dist/synapse/extensions/scene.extension.d.ts +9 -0
  235. package/dist/synapse/extensions/scene.extension.js +37 -0
  236. package/dist/synapse/extensions/scene.extension.js.map +1 -0
  237. package/dist/synapse/extensions/sensor.extension.d.ts +25 -0
  238. package/dist/synapse/extensions/sensor.extension.js +154 -0
  239. package/dist/synapse/extensions/sensor.extension.js.map +1 -0
  240. package/dist/synapse/extensions/switch.extension.d.ts +19 -0
  241. package/dist/synapse/extensions/switch.extension.js +95 -0
  242. package/dist/synapse/extensions/switch.extension.js.map +1 -0
  243. package/dist/synapse/helpers/device-class.helper.d.ts +323 -0
  244. package/dist/synapse/helpers/device-class.helper.js +241 -0
  245. package/dist/synapse/helpers/device-class.helper.js.map +1 -0
  246. package/dist/synapse/helpers/index.d.ts +3 -0
  247. package/dist/synapse/helpers/index.js +7 -0
  248. package/dist/synapse/helpers/index.js.map +1 -0
  249. package/dist/synapse/helpers/metrics.helper.d.ts +13 -0
  250. package/dist/synapse/helpers/metrics.helper.js +30 -0
  251. package/dist/synapse/helpers/metrics.helper.js.map +1 -0
  252. package/dist/synapse/helpers/utility.helper.d.ts +1 -0
  253. package/dist/synapse/helpers/utility.helper.js +3 -0
  254. package/dist/synapse/helpers/utility.helper.js.map +1 -0
  255. package/dist/synapse/index.d.ts +3 -0
  256. package/dist/synapse/index.js +7 -0
  257. package/dist/synapse/index.js.map +1 -0
  258. package/dist/synapse/synapse.module.d.ts +29 -0
  259. package/dist/synapse/synapse.module.js +41 -0
  260. package/dist/synapse/synapse.module.js.map +1 -0
  261. package/dist/type-writer/build.extension.d.ts +2 -0
  262. package/dist/type-writer/build.extension.js +53 -0
  263. package/dist/type-writer/build.extension.js.map +1 -0
  264. package/dist/type-writer/main.d.ts +17 -0
  265. package/dist/type-writer/main.js +36 -0
  266. package/dist/type-writer/main.js.map +1 -0
  267. package/dist/type-writer/type-writer.extension.d.ts +2 -0
  268. package/dist/type-writer/type-writer.extension.js +212 -0
  269. package/dist/type-writer/type-writer.extension.js.map +1 -0
  270. package/dist/utilities/extensions/index.d.ts +3 -0
  271. package/dist/utilities/extensions/index.js +7 -0
  272. package/dist/utilities/extensions/index.js.map +1 -0
  273. package/dist/utilities/extensions/is.extension.d.ts +38 -0
  274. package/dist/utilities/extensions/is.extension.js +104 -0
  275. package/dist/utilities/extensions/is.extension.js.map +1 -0
  276. package/dist/utilities/extensions/zcc-testing.extension.d.ts +4 -0
  277. package/dist/utilities/extensions/zcc-testing.extension.js +9 -0
  278. package/dist/utilities/extensions/zcc-testing.extension.js.map +1 -0
  279. package/dist/utilities/extensions/zcc.extension.d.ts +20 -0
  280. package/dist/utilities/extensions/zcc.extension.js +66 -0
  281. package/dist/utilities/extensions/zcc.extension.js.map +1 -0
  282. package/dist/utilities/helpers/async.helper.d.ts +2 -0
  283. package/dist/utilities/helpers/async.helper.js +26 -0
  284. package/dist/utilities/helpers/async.helper.js.map +1 -0
  285. package/dist/utilities/helpers/context.helper.d.ts +7 -0
  286. package/dist/utilities/helpers/context.helper.js +3 -0
  287. package/dist/utilities/helpers/context.helper.js.map +1 -0
  288. package/dist/utilities/helpers/cron.helper.d.ts +87 -0
  289. package/dist/utilities/helpers/cron.helper.js +92 -0
  290. package/dist/utilities/helpers/cron.helper.js.map +1 -0
  291. package/dist/utilities/helpers/extend.helper.d.ts +2 -0
  292. package/dist/utilities/helpers/extend.helper.js +68 -0
  293. package/dist/utilities/helpers/extend.helper.js.map +1 -0
  294. package/dist/utilities/helpers/index.d.ts +5 -0
  295. package/dist/utilities/helpers/index.js +9 -0
  296. package/dist/utilities/helpers/index.js.map +1 -0
  297. package/dist/utilities/helpers/utilities.helper.d.ts +63 -0
  298. package/dist/utilities/helpers/utilities.helper.js +93 -0
  299. package/dist/utilities/helpers/utilities.helper.js.map +1 -0
  300. package/dist/utilities/index.d.ts +2 -0
  301. package/dist/utilities/index.js +6 -0
  302. package/dist/utilities/index.js.map +1 -0
  303. package/package.json +101 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 zoe-codez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Digital Alchemy core 🌟
2
+
3
+ ## Introduction
4
+
5
+ `@digital-alchemy`: A TypeScript framework designed for Home Assistant, enabling dynamic entity management, service calls, and automation with minimal dependencies.
6
+
7
+ ## 📦 Major Exports
8
+
9
+ `@digital-alchemy` framework is built on key exports, each offering unique features that complement one another:
10
+
11
+ - **@digital-alchemy/core (Base Framework):** Provides caching, logging, configuration, lifecycle events, and utility types.
12
+
13
+ - **@digital-alchemy/core/hass:** Facilitates base interactions with Home Assistant, including websocket connection management, entity reference checking, and a service call interface.
14
+
15
+ - **@digital-alchemy/core/synapse:** Enables the generation of new entities in Home Assistant, such as buttons, sensors, and switches. Requires a socket connection and a custom component installation.
16
+
17
+ - **@digital-alchemy/core/automation:** Focuses on home automation logic, offering room-based scene coordination, active state management for switches, circadian lighting, and more.
18
+
19
+ - **type-writer (CLI Tool):** A helper script that customizes internal type definitions by connecting to your Home Assistant instance and generating accurate service & entity validations.
20
+
21
+ ## 🛠 Installation
22
+
23
+ ### Synapse Integration
24
+
25
+ The Synapse component is essential for creating and managing entities within Home Assistant. Visit the [Synapse Repo](https://github.com/zoe-codez/synapse) for installation instructions and to understand its importance in your setup.
26
+
27
+ ## 📚 External Libraries and Examples
28
+
29
+ Explore the full potential of `@digital-alchemy/core` with our extensions library and illustrative examples. These resources are designed to expand the framework's functionality and provide inspiration for your projects:
30
+
31
+ ### 📚 Extensions Library
32
+
33
+ Enhance your home automation capabilities with the [Digital Alchemy Extensions Library](https://github.com/digital-alchemy-extensions), which includes:
34
+
35
+ - **MQTT Bindings:** Seamlessly integrate MQTT protocols for broader IoT connectivity.
36
+ - **Fastify Bindings:** Leverage Fastify to add efficient HTTP server functionality to your automation projects.
37
+
38
+ ### 🎓 Demo and Example Repositories
39
+
40
+ Kickstart your development with these practical applications:
41
+
42
+ - **Mock Home:** A comprehensive sandbox for experimenting with and showcasing various automation techniques. [Mock Home on GitHub](https://github.com/zoe-codez/mock-home)
43
+ - **Automation Template:** A starter template to quickly get your projects up and running. [Automation Template on GitHub](https://github.com/zoe-codez/automation-template)
44
+
45
+ ## 🤝 Contribution
46
+
47
+ We warmly welcome contributions. Whether you're enhancing the framework, sharing examples, or enriching documentation, your efforts significantly benefit the community.
@@ -0,0 +1,61 @@
1
+ import { AggressiveScenes, CircadianLighting, LightManager, ManagedSwitch, Room, SequenceWatcher, SolarCalculator } from "./extensions";
2
+ export declare const LIB_AUTOMATION: import("../boilerplate").LibraryDefinition<{
3
+ aggressive: typeof AggressiveScenes;
4
+ circadian: typeof CircadianLighting;
5
+ light: typeof LightManager;
6
+ managed_switch: typeof ManagedSwitch;
7
+ room: typeof Room;
8
+ sequence: typeof SequenceWatcher;
9
+ solar: typeof SolarCalculator;
10
+ }, {
11
+ AGGRESSIVE_SCENES: {
12
+ default: true;
13
+ description: string;
14
+ type: "boolean";
15
+ };
16
+ CIRCADIAN_DIFF_THRESHOLD: {
17
+ default: number;
18
+ description: string;
19
+ type: "number";
20
+ };
21
+ CIRCADIAN_ENABLED: {
22
+ default: true;
23
+ description: string;
24
+ type: "boolean";
25
+ };
26
+ CIRCADIAN_MAX_TEMP: {
27
+ default: number;
28
+ description: string;
29
+ type: "number";
30
+ };
31
+ CIRCADIAN_MIN_TEMP: {
32
+ default: number;
33
+ description: string;
34
+ type: "number";
35
+ };
36
+ CIRCADIAN_RATE: {
37
+ default: number;
38
+ description: string[];
39
+ type: "number";
40
+ };
41
+ CIRCADIAN_SENSOR_NAME: {
42
+ default: string;
43
+ description: string;
44
+ type: "string";
45
+ };
46
+ CIRCADIAN_THROTTLE: {
47
+ default: number;
48
+ description: string;
49
+ type: "number";
50
+ };
51
+ SEQUENCE_TIMEOUT: {
52
+ default: number;
53
+ description: string;
54
+ type: "number";
55
+ };
56
+ }>;
57
+ declare module "../boilerplate" {
58
+ interface LoadedModules {
59
+ automation: typeof LIB_AUTOMATION;
60
+ }
61
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIB_AUTOMATION = void 0;
4
+ const boilerplate_1 = require("../boilerplate");
5
+ const extensions_1 = require("./extensions");
6
+ exports.LIB_AUTOMATION = (0, boilerplate_1.CreateLibrary)({
7
+ configuration: {
8
+ AGGRESSIVE_SCENES: {
9
+ default: true,
10
+ description: "Verify continue to match their desired state as defined by the room's current scene",
11
+ type: "boolean",
12
+ },
13
+ CIRCADIAN_DIFF_THRESHOLD: {
14
+ default: 50,
15
+ description: "Current light temperature must be at least this much off target in order to be eligible for adjustment",
16
+ type: "number",
17
+ },
18
+ CIRCADIAN_ENABLED: {
19
+ default: true,
20
+ description: "Take responsibility for generating [CIRCADIAN_SENSOR] and emitting updates",
21
+ type: "boolean",
22
+ },
23
+ CIRCADIAN_MAX_TEMP: {
24
+ default: 5500,
25
+ description: "Maximum color temperature for circadian lighting. Used at solar noon",
26
+ type: "number",
27
+ },
28
+ CIRCADIAN_MIN_TEMP: {
29
+ default: 2000,
30
+ description: "Minimum color temperature for circadian lighting. Used while it's dark out",
31
+ type: "number",
32
+ },
33
+ CIRCADIAN_RATE: {
34
+ default: 3,
35
+ description: [
36
+ "Number of entities to adjust at the same time",
37
+ "Higher values increase load",
38
+ ],
39
+ type: "number",
40
+ },
41
+ CIRCADIAN_SENSOR_NAME: {
42
+ default: "Light temperature",
43
+ description: "Sensor for reading / writing current light temperature to",
44
+ type: "string",
45
+ },
46
+ CIRCADIAN_THROTTLE: {
47
+ default: 300,
48
+ description: "Artificial delay to add",
49
+ type: "number",
50
+ },
51
+ SEQUENCE_TIMEOUT: {
52
+ default: 1500,
53
+ description: "When tracking state changes for a sequence event, another change must happen inside this time window",
54
+ type: "number",
55
+ },
56
+ },
57
+ name: "automation",
58
+ // light depends circadian
59
+ priorityInit: ["circadian"],
60
+ services: {
61
+ aggressive: extensions_1.AggressiveScenes,
62
+ circadian: extensions_1.CircadianLighting,
63
+ light: extensions_1.LightManager,
64
+ managed_switch: extensions_1.ManagedSwitch,
65
+ room: extensions_1.Room,
66
+ sequence: extensions_1.SequenceWatcher,
67
+ solar: extensions_1.SolarCalculator,
68
+ },
69
+ });
70
+ //# sourceMappingURL=automation.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation.module.js","sourceRoot":"","sources":["../../src/automation/automation.module.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAC/C,6CAQsB;AAET,QAAA,cAAc,GAAG,IAAA,2BAAa,EAAC;IAC1C,aAAa,EAAE;QACb,iBAAiB,EAAE;YACjB,OAAO,EAAE,IAAI;YACb,WAAW,EACT,qFAAqF;YACvF,IAAI,EAAE,SAAS;SAChB;QACD,wBAAwB,EAAE;YACxB,OAAO,EAAE,EAAE;YACX,WAAW,EACT,wGAAwG;YAC1G,IAAI,EAAE,QAAQ;SACf;QACD,iBAAiB,EAAE;YACjB,OAAO,EAAE,IAAI;YACb,WAAW,EACT,4EAA4E;YAC9E,IAAI,EAAE,SAAS;SAChB;QACD,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI;YACb,WAAW,EACT,sEAAsE;YACxE,IAAI,EAAE,QAAQ;SACf;QACD,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI;YACb,WAAW,EACT,4EAA4E;YAC9E,IAAI,EAAE,QAAQ;SACf;QACD,cAAc,EAAE;YACd,OAAO,EAAE,CAAC;YACV,WAAW,EAAE;gBACX,+CAA+C;gBAC/C,6BAA6B;aAC9B;YACD,IAAI,EAAE,QAAQ;SACf;QACD,qBAAqB,EAAE;YACrB,OAAO,EAAE,mBAAmB;YAC5B,WAAW,EAAE,2DAA2D;YACxE,IAAI,EAAE,QAAQ;SACf;QACD,kBAAkB,EAAE;YAClB,OAAO,EAAE,GAAG;YACZ,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,QAAQ;SACf;QACD,gBAAgB,EAAE;YAChB,OAAO,EAAE,IAAI;YACb,WAAW,EACT,sGAAsG;YACxG,IAAI,EAAE,QAAQ;SACf;KACF;IACD,IAAI,EAAE,YAAY;IAClB,0BAA0B;IAC1B,YAAY,EAAE,CAAC,WAAW,CAAC;IAC3B,QAAQ,EAAE;QACR,UAAU,EAAE,6BAAgB;QAC5B,SAAS,EAAE,8BAAiB;QAC5B,KAAK,EAAE,yBAAY;QACnB,cAAc,EAAE,0BAAa;QAC7B,IAAI,EAAE,iBAAI;QACV,QAAQ,EAAE,4BAAe;QACzB,KAAK,EAAE,4BAAe;KACvB;CACF,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { TContext, TServiceParams } from "../..";
2
+ import { RoomScene } from "../helpers";
3
+ type TValidateOptions = {
4
+ context: TContext;
5
+ room: string;
6
+ name: string;
7
+ scene: RoomScene;
8
+ };
9
+ /**
10
+ * # Aggressive Scenes extension
11
+ *
12
+ * Sets up opt-in functionality that allows for more active management of scene states inside the system
13
+ * It coordinates with rooms to know what the current state is, and periodically checks entities to ensure that are currently in the state that they are expected to be
14
+ *
15
+ * - Correct for changes made in the real world (humans turning on a switch that should be off at the moment)
16
+ * - Changing definitions of "correct" (like light colors for circadian lighting)
17
+ * - Entities that failed to change to the correct state when asked the first time
18
+ */
19
+ export declare function AggressiveScenes({ logger, config, hass, event, automation, }: TServiceParams): {
20
+ validateRoomScene: ({ scene, room, name, context, }: TValidateOptions) => Promise<void>;
21
+ };
22
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggressiveScenes = void 0;
4
+ const async_1 = require("async");
5
+ const __1 = require("../..");
6
+ const hass_1 = require("../../hass");
7
+ const helpers_1 = require("../helpers");
8
+ /**
9
+ * # Aggressive Scenes extension
10
+ *
11
+ * Sets up opt-in functionality that allows for more active management of scene states inside the system
12
+ * It coordinates with rooms to know what the current state is, and periodically checks entities to ensure that are currently in the state that they are expected to be
13
+ *
14
+ * - Correct for changes made in the real world (humans turning on a switch that should be off at the moment)
15
+ * - Changing definitions of "correct" (like light colors for circadian lighting)
16
+ * - Entities that failed to change to the correct state when asked the first time
17
+ */
18
+ function AggressiveScenes({ logger, config, hass, event, automation, }) {
19
+ // eslint-disable-next-line sonarjs/cognitive-complexity
20
+ async function manageSwitch(entity, scene) {
21
+ const entity_id = entity.entity_id;
22
+ const expected = scene[entity_id];
23
+ if (__1.is.empty(expected)) {
24
+ // ??
25
+ return;
26
+ }
27
+ if (entity.state === "unavailable") {
28
+ logger.warn({ name: entity_id }, `{unavailable} entity, cannot manage state`);
29
+ return;
30
+ }
31
+ let performedUpdate = false;
32
+ if (entity.state !== expected.state) {
33
+ await matchSwitchToScene(entity, expected);
34
+ performedUpdate = true;
35
+ }
36
+ if (performedUpdate) {
37
+ return;
38
+ }
39
+ if ("entity_id" in entity.attributes) {
40
+ // ? This is a group
41
+ const id = entity.attributes.entity_id;
42
+ if (__1.is.array(id) && !__1.is.empty(id)) {
43
+ await (0, async_1.each)(entity.attributes.entity_id, async (child_id) => {
44
+ const child = hass.entity.byId(child_id);
45
+ if (!child) {
46
+ logger.warn(`%s => %s child entity of group cannot be found`, entity_id, child_id);
47
+ return;
48
+ }
49
+ if (child.state === "unavailable") {
50
+ logger.warn({ name: child_id }, `{unavailable} entity, cannot manage state`);
51
+ return;
52
+ }
53
+ if (child.state !== expected.state) {
54
+ await matchSwitchToScene(child, expected);
55
+ }
56
+ });
57
+ }
58
+ }
59
+ }
60
+ async function matchSwitchToScene(entity, expected) {
61
+ const entity_id = entity.entity_id;
62
+ logger.debug({ name: entity_id, state: expected.state }, `changing state`);
63
+ event.emit(helpers_1.AGGRESSIVE_SCENES_ADJUSTMENT, {
64
+ entity_id,
65
+ type: "switch_on_off",
66
+ });
67
+ if (expected.state === "on") {
68
+ await hass.call.switch.turn_on({ entity_id });
69
+ return;
70
+ }
71
+ await hass.call.switch.turn_off({ entity_id });
72
+ }
73
+ /**
74
+ * This function should **NOT** emit logs on noop
75
+ *
76
+ * - errors
77
+ * - warnings
78
+ * - state changes
79
+ */
80
+ async function validateRoomScene({ scene, room, name, context, }) {
81
+ if (config.automation.AGGRESSIVE_SCENES === false ||
82
+ scene?.aggressive === false) {
83
+ // nothing to do
84
+ return;
85
+ }
86
+ if (!scene?.definition) {
87
+ logger.warn({ context, name, room, scene }, `cannot validate room scene`);
88
+ return;
89
+ }
90
+ if (!__1.is.object(scene.definition) || __1.is.empty(scene.definition)) {
91
+ // ? There currently is no use case for a scene with no entities in it
92
+ // Not technically an error though
93
+ logger.warn("no definition");
94
+ return;
95
+ }
96
+ const entities = Object.keys(scene.definition);
97
+ await (0, async_1.each)(entities, async (entity_id) => {
98
+ const entity = hass.entity.byId(entity_id);
99
+ if (!entity) {
100
+ // * Home assistant outright does not send an entity for this id
101
+ // The wrong id was probably input
102
+ //
103
+ // ? This is distinct from "unavailable" entities
104
+ logger.error({ name: entity_id }, `cannot find entity`);
105
+ return;
106
+ }
107
+ const entityDomain = (0, hass_1.domain)(entity_id);
108
+ switch (entityDomain) {
109
+ case "light":
110
+ await automation.light.manageLight(entity, scene.definition);
111
+ return;
112
+ case "switch":
113
+ await manageSwitch(entity, scene.definition);
114
+ return;
115
+ default:
116
+ logger.debug({ name: entityDomain }, `no actions set for domain`);
117
+ }
118
+ });
119
+ }
120
+ return {
121
+ validateRoomScene,
122
+ };
123
+ }
124
+ exports.AggressiveScenes = AggressiveScenes;
125
+ //# sourceMappingURL=aggressive-scenes.extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggressive-scenes.extension.js","sourceRoot":"","sources":["../../../src/automation/extensions/aggressive-scenes.extension.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,6BAAqD;AACrD,qCAA+D;AAC/D,wCAMoB;AASpB;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,UAAU,GACK;IACf,wDAAwD;IACxD,KAAK,UAAU,YAAY,CACzB,MAA2C,EAC3C,KAAsB;QAEtB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAkC,CAAC;QAC5D,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAqB,CAAC;QACtD,IAAI,MAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,KAAK;YACL,OAAO;QACT,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,KAAK,aAAa,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CACT,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,2CAA2C,CAC5C,CAAC;YACF,OAAO;QACT,CAAC;QACD,IAAI,eAAe,GAAG,KAAK,CAAC;QAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YACpC,MAAM,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC3C,eAAe,GAAG,IAAI,CAAC;QACzB,CAAC;QACD,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,WAAW,IAAI,MA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AAiD;gBACjD,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,oBAAoB,CAAC,CAAC;gBACxD,OAAO;YACT,CAAC;YACD,MAAM,YAAY,GAAG,IAAA,aAAM,EAAC,SAAS,CAAC,CAAC;YACvC,QAAQ,YAAY,EAAE,CAAC;gBACrB,KAAK,OAAO;oBACV,MAAM,UAAU,CAAC,KAAK,CAAC,WAAW,CAChC,MAA4C,EAC5C,KAAK,CAAC,UAAU,CACjB,CAAC;oBACF,OAAO;gBACT,KAAK,QAAQ;oBACX,MAAM,YAAY,CAChB,MAA6C,EAC7C,KAAK,CAAC,UAAU,CACjB,CAAC;oBACF,OAAO;gBACT;oBACE,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,2BAA2B,CAAC,CAAC;YACtE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAnJD,4CAmJC"}
@@ -0,0 +1,11 @@
1
+ import { TServiceParams } from "../../boilerplate";
2
+ /**
3
+ * # Circadian lighting
4
+ *
5
+ * Generate an entity to maintain the current color temperature target for lights
6
+ */
7
+ export declare function CircadianLighting({ logger, lifecycle, scheduler, synapse, automation, config, context, event, }: TServiceParams): {
8
+ circadianEntity: import("../../synapse").VirtualSensor<number, object>;
9
+ getKelvin: () => number;
10
+ updateKelvin: () => void;
11
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CircadianLighting = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
+ const utilities_1 = require("../../utilities");
7
+ const helpers_1 = require("../helpers");
8
+ const MIN = 0;
9
+ const MAX = 1;
10
+ /**
11
+ * # Circadian lighting
12
+ *
13
+ * Generate an entity to maintain the current color temperature target for lights
14
+ */
15
+ function CircadianLighting({ logger, lifecycle, scheduler, synapse, automation, config, context, event, }) {
16
+ let circadianEntity;
17
+ lifecycle.onPostConfig(() => {
18
+ if (!config.automation.CIRCADIAN_ENABLED) {
19
+ logger.info(`circadian disabled`);
20
+ return;
21
+ }
22
+ circadianEntity = synapse.sensor({
23
+ context,
24
+ device_class: "temperature",
25
+ icon: "mdi:sun-thermometer",
26
+ name: config.automation.CIRCADIAN_SENSOR_NAME,
27
+ unit_of_measurement: "K",
28
+ });
29
+ out.circadianEntity = circadianEntity;
30
+ scheduler.cron({
31
+ context,
32
+ exec: () => updateKelvin(),
33
+ schedule: utilities_1.CronExpression.EVERY_30_SECONDS,
34
+ });
35
+ });
36
+ event.on(helpers_1.LOCATION_UPDATED, () => updateKelvin());
37
+ function updateKelvin() {
38
+ if (!circadianEntity) {
39
+ return;
40
+ }
41
+ if (!automation.solar.loaded) {
42
+ logger.debug(`lat/long not loaded yet`);
43
+ return;
44
+ }
45
+ const offset = getColorOffset();
46
+ circadianEntity.state = Math.floor((config.automation.CIRCADIAN_MAX_TEMP -
47
+ config.automation.CIRCADIAN_MIN_TEMP) *
48
+ offset +
49
+ config.automation.CIRCADIAN_MIN_TEMP);
50
+ }
51
+ /**
52
+ * Returns 0 when it's dark out, increasing to 1 at solar noon
53
+ */
54
+ function getColorOffset() {
55
+ if (!circadianEntity) {
56
+ return MIN;
57
+ }
58
+ if (!automation.solar.loaded) {
59
+ logger.debug(`lat/long not loaded yet`);
60
+ return MIN;
61
+ }
62
+ const now = (0, dayjs_1.default)();
63
+ const { solarNoon, dawn, dusk } = automation.solar;
64
+ if (now.isBefore(dawn)) {
65
+ // After midnight, but before dawn
66
+ return MIN;
67
+ }
68
+ if (now.isBefore(solarNoon)) {
69
+ // After dawn, but before solar noon
70
+ return Math.abs(solarNoon.diff(now, "s") / solarNoon.diff(dawn, "s") - MAX);
71
+ }
72
+ if (now.isBefore(dusk)) {
73
+ // Afternoon, but before dusk
74
+ return Math.abs(solarNoon.diff(now, "s") / solarNoon.diff(dusk, "s") - MAX);
75
+ }
76
+ // Until midnight
77
+ return MIN;
78
+ }
79
+ const out = {
80
+ circadianEntity,
81
+ getKelvin: () => circadianEntity?.state,
82
+ updateKelvin,
83
+ };
84
+ return out;
85
+ }
86
+ exports.CircadianLighting = CircadianLighting;
87
+ //# sourceMappingURL=circadian.extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circadian.extension.js","sourceRoot":"","sources":["../../../src/automation/extensions/circadian.extension.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAG1B,+CAAiD;AACjD,wCAA8C;AAE9C,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,SAAS,EACT,SAAS,EACT,OAAO,EACP,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACU;IACf,IAAI,eAA0D,CAAC;IAE/D,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE;QAC1B,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;QACD,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;YAC/B,OAAO;YACP,YAAY,EAAE,aAAa;YAC3B,IAAI,EAAE,qBAAqB;YAC3B,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,qBAAqB;YAC7C,mBAAmB,EAAE,GAAG;SACzB,CAAC,CAAC;QACH,GAAG,CAAC,eAAe,GAAG,eAAe,CAAC;QAEtC,SAAS,CAAC,IAAI,CAAC;YACb,OAAO;YACP,IAAI,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE;YAC1B,QAAQ,EAAE,0BAAc,CAAC,gBAAgB;SAC1C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,EAAE,CAAC,0BAAgB,EAAE,GAAG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,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,6BAA6B;YAC7B,OAAO,IAAI,CAAC,GAAG,CACb,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,CAC3D,CAAC;QACJ,CAAC;QACD,iBAAiB;QACjB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,GAAG,GAAG;QACV,eAAe;QACf,SAAS,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE,KAAK;QACvC,YAAY;KACb,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC;AA5FD,8CA4FC"}
@@ -0,0 +1,7 @@
1
+ export * from "./aggressive-scenes.extension";
2
+ export * from "./circadian.extension";
3
+ export * from "./light-manager.extension";
4
+ export * from "./managed-switch.extension";
5
+ export * from "./room.extension";
6
+ export * from "./sequence-matcher.extension";
7
+ export * from "./solar-calc.extension";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./aggressive-scenes.extension"), exports);
5
+ tslib_1.__exportStar(require("./circadian.extension"), exports);
6
+ tslib_1.__exportStar(require("./light-manager.extension"), exports);
7
+ tslib_1.__exportStar(require("./managed-switch.extension"), exports);
8
+ tslib_1.__exportStar(require("./room.extension"), exports);
9
+ tslib_1.__exportStar(require("./sequence-matcher.extension"), exports);
10
+ tslib_1.__exportStar(require("./solar-calc.extension"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/automation/extensions/index.ts"],"names":[],"mappings":";;;AAAA,wEAA8C;AAC9C,gEAAsC;AACtC,oEAA0C;AAC1C,qEAA2C;AAC3C,2DAAiC;AACjC,uEAA6C;AAC7C,iEAAuC"}
@@ -0,0 +1,26 @@
1
+ import { TServiceParams } from "../../boilerplate";
2
+ import { ENTITY_STATE, GenericEntityDTO, PICK_ENTITY } from "../../hass";
3
+ import { RoomDefinition } from "..";
4
+ import { SceneDefinition } from "../helpers";
5
+ type ColorModes = "color_temp" | "xy" | "brightness";
6
+ export type ColorLight = GenericEntityDTO<{
7
+ brightness: number;
8
+ color_mode: ColorModes;
9
+ color_temp: number;
10
+ color_temp_kelvin: number;
11
+ entity_id?: PICK_ENTITY<"light">[];
12
+ hs_color: [h: number, s: number];
13
+ max_color_temp_kelvin: number;
14
+ max_mireds: number;
15
+ min_color_temp_kelvin: number;
16
+ min_mireds: number;
17
+ rgb_color: [number, number, number];
18
+ supported_color_modes: ColorModes[];
19
+ supported_features: number;
20
+ xy_color: [x: number, y: number];
21
+ }>;
22
+ export declare function LightManager({ logger, hass, scheduler, lifecycle, automation, config, context, }: TServiceParams): {
23
+ manageLight: (entity: ENTITY_STATE<PICK_ENTITY<"light">>, scene: SceneDefinition) => Promise<void>;
24
+ registerRoom: (room: RoomDefinition) => Set<RoomDefinition<string>>;
25
+ };
26
+ export {};