Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- The port map shows the latest confirmed colors on the next paint when switch updates arrive slowly. It resumes smooth transitions when updates become frequent again.

## 0.7.2

- EE controls the USW-Pro-XG-8-PoE again after the switch updates itself to UniFi firmware 7.6.11+17272, which Ubiquiti released on November 23. EE refused that firmware because it accepted only 7.5.15+17146 for this model. The new firmware keeps the port LED controller firmware unchanged and changes the program that receives lighting commands. EE accepts it on the Pro XG 8 PoE only, and only while the switch reports exactly the lighting commands and options EE was verified with; any difference keeps EE from controlling the lighting and names the difference. The Pro HD 24, Pro HD 24 PoE and Pro XG 10 PoE still need 7.5.15+17146. `docs/HARDWARE-QUALIFICATION.md` describes the evidence and its limits.
Expand Down
26 changes: 24 additions & 2 deletions desktop/EtherlightingEvolved.Native.Check/Checks/ModelChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3330,13 +3330,35 @@ static void PortAnimationChecks()
}
e(ok && frames.Delay <= 500);
});
T("port animation: slow confirmed colors reach the next paint and fast playback resumes", e =>
{
var frames = new ColorFrames();
var time = 0;
var level = 0;
frames.Push(Colors(("1", new double[] { 0, 0, 0 })), time);
foreach (var gap in new[] { 323, 407, 502, 132, 627, 800, 1200 })
{
time += gap;
var color = new double[] { ++level, 0, 0 };
frames.Push(Colors(("1", color)), time);
e(frames.Sample(time)["1"].SequenceEqual(color) && frames.Sample(time + 30)["1"].SequenceEqual(color), "latest confirmed color");
}
for (var i = 0; i < 10; i++)
{
time += 40;
frames.Push(Colors(("1", new double[] { level + i + 1, 0, 0 })), time);
var shown = frames.Sample(time)["1"][0];
e(shown >= level && shown <= level + i + 1, "resume from confirmed color");
}
e(frames.Delay == 120, "fast arrival cadence restored");
});
T("port animation: cadence evidence expires after interruption and stale output holds exactly", e =>
{
var frames = new ColorFrames();
for (var time = 0; time <= 1600; time += 400) frames.Push(new Dictionary<int, double[]> { [1] = [time / 10.0, 0, 0] }, time);
e(frames.Delay == 450 && frames.Sample(5000)["1"].SequenceEqual([160, 0, 0]) && frames.Sample(6000)["1"].SequenceEqual([160, 0, 0]), "held");
e(frames.Delay == 0 && frames.Sample(5000)["1"].SequenceEqual([160, 0, 0]) && frames.Sample(6000)["1"].SequenceEqual([160, 0, 0]), "held");
frames.Push(new Dictionary<int, double[]> { [1] = [0, 255, 0] }, 10000);
e(frames.Delay == 120 && frames.Sample(11000)["1"].SequenceEqual([0, 255, 0]), "expired");
e(frames.Delay == 0 && frames.Sample(10000)["1"].SequenceEqual([0, 255, 0]), "expired");
frames.Push(new Dictionary<int, double[]> { [1] = [255, 255, 255] }, 9999);
e(frames.Latest()["1"].SequenceEqual([0, 255, 0]), "older frame ignored");
});
Expand Down
23 changes: 15 additions & 8 deletions desktop/EtherlightingEvolved.Native/Core/Model/PortAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public sealed record Frame(double Time, Dictionary<string, double[]> Colors);

static double Clamp(double value, double low, double high) => Math.Max(low, Math.Min(high, value));

const double SlowFrameMs = 300;

public ColorFrames(double delay = 120)
{
MinimumDelay = Clamp(double.IsFinite(delay) ? delay : 120, 0, 500);
Expand Down Expand Up @@ -79,18 +81,23 @@ public bool Push(IEnumerable<KeyValuePair<string, object?>> colors, double time)
if (previous is not null)
{
var interval = time - previous.Time;
if (interval <= 1000)
if (interval > 1000) Intervals.Clear();
Intervals.Add(interval);
if (Intervals.Count > 24) Intervals.RemoveAt(0);
var recentCount = Math.Min(Intervals.Count, 3);
var slowCount = Intervals.TakeLast(recentCount).Count(gap => gap >= SlowFrameMs);
// Ignore a lone stall in a fast stream. Resume interpolation after three timely arrivals.
if (slowCount * 2 > recentCount || (Delay == 0 && slowCount > 0))
{
Intervals.Add(interval);
if (Intervals.Count > 24) Intervals.RemoveAt(0);
Delay = Clamp(Intervals.Max() + 50, MinimumDelay, 500);
Delay = 0;
Frames.Clear();
playback = time;
sampledAt = time;
}
else
{
Intervals.Clear();
Delay = MinimumDelay;
playback = null;
sampledAt = null;
var timely = Intervals.Where(gap => gap < SlowFrameMs);
Delay = Clamp(timely.Max() + 50, MinimumDelay, 500);
}
}
Frames.Add(new Frame(time, decoded));
Expand Down
26 changes: 17 additions & 9 deletions preview/port-animation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export function smoothColor(previous, target, elapsed) {

export const portInk = () => '#ffffff';

// Buffer confirmed frames; slow arrivals never grant permission to predict output.
// Below about three updates per second, show confirmed colors on arrival.
const SLOW_FRAME_MS = 300;
export class ColorFrames {
constructor(delay = 120) {
this.minimumDelay = clamp(Number.isFinite(delay) ? delay : 120, 0, 500);
Expand All @@ -41,14 +42,20 @@ export class ColorFrames {
if (!decoded) return false;
if (previous) {
const interval = time - previous.time;
if (interval <= 1000) {
this.intervals.push(interval);
if (this.intervals.length > 24) this.intervals.shift();
this.delay = clamp(Math.max(...this.intervals) + 50, this.minimumDelay, 500);
if (interval > 1000) this.intervals.length = 0;
this.intervals.push(interval);
if (this.intervals.length > 24) this.intervals.shift();
const recent = this.intervals.slice(-3);
const slowCount = recent.filter(gap => gap >= SLOW_FRAME_MS).length;
// Ignore a lone stall in a fast stream. Resume interpolation after three timely arrivals.
if (slowCount > recent.length / 2 || (this.delay === 0 && slowCount > 0)) {
this.delay = 0;
this.frames.length = 0;
this.playback = time;
this.sampledAt = time;
} else {
this.intervals.length = 0;
this.delay = this.minimumDelay;
this.playback = null; this.sampledAt = null;
const timely = this.intervals.filter(gap => gap < SLOW_FRAME_MS);
this.delay = clamp(Math.max(...timely) + 50, this.minimumDelay, 500);
}
}
this.frames.push({time, colors: decoded});
Expand Down Expand Up @@ -140,7 +147,8 @@ export function createPortAnimator(getElement, environment = globalThis, {onPain
if (!element?.isConnected) { element = getElement(Number(port)); if (element) elements.set(port, element); }
if (!element) continue;
const previous = displayed.get(port);
const color = reducedMotion.matches ? target : smoothColor(previous, target, elapsed);
const live = !preview || !previewPorts.includes(port);
const color = reducedMotion.matches || (live && frames.delay === 0) ? target : smoothColor(previous, target, elapsed);
const css = rgbCss(color);
const prior = painted.get(element);
const ink = portInk();
Expand Down
2 changes: 1 addition & 1 deletion preview/profile-preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function createProfilePreviews(initialState, environment = globalThis) {
if (!visible.has(item.element)) continue;
const colors=item.active ? live : profileColors(item.scene,state,time,item.animation);
for (const [id,bar] of item.bars) {
const target=colors[id] || [0,0,0], color=motion.matches ? target : smoothColor(item.colors.get(id),target,elapsed), css=rgbCss(color);
const target=colors[id] || [0,0,0], color=motion.matches || (item.active && frames.delay===0) ? target : smoothColor(item.colors.get(id),target,elapsed), css=rgbCss(color);
if (item.styles.get(id)!==css) {bar.style.backgroundColor=css;item.styles.set(id,css);}
item.colors.set(id,color);
}
Expand Down
42 changes: 34 additions & 8 deletions tests/port-animation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,35 @@ test('a late sample changes playback pace without rewinding or jumping ahead', (
test('cadence evidence expires after interruption and stale output holds exactly', () => {
const frames = new ColorFrames();
for (let time = 0; time <= 1600; time += 400) frames.push({1: [time / 10, 0, 0]}, time);
assert.equal(frames.delay, 450);
assert.equal(frames.delay, 0);
assert.deepEqual(frames.sample(5000), {1: [160, 0, 0]});
assert.deepEqual(frames.sample(6000), {1: [160, 0, 0]});
frames.push({1: [0, 255, 0]}, 10000);
assert.equal(frames.delay, 120);
assert.deepEqual(frames.sample(11000), {1: [0, 255, 0]});
assert.equal(frames.delay, 0);
assert.deepEqual(frames.sample(10000), {1: [0, 255, 0]});
frames.push({1: [255, 255, 255]}, 9999);
assert.deepEqual(frames.latest(), {1: [0, 255, 0]});
});

test('slow confirmed colors reach the next paint and fast playback resumes without replaying old colors', () => {
const frames = new ColorFrames();
let time = 0, level = 0;
frames.push({1: [0, 0, 0]}, time);
for (const gap of [323, 407, 502, 132, 627, 800, 1200]) {
time += gap;
frames.push({1: [++level, 0, 0]}, time);
assert.deepEqual(frames.sample(time)[1], [level, 0, 0]);
assert.deepEqual(frames.sample(time + 30)[1], [level, 0, 0]);
}
for (let i = 0; i < 10; i++) {
time += 40;
frames.push({1: [level + i + 1, 0, 0]}, time);
const shown = frames.sample(time)[1][0];
assert.ok(shown >= level && shown <= level + i + 1);
}
assert.equal(frames.delay, 120);
});

test('neutral port labels retain 4.5 contrast in every theme through lighting colors and selection', async () => {
const [css, palettes] = await Promise.all(['style.css','themes.css'].map(name => readFile(new URL('../preview/'+name, import.meta.url), 'utf8')));
const channels = hex => {assert.match(hex,/^#[\da-f]{6}(?:[\da-f]{2})?$/i);return [1,3,5].map(offset=>parseInt(hex.slice(offset,offset+2),16));};
Expand Down Expand Up @@ -155,13 +174,20 @@ test('ambient feedback receives the displayed frame and follows the animator lif
animator.pushFrame({1:'#0011ff',8:'#ff22aa'},0); mock.flush(10);
animator.pushFrame({1:'#ffaa00',8:'#aa33ff'},400); mock.flush(500);
assert.equal(samples.length,2);
assert.equal(styles.get('1'), rgbCss([255,170,0]));
assert.equal(styles.get('8'), rgbCss([170,51,255]));
animator.setPreview(() => ({1:'#000000'}));
mock.flush(508);
assert.equal(styles.get('1'), rgbCss(smoothColor([255,170,0], [0,0,0], 8)));
assert.equal(styles.get('8'), rgbCss([170,51,255]));
animator.stop(); mock.flush(510);
assert.equal(samples.length,2);
mock.motion(true); animator.pushFrame({1:'#ffffff',8:'#ffffff'},600); mock.flush(610);
assert.equal(samples.length,3);
animator.setPreview(null);
mock.motion(true); animator.pushFrame({1:'#ffffff',8:'#ffffff'},600); mock.flush(610);
assert.equal(samples.length,4);
assert.equal(mock.queue.size,0);
animator.dispose(); mock.flush(620);
assert.equal(samples.length,3);
assert.equal(samples.length,4);
});

test('optional feedback failure cannot interrupt port playback', () => {
Expand Down Expand Up @@ -251,7 +277,7 @@ test('a failing preview yields to confirmed output and is not retried on each fr
assert.equal(styles.get('--port-color'), rgbCss([255, 0, 0]));
assert.equal(mock.queue.size, 1);
for (const time of [30, 50, 70]) mock.flush(time);
animator.pushFrame({1: '#00ff00'}, 1000); mock.flush(2000);
animator.pushFrame({1: '#00ff00'}, 200); mock.flush(2000);
assert.equal(calls, 1, 'a broken draft must not throw again on every paint or telemetry update');
assert.deepEqual(mock.warnings, ['Port preview failed; showing confirmed lighting.']);
assert.equal(styles.get('--port-color'), rgbCss(smoothColor([255, 0, 0], [0, 255, 0], 80)));
Expand Down Expand Up @@ -290,7 +316,7 @@ test('a draft that fails after painting returns to confirmed color without blend
const preview = () => { calls++; if (broken) throw new Error('invalid changed draft'); return {1: '#00ff00'}; };
animator.setPreview(preview); animator.pushFrame({1: '#00aaff', 8: '#ff0000'}, 0); mock.flush(10);
assert.equal(styles.get(1), rgbCss([0, 255, 0]));
broken = true; animator.pushFrame({1: '#00aaff', 8: '#0000ff'}, 1000); mock.flush(2000);
broken = true; animator.pushFrame({1: '#00aaff', 8: '#0000ff'}, 200); mock.flush(2000);
assert.equal(styles.get(1), rgbCss([0, 170, 255]));
assert.equal(styles.get(8), rgbCss(smoothColor([255, 0, 0], [0, 0, 255], 80)), 'unrelated live ports retain their interpolation');
mock.flush(2010); assert.equal(calls, 2);
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fan_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ async def unreachable():
raise UnreachableError("fixture: the switch cannot be reached")

monkeypatch.setattr(switch, "connect", unreachable)
await switch.close()
engine.connected = False
with pytest.raises(UnreachableError):
await engine.switch.connect()
await asyncio.sleep(0)


Expand Down
Loading