@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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/automation/automation.module.d.ts +61 -0
- package/dist/automation/automation.module.js +70 -0
- package/dist/automation/automation.module.js.map +1 -0
- package/dist/automation/extensions/aggressive-scenes.extension.d.ts +22 -0
- package/dist/automation/extensions/aggressive-scenes.extension.js +125 -0
- package/dist/automation/extensions/aggressive-scenes.extension.js.map +1 -0
- package/dist/automation/extensions/circadian.extension.d.ts +11 -0
- package/dist/automation/extensions/circadian.extension.js +87 -0
- package/dist/automation/extensions/circadian.extension.js.map +1 -0
- package/dist/automation/extensions/index.d.ts +7 -0
- package/dist/automation/extensions/index.js +11 -0
- package/dist/automation/extensions/index.js.map +1 -0
- package/dist/automation/extensions/light-manager.extension.d.ts +26 -0
- package/dist/automation/extensions/light-manager.extension.js +260 -0
- package/dist/automation/extensions/light-manager.extension.js.map +1 -0
- package/dist/automation/extensions/managed-switch.extension.d.ts +3 -0
- package/dist/automation/extensions/managed-switch.extension.js +73 -0
- package/dist/automation/extensions/managed-switch.extension.js.map +1 -0
- package/dist/automation/extensions/room.extension.d.ts +11 -0
- package/dist/automation/extensions/room.extension.js +179 -0
- package/dist/automation/extensions/room.extension.js.map +1 -0
- package/dist/automation/extensions/sequence-matcher.extension.d.ts +3 -0
- package/dist/automation/extensions/sequence-matcher.extension.js +126 -0
- package/dist/automation/extensions/sequence-matcher.extension.js.map +1 -0
- package/dist/automation/extensions/solar-calc.extension.d.ts +20 -0
- package/dist/automation/extensions/solar-calc.extension.js +105 -0
- package/dist/automation/extensions/solar-calc.extension.js.map +1 -0
- package/dist/automation/helpers/events.helper.d.ts +33 -0
- package/dist/automation/helpers/events.helper.js +14 -0
- package/dist/automation/helpers/events.helper.js.map +1 -0
- package/dist/automation/helpers/index.d.ts +7 -0
- package/dist/automation/helpers/index.js +11 -0
- package/dist/automation/helpers/index.js.map +1 -0
- package/dist/automation/helpers/managed-switch.helper.d.ts +41 -0
- package/dist/automation/helpers/managed-switch.helper.js +3 -0
- package/dist/automation/helpers/managed-switch.helper.js.map +1 -0
- package/dist/automation/helpers/metrics.helper.d.ts +13 -0
- package/dist/automation/helpers/metrics.helper.js +30 -0
- package/dist/automation/helpers/metrics.helper.js.map +1 -0
- package/dist/automation/helpers/reftimes.helper.d.ts +54 -0
- package/dist/automation/helpers/reftimes.helper.js +33 -0
- package/dist/automation/helpers/reftimes.helper.js.map +1 -0
- package/dist/automation/helpers/scene.helper.d.ts +97 -0
- package/dist/automation/helpers/scene.helper.js +5 -0
- package/dist/automation/helpers/scene.helper.js.map +1 -0
- package/dist/automation/helpers/sequence.helper.d.ts +55 -0
- package/dist/automation/helpers/sequence.helper.js +3 -0
- package/dist/automation/helpers/sequence.helper.js.map +1 -0
- package/dist/automation/helpers/solar.helper.d.ts +3 -0
- package/dist/automation/helpers/solar.helper.js +262 -0
- package/dist/automation/helpers/solar.helper.js.map +1 -0
- package/dist/automation/index.d.ts +3 -0
- package/dist/automation/index.js +10 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/boilerplate/extensions/cache.extension.d.ts +24 -0
- package/dist/boilerplate/extensions/cache.extension.js +96 -0
- package/dist/boilerplate/extensions/cache.extension.js.map +1 -0
- package/dist/boilerplate/extensions/configuration.extension.d.ts +23 -0
- package/dist/boilerplate/extensions/configuration.extension.js +98 -0
- package/dist/boilerplate/extensions/configuration.extension.js.map +1 -0
- package/dist/boilerplate/extensions/fetch.extension.d.ts +20 -0
- package/dist/boilerplate/extensions/fetch.extension.js +154 -0
- package/dist/boilerplate/extensions/fetch.extension.js.map +1 -0
- package/dist/boilerplate/extensions/index.d.ts +6 -0
- package/dist/boilerplate/extensions/index.js +10 -0
- package/dist/boilerplate/extensions/index.js.map +1 -0
- package/dist/boilerplate/extensions/logger.extension.d.ts +39 -0
- package/dist/boilerplate/extensions/logger.extension.js +159 -0
- package/dist/boilerplate/extensions/logger.extension.js.map +1 -0
- package/dist/boilerplate/extensions/scheduler.extension.d.ts +21 -0
- package/dist/boilerplate/extensions/scheduler.extension.js +117 -0
- package/dist/boilerplate/extensions/scheduler.extension.js.map +1 -0
- package/dist/boilerplate/extensions/wiring.extension.d.ts +101 -0
- package/dist/boilerplate/extensions/wiring.extension.js +452 -0
- package/dist/boilerplate/extensions/wiring.extension.js.map +1 -0
- package/dist/boilerplate/helpers/cache-memory.helper.d.ts +7 -0
- package/dist/boilerplate/helpers/cache-memory.helper.js +65 -0
- package/dist/boilerplate/helpers/cache-memory.helper.js.map +1 -0
- package/dist/boilerplate/helpers/cache-redis.helper.d.ts +7 -0
- package/dist/boilerplate/helpers/cache-redis.helper.js +69 -0
- package/dist/boilerplate/helpers/cache-redis.helper.js.map +1 -0
- package/dist/boilerplate/helpers/config-environment-loader.helper.d.ts +2 -0
- package/dist/boilerplate/helpers/config-environment-loader.helper.js +56 -0
- package/dist/boilerplate/helpers/config-environment-loader.helper.js.map +1 -0
- package/dist/boilerplate/helpers/config-file-loader.helper.d.ts +4 -0
- package/dist/boilerplate/helpers/config-file-loader.helper.js +87 -0
- package/dist/boilerplate/helpers/config-file-loader.helper.js.map +1 -0
- package/dist/boilerplate/helpers/config.helper.d.ts +102 -0
- package/dist/boilerplate/helpers/config.helper.js +32 -0
- package/dist/boilerplate/helpers/config.helper.js.map +1 -0
- package/dist/boilerplate/helpers/errors.helper.d.ts +39 -0
- package/dist/boilerplate/helpers/errors.helper.js +76 -0
- package/dist/boilerplate/helpers/errors.helper.js.map +1 -0
- package/dist/boilerplate/helpers/events.helper.d.ts +3 -0
- package/dist/boilerplate/helpers/events.helper.js +11 -0
- package/dist/boilerplate/helpers/events.helper.js.map +1 -0
- package/dist/boilerplate/helpers/fetch.helper.d.ts +170 -0
- package/dist/boilerplate/helpers/fetch.helper.js +173 -0
- package/dist/boilerplate/helpers/fetch.helper.js.map +1 -0
- package/dist/boilerplate/helpers/index.d.ts +12 -0
- package/dist/boilerplate/helpers/index.js +16 -0
- package/dist/boilerplate/helpers/index.js.map +1 -0
- package/dist/boilerplate/helpers/lifecycle.helper.d.ts +43 -0
- package/dist/boilerplate/helpers/lifecycle.helper.js +13 -0
- package/dist/boilerplate/helpers/lifecycle.helper.js.map +1 -0
- package/dist/boilerplate/helpers/metrics.helper.d.ts +73 -0
- package/dist/boilerplate/helpers/metrics.helper.js +141 -0
- package/dist/boilerplate/helpers/metrics.helper.js.map +1 -0
- package/dist/boilerplate/helpers/testing.helper.d.ts +13 -0
- package/dist/boilerplate/helpers/testing.helper.js +91 -0
- package/dist/boilerplate/helpers/testing.helper.js.map +1 -0
- package/dist/boilerplate/helpers/wiring.helper.d.ts +155 -0
- package/dist/boilerplate/helpers/wiring.helper.js +5 -0
- package/dist/boilerplate/helpers/wiring.helper.js.map +1 -0
- package/dist/boilerplate/index.d.ts +2 -0
- package/dist/boilerplate/index.js +6 -0
- package/dist/boilerplate/index.js.map +1 -0
- package/dist/gotify/extensions/application.extension.d.ts +13 -0
- package/dist/gotify/extensions/application.extension.js +52 -0
- package/dist/gotify/extensions/application.extension.js.map +1 -0
- package/dist/gotify/extensions/client.extension.d.ts +8 -0
- package/dist/gotify/extensions/client.extension.js +38 -0
- package/dist/gotify/extensions/client.extension.js.map +1 -0
- package/dist/gotify/extensions/fetch.extension.d.ts +2 -0
- package/dist/gotify/extensions/fetch.extension.js +14 -0
- package/dist/gotify/extensions/fetch.extension.js.map +1 -0
- package/dist/gotify/extensions/index.d.ts +4 -0
- package/dist/gotify/extensions/index.js +8 -0
- package/dist/gotify/extensions/index.js.map +1 -0
- package/dist/gotify/extensions/message.extension.d.ts +8 -0
- package/dist/gotify/extensions/message.extension.js +37 -0
- package/dist/gotify/extensions/message.extension.js.map +1 -0
- package/dist/gotify/gotify.module.d.ts +29 -0
- package/dist/gotify/gotify.module.js +33 -0
- package/dist/gotify/gotify.module.js.map +1 -0
- package/dist/gotify/helpers/api.d.ts +346 -0
- package/dist/gotify/helpers/api.js +14 -0
- package/dist/gotify/helpers/api.js.map +1 -0
- package/dist/gotify/helpers/events.helper.d.ts +6 -0
- package/dist/gotify/helpers/events.helper.js +5 -0
- package/dist/gotify/helpers/events.helper.js.map +1 -0
- package/dist/gotify/helpers/index.d.ts +2 -0
- package/dist/gotify/helpers/index.js +6 -0
- package/dist/gotify/helpers/index.js.map +1 -0
- package/dist/gotify/index.d.ts +3 -0
- package/dist/gotify/index.js +7 -0
- package/dist/gotify/index.js.map +1 -0
- package/dist/hass/dynamic.d.ts +1126 -0
- package/dist/hass/dynamic.js +153 -0
- package/dist/hass/dynamic.js.map +1 -0
- package/dist/hass/extensions/call-proxy.extension.d.ts +4 -0
- package/dist/hass/extensions/call-proxy.extension.js +88 -0
- package/dist/hass/extensions/call-proxy.extension.js.map +1 -0
- package/dist/hass/extensions/entity-manager.extension.d.ts +61 -0
- package/dist/hass/extensions/entity-manager.extension.js +214 -0
- package/dist/hass/extensions/entity-manager.extension.js.map +1 -0
- package/dist/hass/extensions/fetch-api.extension.d.ts +26 -0
- package/dist/hass/extensions/fetch-api.extension.js +166 -0
- package/dist/hass/extensions/fetch-api.extension.js.map +1 -0
- package/dist/hass/extensions/index.d.ts +5 -0
- package/dist/hass/extensions/index.js +9 -0
- package/dist/hass/extensions/index.js.map +1 -0
- package/dist/hass/extensions/utilities.extension.d.ts +9 -0
- package/dist/hass/extensions/utilities.extension.js +43 -0
- package/dist/hass/extensions/utilities.extension.js.map +1 -0
- package/dist/hass/extensions/websocket-api.extension.d.ts +39 -0
- package/dist/hass/extensions/websocket-api.extension.js +363 -0
- package/dist/hass/extensions/websocket-api.extension.js.map +1 -0
- package/dist/hass/hass.module.d.ts +53 -0
- package/dist/hass/hass.module.js +59 -0
- package/dist/hass/hass.module.js.map +1 -0
- package/dist/hass/helpers/backup.helper.d.ts +11 -0
- package/dist/hass/helpers/backup.helper.js +3 -0
- package/dist/hass/helpers/backup.helper.js.map +1 -0
- package/dist/hass/helpers/constants.helper.d.ts +54 -0
- package/dist/hass/helpers/constants.helper.js +63 -0
- package/dist/hass/helpers/constants.helper.js.map +1 -0
- package/dist/hass/helpers/entity-state.helper.d.ts +45 -0
- package/dist/hass/helpers/entity-state.helper.js +9 -0
- package/dist/hass/helpers/entity-state.helper.js.map +1 -0
- package/dist/hass/helpers/fetch/calendar.d.ts +54 -0
- package/dist/hass/helpers/fetch/calendar.js +3 -0
- package/dist/hass/helpers/fetch/calendar.js.map +1 -0
- package/dist/hass/helpers/fetch/configuration.d.ts +34 -0
- package/dist/hass/helpers/fetch/configuration.js +3 -0
- package/dist/hass/helpers/fetch/configuration.js.map +1 -0
- package/dist/hass/helpers/fetch/index.d.ts +4 -0
- package/dist/hass/helpers/fetch/index.js +8 -0
- package/dist/hass/helpers/fetch/index.js.map +1 -0
- package/dist/hass/helpers/fetch/server-log.d.ts +10 -0
- package/dist/hass/helpers/fetch/server-log.js +20 -0
- package/dist/hass/helpers/fetch/server-log.js.map +1 -0
- package/dist/hass/helpers/fetch/service-list.d.ts +51 -0
- package/dist/hass/helpers/fetch/service-list.js +3 -0
- package/dist/hass/helpers/fetch/service-list.js.map +1 -0
- package/dist/hass/helpers/index.d.ts +7 -0
- package/dist/hass/helpers/index.js +11 -0
- package/dist/hass/helpers/index.js.map +1 -0
- package/dist/hass/helpers/metrics.helper.d.ts +13 -0
- package/dist/hass/helpers/metrics.helper.js +30 -0
- package/dist/hass/helpers/metrics.helper.js.map +1 -0
- package/dist/hass/helpers/utility.helper.d.ts +57 -0
- package/dist/hass/helpers/utility.helper.js +34 -0
- package/dist/hass/helpers/utility.helper.js.map +1 -0
- package/dist/hass/helpers/websocket.helper.d.ts +129 -0
- package/dist/hass/helpers/websocket.helper.js +3 -0
- package/dist/hass/helpers/websocket.helper.js.map +1 -0
- package/dist/hass/index.d.ts +4 -0
- package/dist/hass/index.js +8 -0
- package/dist/hass/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/nexus/entities.extension.d.ts +2 -0
- package/dist/nexus/entities.extension.js +51 -0
- package/dist/nexus/entities.extension.js.map +1 -0
- package/dist/nexus/main.d.ts +9 -0
- package/dist/nexus/main.js +28 -0
- package/dist/nexus/main.js.map +1 -0
- package/dist/synapse/extensions/binary-sensor.extension.d.ts +19 -0
- package/dist/synapse/extensions/binary-sensor.extension.js +84 -0
- package/dist/synapse/extensions/binary-sensor.extension.js.map +1 -0
- package/dist/synapse/extensions/button.extension.d.ts +10 -0
- package/dist/synapse/extensions/button.extension.js +46 -0
- package/dist/synapse/extensions/button.extension.js.map +1 -0
- package/dist/synapse/extensions/index.d.ts +6 -0
- package/dist/synapse/extensions/index.js +10 -0
- package/dist/synapse/extensions/index.js.map +1 -0
- package/dist/synapse/extensions/registry.extension.d.ts +21 -0
- package/dist/synapse/extensions/registry.extension.js +207 -0
- package/dist/synapse/extensions/registry.extension.js.map +1 -0
- package/dist/synapse/extensions/scene.extension.d.ts +9 -0
- package/dist/synapse/extensions/scene.extension.js +37 -0
- package/dist/synapse/extensions/scene.extension.js.map +1 -0
- package/dist/synapse/extensions/sensor.extension.d.ts +25 -0
- package/dist/synapse/extensions/sensor.extension.js +154 -0
- package/dist/synapse/extensions/sensor.extension.js.map +1 -0
- package/dist/synapse/extensions/switch.extension.d.ts +19 -0
- package/dist/synapse/extensions/switch.extension.js +95 -0
- package/dist/synapse/extensions/switch.extension.js.map +1 -0
- package/dist/synapse/helpers/device-class.helper.d.ts +323 -0
- package/dist/synapse/helpers/device-class.helper.js +241 -0
- package/dist/synapse/helpers/device-class.helper.js.map +1 -0
- package/dist/synapse/helpers/index.d.ts +3 -0
- package/dist/synapse/helpers/index.js +7 -0
- package/dist/synapse/helpers/index.js.map +1 -0
- package/dist/synapse/helpers/metrics.helper.d.ts +13 -0
- package/dist/synapse/helpers/metrics.helper.js +30 -0
- package/dist/synapse/helpers/metrics.helper.js.map +1 -0
- package/dist/synapse/helpers/utility.helper.d.ts +1 -0
- package/dist/synapse/helpers/utility.helper.js +3 -0
- package/dist/synapse/helpers/utility.helper.js.map +1 -0
- package/dist/synapse/index.d.ts +3 -0
- package/dist/synapse/index.js +7 -0
- package/dist/synapse/index.js.map +1 -0
- package/dist/synapse/synapse.module.d.ts +29 -0
- package/dist/synapse/synapse.module.js +41 -0
- package/dist/synapse/synapse.module.js.map +1 -0
- package/dist/type-writer/build.extension.d.ts +2 -0
- package/dist/type-writer/build.extension.js +53 -0
- package/dist/type-writer/build.extension.js.map +1 -0
- package/dist/type-writer/main.d.ts +17 -0
- package/dist/type-writer/main.js +36 -0
- package/dist/type-writer/main.js.map +1 -0
- package/dist/type-writer/type-writer.extension.d.ts +2 -0
- package/dist/type-writer/type-writer.extension.js +212 -0
- package/dist/type-writer/type-writer.extension.js.map +1 -0
- package/dist/utilities/extensions/index.d.ts +3 -0
- package/dist/utilities/extensions/index.js +7 -0
- package/dist/utilities/extensions/index.js.map +1 -0
- package/dist/utilities/extensions/is.extension.d.ts +38 -0
- package/dist/utilities/extensions/is.extension.js +104 -0
- package/dist/utilities/extensions/is.extension.js.map +1 -0
- package/dist/utilities/extensions/zcc-testing.extension.d.ts +4 -0
- package/dist/utilities/extensions/zcc-testing.extension.js +9 -0
- package/dist/utilities/extensions/zcc-testing.extension.js.map +1 -0
- package/dist/utilities/extensions/zcc.extension.d.ts +20 -0
- package/dist/utilities/extensions/zcc.extension.js +66 -0
- package/dist/utilities/extensions/zcc.extension.js.map +1 -0
- package/dist/utilities/helpers/async.helper.d.ts +2 -0
- package/dist/utilities/helpers/async.helper.js +26 -0
- package/dist/utilities/helpers/async.helper.js.map +1 -0
- package/dist/utilities/helpers/context.helper.d.ts +7 -0
- package/dist/utilities/helpers/context.helper.js +3 -0
- package/dist/utilities/helpers/context.helper.js.map +1 -0
- package/dist/utilities/helpers/cron.helper.d.ts +87 -0
- package/dist/utilities/helpers/cron.helper.js +92 -0
- package/dist/utilities/helpers/cron.helper.js.map +1 -0
- package/dist/utilities/helpers/extend.helper.d.ts +2 -0
- package/dist/utilities/helpers/extend.helper.js +68 -0
- package/dist/utilities/helpers/extend.helper.js.map +1 -0
- package/dist/utilities/helpers/index.d.ts +5 -0
- package/dist/utilities/helpers/index.js +9 -0
- package/dist/utilities/helpers/index.js.map +1 -0
- package/dist/utilities/helpers/utilities.helper.d.ts +63 -0
- package/dist/utilities/helpers/utilities.helper.js +93 -0
- package/dist/utilities/helpers/utilities.helper.js.map +1 -0
- package/dist/utilities/index.d.ts +2 -0
- package/dist/utilities/index.js +6 -0
- package/dist/utilities/index.js.map +1 -0
- package/package.json +101 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Get } from "type-fest";
|
|
2
|
+
import { TBlackHole } from "../..";
|
|
3
|
+
import { ENTITY_SETUP, iCallService } from "../dynamic";
|
|
4
|
+
import { HassEntityContext } from ".";
|
|
5
|
+
/**
|
|
6
|
+
* Pick any valid entity, optionally limiting by domain
|
|
7
|
+
*/
|
|
8
|
+
export type PICK_ENTITY<DOMAIN extends ALL_DOMAINS = ALL_DOMAINS> = {
|
|
9
|
+
[key in DOMAIN]: `${key}.${keyof (typeof ENTITY_SETUP)[key] & string}`;
|
|
10
|
+
}[DOMAIN];
|
|
11
|
+
/**
|
|
12
|
+
* Pick any valid entity, optionally limiting by domain
|
|
13
|
+
*/
|
|
14
|
+
export type PICK_SERVICE<DOMAIN extends ALL_SERVICE_DOMAINS = ALL_SERVICE_DOMAINS> = {
|
|
15
|
+
[key in DOMAIN]: `${key}.${keyof iCallService[key] & string}`;
|
|
16
|
+
}[DOMAIN];
|
|
17
|
+
export type PICK_SERVICE_PARAMETERS<SERVICE extends PICK_SERVICE> = Get<iCallService, SERVICE> extends (serviceParams: infer ServiceParams) => TBlackHole ? ServiceParams : never;
|
|
18
|
+
export declare function entity_split(entity: {
|
|
19
|
+
entity_id: PICK_ENTITY;
|
|
20
|
+
} | PICK_ENTITY): [ALL_DOMAINS, string];
|
|
21
|
+
/**
|
|
22
|
+
* Extract the domain from an entity with type safety
|
|
23
|
+
*/
|
|
24
|
+
export declare function domain(entity: {
|
|
25
|
+
entity_id: PICK_ENTITY;
|
|
26
|
+
} | PICK_ENTITY): ALL_DOMAINS;
|
|
27
|
+
/**
|
|
28
|
+
* Type definitions to match a specific entity.
|
|
29
|
+
*/
|
|
30
|
+
export type ENTITY_STATE<ENTITY_ID extends PICK_ENTITY> = Omit<Get<typeof ENTITY_SETUP, ENTITY_ID>, "state" | "context" | "last_changed" | "last_updated"> & {
|
|
31
|
+
last_changed: string;
|
|
32
|
+
last_updated: string;
|
|
33
|
+
state: string;
|
|
34
|
+
context: HassEntityContext;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Union of all domains that contain entities
|
|
38
|
+
*/
|
|
39
|
+
export type ALL_DOMAINS = keyof typeof ENTITY_SETUP;
|
|
40
|
+
/**
|
|
41
|
+
* Union of all services with callable methods
|
|
42
|
+
*/
|
|
43
|
+
export type ALL_SERVICE_DOMAINS = keyof iCallService;
|
|
44
|
+
export type GetDomain<ENTITY extends PICK_ENTITY> = ENTITY extends `${infer domain}.${string}` ? domain : never;
|
|
45
|
+
declare module "../../utilities" {
|
|
46
|
+
interface IsIt {
|
|
47
|
+
domain: <DOMAIN extends ALL_DOMAINS>(entity: string, domain: DOMAIN) => entity is PICK_ENTITY<DOMAIN>;
|
|
48
|
+
}
|
|
49
|
+
interface ZCCDefinition {
|
|
50
|
+
/**
|
|
51
|
+
* Take some strings, and reformat into an entity_id using the same rules as home assistant
|
|
52
|
+
*
|
|
53
|
+
* Doesn't account for uniqueness rules that cause _1 / _2 / _3 / etc to be added
|
|
54
|
+
*/
|
|
55
|
+
toHassId: <DOMAIN extends ALL_DOMAINS>(domain: DOMAIN, ...parts: string[]) => PICK_ENTITY<DOMAIN>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.domain = exports.entity_split = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
function entity_split(entity) {
|
|
6
|
+
if (__1.is.object(entity)) {
|
|
7
|
+
entity = entity.entity_id;
|
|
8
|
+
}
|
|
9
|
+
return entity.split(".");
|
|
10
|
+
}
|
|
11
|
+
exports.entity_split = entity_split;
|
|
12
|
+
/**
|
|
13
|
+
* Extract the domain from an entity with type safety
|
|
14
|
+
*/
|
|
15
|
+
function domain(entity) {
|
|
16
|
+
if (__1.is.object(entity)) {
|
|
17
|
+
entity = entity.entity_id;
|
|
18
|
+
}
|
|
19
|
+
return entity_split(entity).shift();
|
|
20
|
+
}
|
|
21
|
+
exports.domain = domain;
|
|
22
|
+
__1.is.domain = (entity, domain) => {
|
|
23
|
+
const [test] = entity.split(".");
|
|
24
|
+
return test === domain;
|
|
25
|
+
};
|
|
26
|
+
__1.ZCC.toHassId = (domain, ...parts) => {
|
|
27
|
+
const name = parts
|
|
28
|
+
.join(" ")
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replaceAll(/\s+/g, "_")
|
|
31
|
+
.replaceAll(/\W/g, "");
|
|
32
|
+
return `${domain}.${name}`;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=utility.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.helper.js","sourceRoot":"","sources":["../../../src/hass/helpers/utility.helper.ts"],"names":[],"mappings":";;;AAEA,6BAA4C;AA2B5C,SAAgB,YAAY,CAC1B,MAAgD;IAEhD,IAAI,MAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAA0B,CAAC;AACpD,CAAC;AAPD,oCAOC;AACD;;GAEG;AACH,SAAgB,MAAM,CACpB,MAAgD;IAEhD,IAAI,MAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;IAC5B,CAAC;IACD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,KAAK,EAAiB,CAAC;AACrD,CAAC;AAPD,wBAOC;AA4BD,MAAE,CAAC,MAAM,GAAG,CACV,MAAc,EACd,MAAc,EACiB,EAAE;IACjC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,IAAI,KAAK,MAAM,CAAC;AACzB,CAAC,CAAC;AAqBF,OAAG,CAAC,QAAQ,GAAG,CACb,MAAc,EACd,GAAG,KAAe,EAClB,EAAE;IACF,MAAM,IAAI,GAAG,KAAK;SACf,IAAI,CAAC,GAAG,CAAC;SACT,WAAW,EAAE;SACb,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzB,OAAO,GAAG,MAAM,IAAI,IAAI,EAAyB,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Dayjs } from "dayjs";
|
|
2
|
+
import { TBlackHole, TContext } from "../..";
|
|
3
|
+
import { HASSIO_WS_COMMAND, HassSocketMessageTypes } from "./constants.helper";
|
|
4
|
+
import { EntityUpdateEvent } from "./entity-state.helper";
|
|
5
|
+
import { ALL_DOMAINS, ENTITY_STATE, PICK_ENTITY } from "./utility.helper";
|
|
6
|
+
export interface AreaDTO {
|
|
7
|
+
area_id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EntityRegistryItem {
|
|
11
|
+
area_id: string;
|
|
12
|
+
config_entry_id: string;
|
|
13
|
+
device_id: string;
|
|
14
|
+
disabled_by: string;
|
|
15
|
+
entity_id: string;
|
|
16
|
+
icon: string;
|
|
17
|
+
name: string;
|
|
18
|
+
platform: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DeviceListItemDTO {
|
|
21
|
+
area_id: string;
|
|
22
|
+
config_entries: string[];
|
|
23
|
+
connections: string[][];
|
|
24
|
+
disabled_by: null;
|
|
25
|
+
entry_type: null;
|
|
26
|
+
id: string;
|
|
27
|
+
identifiers: string[];
|
|
28
|
+
manufacturer: string;
|
|
29
|
+
model: string;
|
|
30
|
+
name: string;
|
|
31
|
+
name_by_user: null;
|
|
32
|
+
sw_version: string;
|
|
33
|
+
via_device_id: null;
|
|
34
|
+
}
|
|
35
|
+
export interface HassNotificationDTO {
|
|
36
|
+
created_at: string;
|
|
37
|
+
message: string;
|
|
38
|
+
notification_id: string;
|
|
39
|
+
status: "unread";
|
|
40
|
+
title: string;
|
|
41
|
+
}
|
|
42
|
+
export interface SignRequestResponse {
|
|
43
|
+
path: string;
|
|
44
|
+
}
|
|
45
|
+
export interface SocketMessageDTO {
|
|
46
|
+
error?: Record<string, unknown>;
|
|
47
|
+
event?: EntityUpdateEvent;
|
|
48
|
+
id: string;
|
|
49
|
+
message?: string;
|
|
50
|
+
result?: Record<string, unknown>;
|
|
51
|
+
type: HassSocketMessageTypes;
|
|
52
|
+
}
|
|
53
|
+
export interface SendSocketMessageDTO {
|
|
54
|
+
access_token?: string;
|
|
55
|
+
disabled_by?: "user";
|
|
56
|
+
domain?: string;
|
|
57
|
+
hidden_by?: "user";
|
|
58
|
+
service?: string;
|
|
59
|
+
service_data?: unknown;
|
|
60
|
+
type: HASSIO_WS_COMMAND | `${HASSIO_WS_COMMAND}`;
|
|
61
|
+
}
|
|
62
|
+
export interface UpdateEntityMessageDTO<DOMAIN extends ALL_DOMAINS = ALL_DOMAINS> {
|
|
63
|
+
area_id?: string;
|
|
64
|
+
disabled_by?: "user";
|
|
65
|
+
entity_id: PICK_ENTITY<DOMAIN>;
|
|
66
|
+
hidden_by?: "user";
|
|
67
|
+
icon?: string;
|
|
68
|
+
name: string;
|
|
69
|
+
new_entity_id: PICK_ENTITY<DOMAIN>;
|
|
70
|
+
type: HASSIO_WS_COMMAND.registry_update;
|
|
71
|
+
}
|
|
72
|
+
export interface RemoveEntityMessageDTO {
|
|
73
|
+
entity_id: PICK_ENTITY;
|
|
74
|
+
type: HASSIO_WS_COMMAND.entity_remove;
|
|
75
|
+
}
|
|
76
|
+
export interface FindRelatedDTO {
|
|
77
|
+
item_id: string;
|
|
78
|
+
item_type: string;
|
|
79
|
+
type: HASSIO_WS_COMMAND.search_related;
|
|
80
|
+
}
|
|
81
|
+
export interface RegistryGetDTO {
|
|
82
|
+
entity_id: string;
|
|
83
|
+
type: HASSIO_WS_COMMAND.registry_get;
|
|
84
|
+
}
|
|
85
|
+
export interface RenderTemplateDTO {
|
|
86
|
+
template: string;
|
|
87
|
+
timeout: number;
|
|
88
|
+
type: HASSIO_WS_COMMAND.render_template;
|
|
89
|
+
}
|
|
90
|
+
export interface SubscribeTriggerDTO {
|
|
91
|
+
trigger: Record<string, unknown>;
|
|
92
|
+
type: HASSIO_WS_COMMAND.subscribe_trigger;
|
|
93
|
+
}
|
|
94
|
+
export interface UnsubscribeEventsDTO {
|
|
95
|
+
subscription: number;
|
|
96
|
+
type: HASSIO_WS_COMMAND.unsubscribe_events;
|
|
97
|
+
}
|
|
98
|
+
export interface SignPathDTO {
|
|
99
|
+
path: string;
|
|
100
|
+
type: HASSIO_WS_COMMAND.download_backup;
|
|
101
|
+
}
|
|
102
|
+
export interface RemoveBackupDTO {
|
|
103
|
+
slug: string;
|
|
104
|
+
type: HASSIO_WS_COMMAND.remove_backup;
|
|
105
|
+
}
|
|
106
|
+
export interface EntityHistoryDTO<ENTITIES extends PICK_ENTITY[] = PICK_ENTITY[]> {
|
|
107
|
+
end_time: Date | string | Dayjs;
|
|
108
|
+
entity_ids: ENTITIES;
|
|
109
|
+
minimal_response?: boolean;
|
|
110
|
+
no_attributes?: boolean;
|
|
111
|
+
start_time: Date | string | Dayjs;
|
|
112
|
+
type: HASSIO_WS_COMMAND.history_during_period;
|
|
113
|
+
}
|
|
114
|
+
export type EntityHistoryResult<ENTITY extends PICK_ENTITY = PICK_ENTITY, ATTRIBUTES extends object = object> = Pick<ENTITY_STATE<ENTITY> & {
|
|
115
|
+
attributes: ATTRIBUTES;
|
|
116
|
+
}, "attributes" | "state"> & {
|
|
117
|
+
date: Date;
|
|
118
|
+
};
|
|
119
|
+
export type SOCKET_MESSAGES = {
|
|
120
|
+
id?: number;
|
|
121
|
+
} & (FindRelatedDTO | RegistryGetDTO | RemoveBackupDTO | RenderTemplateDTO | RemoveEntityMessageDTO | SendSocketMessageDTO | SignPathDTO | SubscribeTriggerDTO | UnsubscribeEventsDTO | UpdateEntityMessageDTO | EntityHistoryDTO);
|
|
122
|
+
export type OnHassEventCallback<T = object> = (event: T) => TBlackHole;
|
|
123
|
+
export type OnHassEventOptions<T = object> = {
|
|
124
|
+
context: TContext;
|
|
125
|
+
label?: string;
|
|
126
|
+
exec: OnHassEventCallback<T>;
|
|
127
|
+
event: string;
|
|
128
|
+
once?: boolean;
|
|
129
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.helper.js","sourceRoot":"","sources":["../../../src/hass/helpers/websocket.helper.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./dynamic"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./extensions"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./hass.module"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./helpers"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hass/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,uDAA6B;AAC7B,wDAA8B;AAC9B,oDAA0B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// Main namespace exports. MVP folders to not pollute the loaded modules
|
|
5
|
+
tslib_1.__exportStar(require("./utilities"), exports);
|
|
6
|
+
//
|
|
7
|
+
tslib_1.__exportStar(require("./boilerplate"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAAwE;AACxE,sDAA4B;AAC5B,EAAE;AACF,wDAA8B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntitiesExtension = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
function EntitiesExtension({ synapse, logger, context, scheduler, }) {
|
|
6
|
+
synapse.button({
|
|
7
|
+
context,
|
|
8
|
+
exec: () => {
|
|
9
|
+
logger.info("oranges clicked");
|
|
10
|
+
},
|
|
11
|
+
icon: "solar-angle",
|
|
12
|
+
name: "Click for oranges",
|
|
13
|
+
});
|
|
14
|
+
const binary = synapse.binary_sensor({
|
|
15
|
+
context,
|
|
16
|
+
defaultState: "on",
|
|
17
|
+
icon: "sun-angle",
|
|
18
|
+
name: "Test binary sensor",
|
|
19
|
+
});
|
|
20
|
+
const sensor = synapse.sensor({
|
|
21
|
+
context,
|
|
22
|
+
defaultAttributes: {
|
|
23
|
+
number: 5000,
|
|
24
|
+
},
|
|
25
|
+
defaultState: "banana",
|
|
26
|
+
name: "Demo sensor",
|
|
27
|
+
});
|
|
28
|
+
scheduler.interval({
|
|
29
|
+
context,
|
|
30
|
+
exec: () => {
|
|
31
|
+
binary.on = !binary.on;
|
|
32
|
+
sensor.state = Date.now().toString();
|
|
33
|
+
sensor.attributes.number = sensor.attributes.number + __1.INCREMENT;
|
|
34
|
+
theSwitch.on = !theSwitch.on;
|
|
35
|
+
},
|
|
36
|
+
interval: 2000,
|
|
37
|
+
});
|
|
38
|
+
synapse.scene({
|
|
39
|
+
context,
|
|
40
|
+
exec: () => {
|
|
41
|
+
logger.warn("scene activated");
|
|
42
|
+
},
|
|
43
|
+
name: "test scene",
|
|
44
|
+
});
|
|
45
|
+
const theSwitch = synapse.switch({
|
|
46
|
+
context,
|
|
47
|
+
name: "the switch",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.EntitiesExtension = EntitiesExtension;
|
|
51
|
+
//# sourceMappingURL=entities.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.extension.js","sourceRoot":"","sources":["../../src/nexus/entities.extension.ts"],"names":[],"mappings":";;;AAAA,0BAA+C;AAE/C,SAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,OAAO,EACP,SAAS,GACM;IACf,OAAO,CAAC,MAAM,CAAC;QACb,OAAO;QACP,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,mBAAmB;KAC1B,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;QACnC,OAAO;QACP,YAAY,EAAE,IAAI;QAClB,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,oBAAoB;KAC3B,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAA6B;QACxD,OAAO;QACP,iBAAiB,EAAE;YACjB,MAAM,EAAE,IAAI;SACb;QACD,YAAY,EAAE,QAAQ;QACtB,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;IACH,SAAS,CAAC,QAAQ,CAAC;QACjB,OAAO;QACP,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,aAAS,CAAC;YAChE,SAAS,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,CAAC;QACD,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,CAAC;QACZ,OAAO;QACP,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,YAAY;KACnB,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/B,OAAO;QACP,IAAI,EAAE,YAAY;KACnB,CAAC,CAAC;AACL,CAAC;AAjDD,8CAiDC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntitiesExtension } from "./entities.extension";
|
|
2
|
+
export declare const NEXUS_APP: import("..").ApplicationDefinition<{
|
|
3
|
+
entities: typeof EntitiesExtension;
|
|
4
|
+
}, import("..").ModuleConfiguration>;
|
|
5
|
+
declare module ".." {
|
|
6
|
+
interface LoadedModules {
|
|
7
|
+
nexus: typeof NEXUS_APP;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NEXUS_APP = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const automation_1 = require("../automation");
|
|
6
|
+
const hass_1 = require("../hass");
|
|
7
|
+
const synapse_1 = require("../synapse");
|
|
8
|
+
const entities_extension_1 = require("./entities.extension");
|
|
9
|
+
exports.NEXUS_APP = (0, __1.CreateApplication)({
|
|
10
|
+
libraries: [hass_1.LIB_HASS, synapse_1.LIB_SYNAPSE, automation_1.LIB_AUTOMATION],
|
|
11
|
+
name: "nexus",
|
|
12
|
+
services: {
|
|
13
|
+
entities: entities_extension_1.EntitiesExtension,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
setImmediate(async () => {
|
|
17
|
+
await exports.NEXUS_APP.bootstrap({
|
|
18
|
+
configuration: {
|
|
19
|
+
boilerplate: {
|
|
20
|
+
LOG_LEVEL: "debug",
|
|
21
|
+
},
|
|
22
|
+
hass: {
|
|
23
|
+
AUTO_SCAN_CALL_PROXY: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/nexus/main.ts"],"names":[],"mappings":";;;AAAA,0BAAuC;AACvC,8CAA+C;AAC/C,kCAAmC;AACnC,wCAAyC;AACzC,6DAAyD;AAE5C,QAAA,SAAS,GAAG,IAAA,qBAAiB,EAAC;IACzC,SAAS,EAAE,CAAC,eAAQ,EAAE,qBAAW,EAAE,2BAAc,CAAC;IAClD,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE;QACR,QAAQ,EAAE,sCAAiB;KAC5B;CACF,CAAC,CAAC;AAQH,YAAY,CAAC,KAAK,IAAI,EAAE;IACtB,MAAM,iBAAS,CAAC,SAAS,CAAC;QACxB,aAAa,EAAE;YACb,WAAW,EAAE;gBACX,SAAS,EAAE,OAAO;aACnB;YACD,IAAI,EAAE;gBACJ,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TServiceParams } from "../../boilerplate";
|
|
2
|
+
import { TBlackHole, TContext } from "../../utilities";
|
|
3
|
+
import { OnOff } from "..";
|
|
4
|
+
type TBinarySensor = {
|
|
5
|
+
context: TContext;
|
|
6
|
+
defaultState?: OnOff;
|
|
7
|
+
icon?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
export type VirtualBinarySensor = {
|
|
11
|
+
state: OnOff;
|
|
12
|
+
name: string;
|
|
13
|
+
icon: string;
|
|
14
|
+
onUpdate: (callback: BinarySensorUpdateCallback) => void;
|
|
15
|
+
on: boolean;
|
|
16
|
+
};
|
|
17
|
+
type BinarySensorUpdateCallback = (state: boolean) => TBlackHole;
|
|
18
|
+
export declare function BinarySensor({ logger, context, lifecycle, synapse, }: TServiceParams): (entity: TBinarySensor) => VirtualBinarySensor;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinarySensor = void 0;
|
|
4
|
+
const utilities_1 = require("../../utilities");
|
|
5
|
+
function BinarySensor({ logger, context, lifecycle, synapse, }) {
|
|
6
|
+
const callbacks = [];
|
|
7
|
+
const registry = synapse.registry({
|
|
8
|
+
context,
|
|
9
|
+
details: item => ({ state: item.state }),
|
|
10
|
+
domain: "binary_sensor",
|
|
11
|
+
});
|
|
12
|
+
// # Binary sensor entity creation function
|
|
13
|
+
function create(entity) {
|
|
14
|
+
let state;
|
|
15
|
+
// ## Handle state updates. Ignore non-updates
|
|
16
|
+
async function setState(newState) {
|
|
17
|
+
if (newState === state) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
state = newState;
|
|
21
|
+
setImmediate(async () => {
|
|
22
|
+
logger.trace({
|
|
23
|
+
name: entity.context,
|
|
24
|
+
sensor: entity.name,
|
|
25
|
+
}, `syncing state`);
|
|
26
|
+
await registry.setCache(id, state);
|
|
27
|
+
await registry.send(id, { state });
|
|
28
|
+
await (0, utilities_1.each)(callbacks, async (callback) => await utilities_1.ZCC.safeExec(async () => await callback(state === "on")));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// ## Wait until bootstrap to load cache
|
|
32
|
+
lifecycle.onBootstrap(async () => {
|
|
33
|
+
state = await registry.getCache(id);
|
|
34
|
+
if (utilities_1.is.undefined(state)) {
|
|
35
|
+
state = entity.defaultState || "off";
|
|
36
|
+
registry.loadFromHass(id, data => {
|
|
37
|
+
if (utilities_1.is.empty(data)) {
|
|
38
|
+
// wat
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
logger.debug({ data, id, name: entity.name }, `received value`);
|
|
42
|
+
state = data.state;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// ## Proxy object as return
|
|
47
|
+
const out = new Proxy({}, {
|
|
48
|
+
get(_, property) {
|
|
49
|
+
if (property === "state") {
|
|
50
|
+
return state;
|
|
51
|
+
}
|
|
52
|
+
if (property === "on") {
|
|
53
|
+
return state === "on";
|
|
54
|
+
}
|
|
55
|
+
if (property === "icon") {
|
|
56
|
+
return entity.icon;
|
|
57
|
+
}
|
|
58
|
+
if (property === "onUpdate") {
|
|
59
|
+
return (callback) => callbacks.push(callback);
|
|
60
|
+
}
|
|
61
|
+
if (property === "name") {
|
|
62
|
+
return entity.name;
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
},
|
|
66
|
+
set(_, property, value) {
|
|
67
|
+
if (property === "state") {
|
|
68
|
+
setState(value);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (property === "on") {
|
|
72
|
+
setState(value ? "on" : "off");
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const id = registry.add(out);
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
return create;
|
|
82
|
+
}
|
|
83
|
+
exports.BinarySensor = BinarySensor;
|
|
84
|
+
//# sourceMappingURL=binary-sensor.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-sensor.extension.js","sourceRoot":"","sources":["../../../src/synapse/extensions/binary-sensor.extension.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TBlackHole, TContext, TServiceParams } from "../..";
|
|
2
|
+
type TButton = {
|
|
3
|
+
exec: () => TBlackHole;
|
|
4
|
+
context: TContext;
|
|
5
|
+
label?: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function Button({ logger, hass, context, synapse }: TServiceParams): (entity: TButton) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Button = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
const __2 = require("..");
|
|
6
|
+
function Button({ logger, hass, context, synapse }) {
|
|
7
|
+
const registry = synapse.registry({
|
|
8
|
+
context,
|
|
9
|
+
domain: "button",
|
|
10
|
+
});
|
|
11
|
+
// ### Listen for socket events
|
|
12
|
+
hass.socket.onEvent({
|
|
13
|
+
context: context,
|
|
14
|
+
event: "digital_alchemy_activate",
|
|
15
|
+
exec({ data }) {
|
|
16
|
+
const item = registry.byId(data.id);
|
|
17
|
+
if (!item) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { exec, context, label, name } = item;
|
|
21
|
+
logger.trace({ data, label: name }, `received button press`);
|
|
22
|
+
setImmediate(async () => {
|
|
23
|
+
await __1.ZCC.safeExec({
|
|
24
|
+
duration: __2.BUTTON_EXECUTION_TIME,
|
|
25
|
+
errors: __2.BUTTON_ERRORS,
|
|
26
|
+
exec: async () => await exec(),
|
|
27
|
+
executions: __2.BUTTON_EXECUTION_COUNT,
|
|
28
|
+
labels: { context, label },
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* ### Register a new button
|
|
35
|
+
*
|
|
36
|
+
* Can be called from construction phase - bootstrap.
|
|
37
|
+
* Auto syncs with home assistant onReady, and will emit warnings for new buttons after.
|
|
38
|
+
*
|
|
39
|
+
* Warnings indicate that a manual update of the integration may be required.
|
|
40
|
+
*/
|
|
41
|
+
return function create(entity) {
|
|
42
|
+
registry.add(entity);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.Button = Button;
|
|
46
|
+
//# sourceMappingURL=button.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.extension.js","sourceRoot":"","sources":["../../../src/synapse/extensions/button.extension.ts"],"names":[],"mappings":";;;AAAA,6BAAkE;AAClE,0BAIY;AAeZ,SAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAkB;IACvE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAU;QACzC,OAAO;QACP,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAC;IAEH,+BAA+B;IAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAClB,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE,0BAA0B;QACjC,IAAI,CAAC,EAAE,IAAI,EAAyB;YAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YAC5C,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,uBAAuB,CAAC,CAAC;YAC7D,YAAY,CAAC,KAAK,IAAI,EAAE;gBACtB,MAAM,OAAG,CAAC,QAAQ,CAAC;oBACjB,QAAQ,EAAE,yBAAqB;oBAC/B,MAAM,EAAE,iBAAa;oBACrB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE;oBAC9B,UAAU,EAAE,0BAAsB;oBAClC,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;iBAC3B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH;;;;;;;OAOG;IACH,OAAO,SAAS,MAAM,CAAC,MAAe;QACpC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAxCD,wBAwCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./binary-sensor.extension"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./button.extension"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./registry.extension"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./scene.extension"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./sensor.extension"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./switch.extension"), exports);
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/synapse/extensions/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,6DAAmC;AACnC,+DAAqC;AACrC,4DAAkC;AAClC,6DAAmC;AACnC,6DAAmC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TContext, TServiceParams } from "../..";
|
|
2
|
+
import { ALL_DOMAINS } from "../../hass";
|
|
3
|
+
type BaseEntity = {
|
|
4
|
+
name: string;
|
|
5
|
+
icon?: string;
|
|
6
|
+
unique_id?: string;
|
|
7
|
+
};
|
|
8
|
+
type SynapseSocketOptions<DATA extends object> = {
|
|
9
|
+
context: TContext;
|
|
10
|
+
domain: ALL_DOMAINS;
|
|
11
|
+
details?: (data: DATA) => object;
|
|
12
|
+
};
|
|
13
|
+
export declare function Registry({ lifecycle, logger, hass, cache, config, context, scheduler, }: TServiceParams): <DATA extends BaseEntity>({ domain, context, details, }: SynapseSocketOptions<DATA>) => {
|
|
14
|
+
add(data: DATA): string;
|
|
15
|
+
byId(id: string): DATA;
|
|
16
|
+
getCache<T>(id: string, defaultValue?: T): Promise<T>;
|
|
17
|
+
loadFromHass: <T_1 extends object>(id: string, callback: (argument: T_1) => void) => void;
|
|
18
|
+
send(id: string, data: object): Promise<void>;
|
|
19
|
+
setCache(id: string, value: unknown): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export {};
|