Skip to content

Commit

Permalink
catch up commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-codez committed May 7, 2024
1 parent 7b177f8 commit 1d33d6e
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 303 deletions.
575 changes: 289 additions & 286 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
},
"license": "MIT",
"dependencies": {
"@digital-alchemy/core": "^0.3.10",
"@digital-alchemy/hass": "^0.3.8",
"dayjs": "^1.11.10",
"prom-client": "^15.1.1",
"ws": "^8.16.0"
"@digital-alchemy/core": "^0.3.13",
"@digital-alchemy/hass": "^0.3.23",
"dayjs": "^1.11.11",
"prom-client": "^15.1.2",
"ws": "^8.17.0"
},
"devDependencies": {
"@cspell/eslint-plugin": "^8.7.0",
"@cspell/eslint-plugin": "^8.8.0",
"@types/figlet": "^1.5.8",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/minimist": "^1.2.5",
"@types/mute-stream": "^0.0.4",
"@types/node": "^20.12.7",
"@types/node": "^20.12.10",
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -51,16 +51,16 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-security": "^3.0.0",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-sonarjs": "^0.25.1",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unicorn": "^52.0.0",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"npm-check-updates": "^16.14.18",
"npm-check-updates": "^16.14.20",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"tsx": "^4.7.2",
"type-fest": "^4.15.0",
"tsx": "^4.9.3",
"type-fest": "^4.18.2",
"typescript": "^5.4.5"
}
}
1 change: 1 addition & 0 deletions src/extensions/number.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function NumberDomain({ context, synapse }: TServiceParams) {
const id = registry.add(numberOut);
const loader = synapse.storage.loader<STATE, ATTRIBUTES>({
id,
name: entity.name,
registry: registry as TRegistry<unknown>,
value: {
attributes: {} as ATTRIBUTES,
Expand Down
1 change: 1 addition & 0 deletions src/extensions/select.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function SelectDomain({ context, synapse }: TServiceParams) {
const id = registry.add(numberOut);
const loader = synapse.storage.loader<STATE, ATTRIBUTES>({
id,
name: entity.name,
registry: registry as TRegistry<unknown>,
value: {
attributes: (entity.defaultAttributes ?? {}) as ATTRIBUTES,
Expand Down
1 change: 1 addition & 0 deletions src/extensions/sensor.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function Sensor({ context, synapse }: TServiceParams) {

const loader = synapse.storage.loader<STATE, ATTRIBUTES>({
id,
name: entity.name,
registry: registry as TRegistry<unknown>,
value: {
attributes: {} as ATTRIBUTES,
Expand Down
23 changes: 19 additions & 4 deletions src/extensions/storage.extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BootstrapException,
deepExtend,
each,
is,
NOT_FOUND,
Expand Down Expand Up @@ -36,7 +37,8 @@ type LoaderOptions<STATE, ATTRIBUTES extends object> = {
};

type TCallback<STATE, ATTRIBUTES extends object> = (
options: StorageData<STATE, ATTRIBUTES>,
new_state: StorageData<STATE, ATTRIBUTES>,
old_state: StorageData<STATE, ATTRIBUTES>,
) => TBlackHole;

export function ValueStorage({
Expand Down Expand Up @@ -164,11 +166,17 @@ export function ValueStorage({
function RunCallbacks(data: StorageData<STATE, ATTRIBUTES>) {
setImmediate(async () => {
await store();
await registry.send(id, data);
const current = {
attributes: entity.attributes,
state: entity.state,
};
await registry.send(id, current);
await each(
callbacks,
async callback =>
await internal.safeExec(async () => await callback(data)),
await internal.safeExec(
async () => await callback(current, data),
),
);
});
}
Expand Down Expand Up @@ -196,6 +204,13 @@ export function ValueStorage({
if (is.equal(entity.attributes[key], incoming)) {
return;
}
const current = deepExtend(
{},
{
attributes: entity.attributes,
state: entity.state,
},
);
value.attributes[key] = incoming;
logger.trace(
{ domain, key, name, value: incoming },
Expand All @@ -205,7 +220,7 @@ export function ValueStorage({
domain: registry.domain,
name,
});
RunCallbacks({ attributes: entity.attributes });
RunCallbacks(current);
},

setAttributes(newAttributes: ATTRIBUTES) {
Expand Down
1 change: 1 addition & 0 deletions src/extensions/switch.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function Switch({ logger, context, hass, synapse }: TServiceParams) {
const id = registry.add(returnEntity);
const loader = synapse.storage.loader<LocalOnOff, ATTRIBUTES>({
id,
name: entity.name,
registry: registry as TRegistry<unknown>,
value: {
attributes: {} as ATTRIBUTES,
Expand Down

0 comments on commit 1d33d6e

Please sign in to comment.