Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get kelvin fix #48

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@digital-alchemy/automation",
"repository": "https://github.com/Digital-Alchemy-TS/automation",
"homepage": "https://docs.digital-alchemy.app/Automation",
"version": "25.1.1",
"version": "25.2.1",
"scripts": {
"build": "rm -rf dist/; tsc",
"lint": "eslint src",
Expand Down Expand Up @@ -31,33 +31,33 @@
"dayjs": "^1"
},
"devDependencies": {
"@cspell/eslint-plugin": "^8.17.1",
"@digital-alchemy/core": "^25.1.1",
"@digital-alchemy/hass": "^25.1.1",
"@digital-alchemy/synapse": "^25.1.1",
"@eslint/compat": "^1.2.5",
"@cspell/eslint-plugin": "^8.17.3",
"@digital-alchemy/core": "^25.2.1",
"@digital-alchemy/hass": "^25.2.1",
"@digital-alchemy/synapse": "^25.2.1",
"@eslint/compat": "^1.2.6",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "8.19.1",
"@typescript-eslint/parser": "8.19.1",
"@eslint/js": "^9.20.0",
"@types/node": "^22.13.1",
"@typescript-eslint/eslint-plugin": "8.23.0",
"@typescript-eslint/parser": "8.23.0",
"dayjs": "^1.11.13",
"eslint": "9.18.0",
"eslint-config-prettier": "9.1.0",
"eslint": "9.20.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsonc": "^2.18.2",
"eslint-plugin-jsonc": "^2.19.1",
"eslint-plugin-no-unsanitized": "^4.1.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sonarjs": "^3.0.1",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unicorn": "^56.0.1",
"prettier": "^3.4.2",
"prettier": "^3.5.0",
"tsx": "^4.19.2",
"type-fest": "^4.32.0",
"type-fest": "^4.34.1",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
"vitest": "^3.0.5"
},
"packageManager": "yarn@4.5.1"
}
13 changes: 11 additions & 2 deletions src/services/aggressive-scenes.service.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each, is, TContext, TServiceParams } from "@digital-alchemy/core";
import { each, TContext, TServiceParams } from "@digital-alchemy/core";
import { domain, ENTITY_STATE, PICK_ENTITY, PICK_FROM_AREA, TAreaId } from "@digital-alchemy/hass";

import {
Expand All @@ -16,7 +16,16 @@ type TValidateOptions<ROOM extends TAreaId> = {
scene: RoomScene<ROOM>;
};

export function AggressiveScenes({ logger, config, hass, event, automation }: TServiceParams) {
export function AggressiveScenes({
internal: {
utils: { is },
},
logger,
config,
hass,
event,
automation,
}: TServiceParams) {
async function manageSwitch<ROOM extends TAreaId, SCENE extends SceneDefinition<ROOM>>(
entity: ENTITY_STATE<PICK_FROM_AREA<ROOM, "switch">>,
scene: SCENE,
Expand Down
19 changes: 10 additions & 9 deletions src/services/circadian.service.mts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export function CircadianLighting({

event.on(LOCATION_UPDATED, () => updateKelvin());

function getKelvin() {
const offset = getColorOffset();
return Math.floor(
(config.automation.CIRCADIAN_MAX_TEMP - config.automation.CIRCADIAN_MIN_TEMP) * offset +
config.automation.CIRCADIAN_MIN_TEMP,
);
}

function updateKelvin() {
if (!circadianEntity) {
return;
Expand All @@ -48,14 +56,7 @@ export function CircadianLighting({
logger.debug({ name: updateKelvin }, `lat/long not loaded yet`);
return;
}
const offset = getColorOffset();
circadianEntity.storage.set(
"state",
Math.floor(
(config.automation.CIRCADIAN_MAX_TEMP - config.automation.CIRCADIAN_MIN_TEMP) * offset +
config.automation.CIRCADIAN_MIN_TEMP,
),
);
circadianEntity.storage.set("state", getKelvin());
}

/**
Expand Down Expand Up @@ -90,7 +91,7 @@ export function CircadianLighting({

const out = {
circadianEntity,
getKelvin: () => Number(circadianEntity?.storage.get("state")),
getKelvin,
updateKelvin,
};
return out;
Expand Down
4 changes: 3 additions & 1 deletion src/services/light-manager.service.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
DOWN,
each,
eachLimit,
is,
NONE,
sleep,
TServiceParams,
Expand Down Expand Up @@ -61,6 +60,9 @@ export function LightManager({
hass,
scheduler,
lifecycle,
internal: {
utils: { is },
},
automation,
config,
}: TServiceParams) {
Expand Down
12 changes: 10 additions & 2 deletions src/services/managed-switch.service.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { CronExpression, is, SINGLE, TContext, TServiceParams } from "@digital-alchemy/core";
import { CronExpression, SINGLE, TContext, TServiceParams } from "@digital-alchemy/core";

import { ManagedSwitchOptions, PickASwitch } from "../helpers/index.mts";

export function ManagedSwitch({ logger, hass, scheduler, lifecycle }: TServiceParams) {
export function ManagedSwitch({
logger,
hass,
scheduler,
lifecycle,
internal: {
utils: { is },
},
}: TServiceParams) {
/**
* Logic runner for the state enforcer
*/
Expand Down
6 changes: 4 additions & 2 deletions src/services/room.service.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
eachSeries,
FIRST,
InternalError,
is,
TServiceParams,
VALUE,
} from "@digital-alchemy/core";
Expand Down Expand Up @@ -42,6 +41,9 @@ export function Room({
logger,
hass,
synapse,
internal: {
utils: { is },
},
scheduler,
automation,
context: parentContext,
Expand All @@ -51,7 +53,7 @@ export function Room({
context,
scenes,
}: RoomConfiguration<SCENES, ROOM>): RoomDefinition<SCENES> {
logger.info({ name }, `create room`);
logger.debug({ name }, `create room`);
const SCENE_LIST = Object.keys(scenes) as SCENES[];

const sensorName = `${name} current scene`;
Expand Down
3 changes: 2 additions & 1 deletion src/services/sequence-matcher.service.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { is, sleep, START, TServiceParams } from "@digital-alchemy/core";
import { sleep, START, TServiceParams } from "@digital-alchemy/core";

import { ActiveWatcher, GenericFilter, SequenceWatchOptions, TrackedOptions } from "../index.mts";

export function SequenceWatcher({ logger, hass, config, internal }: TServiceParams) {
const { is } = internal.utils;
const ACTIVE = new Map<object, ActiveWatcher>();
const WATCHED_EVENTS = new Map<string, TrackedOptions[]>();
const EVENT_REMOVAL = new Map<string, () => void>();
Expand Down
12 changes: 10 additions & 2 deletions src/services/solar-calc.service.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CronExpression, is, TBlackHole, TServiceParams } from "@digital-alchemy/core";
import { CronExpression, TBlackHole, TServiceParams } from "@digital-alchemy/core";
import { HassConfig } from "@digital-alchemy/hass";
import dayjs, { Dayjs } from "dayjs";
import { Duration, DurationUnitsObjectType, DurationUnitType } from "dayjs/plugin/duration";
Expand Down Expand Up @@ -79,7 +79,15 @@ type SolarReference = Record<SolarEvents, Dayjs> & {
/**
* Benefits from a persistent cache, like Redis
*/
export function SolarCalculator({ logger, scheduler, hass, lifecycle }: TServiceParams) {
export function SolarCalculator({
logger,
scheduler,
hass,
lifecycle,
internal: {
utils: { is },
},
}: TServiceParams) {
let config: HassConfig;
const event = new EventEmitter();
event.setMaxListeners(UNLIMITED);
Expand Down
Loading