Skip to content

Commit

Permalink
Complete carousel refactor.
Browse files Browse the repository at this point in the history
Reduces one layer of DOM nesting for simplication, uses the latest Embla
version, unittests for everything.
  • Loading branch information
dermotduffy committed Sep 4, 2023
1 parent 48ece1e commit e830db1
Show file tree
Hide file tree
Showing 56 changed files with 3,550 additions and 1,939 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"custom-card-helpers": "^1.9.0",
"date-fns": "^2.29.2",
"date-fns-tz": "^1.3.7",
"embla-carousel": "^7.0.9",
"embla-carousel-wheel-gestures": "^3.0.0",
"embla-carousel": "8.0.0-rc12",
"embla-carousel-wheel-gestures": "8.0.0-rc04",
"home-assistant-js-websocket": "^8.0.0",
"keycharm": "^0.4.0",
"lit": "^2.3.1",
Expand Down Expand Up @@ -62,7 +62,7 @@
"@types/masonry-layout": "^4.2.5",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"@vitest/coverage-c8": "^0.29.8",
"@vitest/coverage-istanbul": "^0.34.3",
"eslint": "^8.23.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -80,8 +80,8 @@
"sass": "^1.54.9",
"ts-prune": "^0.10.3",
"typescript": "^4.9.5",
"vitest": "^0.29.8",
"vitest-mock-extended": "^1.1.3"
"vitest": "^0.34.3",
"vitest-mock-extended": "^1.2.1"
},
"scripts": {
"start": "rollup -c --watch",
Expand Down
2 changes: 1 addition & 1 deletion src/action-handler-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {
import { noChange } from 'lit';
import {
AttributePart,
directive,
Directive,
DirectiveParameters,
directive,
} from 'lit/directive.js';
import { stopEventFromActivatingCardWideActions } from './utils/action.js';
import { Timer } from './utils/timer.js';
Expand Down
12 changes: 5 additions & 7 deletions src/cached-value-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ export class CachedValueController<T> implements ReactiveController {
public startTimer(): void {
this.stopTimer();

if (this._timerSeconds > 0) {
this._timerStartCallback?.();
this._timer.startRepeated(this._timerSeconds, () => {
this.updateValue();
this._host.requestUpdate();
});
}
this._timerStartCallback?.();
this._timer.startRepeated(this._timerSeconds, () => {
this.updateValue();
this._host.requestUpdate();
});
}

public hasTimer(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/camera-manager/engine-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class CameraManagerEngineFactory {
engine = Engine.MotionEye;
} else if (cameraConfig.engine === 'generic') {
engine = Engine.Generic;
} else if (cameraConfig.engine === 'auto') {
} else {
const cameraEntity = getCameraEntityFromConfig(cameraConfig);

if (cameraEntity) {
Expand Down
19 changes: 9 additions & 10 deletions src/camera-manager/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class ExpiringMemoryRangeSet
}

public add(range: ExpiringRange<Date>): void {
this._expireOldRanges();
this._ranges.push(range);
this._expireOldRanges();
}

protected _expireOldRanges(): void {
Expand Down Expand Up @@ -95,26 +95,25 @@ export const compressRanges = <T extends Date | number>(
ranges = orderBy(ranges, (range) => range.start, 'asc');

let current: Range<T> | null = null;
for (let i = 0; i < ranges.length; ++i) {
const item = ranges[i];
const itemStartSeconds =
item.start instanceof Date ? item.start.getTime() : item.start;
for (const range of ranges) {
const rangeStartSeconds: number =
range.start instanceof Date ? range.start.getTime() : range.start;

if (!current) {
current = { ...item };
current = { ...range };
continue;
}

const currentEndSeconds =
current.end instanceof Date ? current.end.getTime() : (current.end as number);

if (currentEndSeconds + toleranceSeconds * 1000 >= itemStartSeconds) {
if (item.end > current.end) {
current.end = item.end;
if (currentEndSeconds + toleranceSeconds * 1000 >= rangeStartSeconds) {
if (range.end > current.end) {
current.end = range.end;
}
} else {
compressedRanges.push(current);
current = { ...item };
current = { ...range };
}
}
if (current) {
Expand Down
Loading

0 comments on commit e830db1

Please sign in to comment.