Borg Assimilation
Singleton:
window.lcards.core.borgAssimilationManagerClass:BorgAssimilationManager(src/core/borg/BorgAssimilationManager.js), extendsBaseServiceConsole API:window.lcards.borg.*(src/lcards-main.js:735-739) User docs: Borg Assimilation (options, layers, examples) and Borg actions
Overview
BorgAssimilationManager runs the Borg assimilation Easter egg on one browser: it swaps the palette to the borg_alert alert mode, swaps the LCARS font for the Borg typeface, plays the borg-assimilation screen effect as an intro until it is dismissed, then leaves persistent screen effects on the page. deassimilate() plays an outro and reverts all of it, returning the palette to the alert mode that was active before.
It is an orchestrator only. The work is done by:
| Step | Done by |
|---|---|
| Palette | ThemeManager.setAlertMode('borg_alert', { transitionStyle }) and the borg_alert transform in src/core/themes/alertModeTransform.js |
| Palette hue | setAlertModeTransformParameter() / getAlertModeTransform() / resetAlertModeTransform() (alertModeTransform.js) |
| Font | injectBorgFont() / revertBorgFont() (src/core/themes/borgFontAssimilation.js) |
| Intro, persistent and outro effects | ScreenEffectManager (apply, applySlot, clearSlot, clear) and the borg-assimilation preset (src/core/screen-effects/effects/BorgAssimilationEffect.js) |
| Sounds | SoundManager.play() / playSource() |
This page describes how it works. What each option does, with examples, is in the user docs; they are not repeated here.
Location and setup
| What | Where |
|---|---|
| Class | src/core/borg/BorgAssimilationManager.js |
| Created | LCARdSCore._performInitialization(), src/core/lcards-core.js:300, right after ScreenEffectManager, and assigned to window.lcards.core.borgAssimilationManager at once (:301) |
| HASS | none: core does not call its updateHass() |
| State | _assimilated (isAssimilated getter), _introDismiss (the pending intro's dismiss function), _fontWasSwapped, _priorAlertMode (the alert mode to return to) |
Who calls it:
| Caller | How |
|---|---|
| Console | window.lcards.borg.assimilate(opts), .deassimilate(opts), .status; window.lcards.alert.borg(opts) is a shortcut for assimilate (src/lcards-main.js:724) |
lcards.borg_assimilate / lcards.borg_deassimilate actions | custom_components/lcards/services.py (handle_borg_assimilate, handle_borg_deassimilate) fires a targeted lcards_event; IntegrationService._handleLcardsEvent() (src/core/services/IntegrationService.js:549-581) maps the payload to options (below) |
| Connection overlay, Borg mode | ConnectionOverlayService._onDisconnected() calls assimilate(borgOptsFromLayers(message.borgLayers)) after the disconnect tolerance; _doReconnected() calls deassimilate() (see Disconnect tolerance) |
| Connectivity tab, Test button | src/panels/components/lcards-connectivity-tab.js uses the same borgOptsFromLayers() |
Action payload to options
handle_borg_assimilate normalises the action fields before they reach the browser: the flat shortcuts (site_count, tendrils_per_site, tendril_length, particle_count, renderer, corruption, overrun, cube) become intro_layers.canvas params (snake_case keys in intro_layers.canvas are converted to camelCase, and win on overlap); cube: none | detailed | classic becomes cube: false or cube: true plus cubeStyle; suppress_persistent becomes persistent_layers: {} unless persistent_layers is set; font_swap is sent as fontSwap and palette_hue as paletteHue. IntegrationService then maps:
| Payload key | assimilate() option |
|---|---|
intro_duration | duration |
transition_style | transitionStyle |
intro_layers | intro |
persistent_layers | persistentLayers |
fontSwap | fontSwap |
paletteHue | paletteHue |
sound | sound |
| Payload key | deassimilate() option |
|---|---|
with_outro | withOutro |
outro_layers | outroLayers |
revert_transition_style | revertTransitionStyle |
sound | sound |
paletteHue is set by the action (palette_hue), the console API and the connection overlay (message.borgLayers.paletteHue).
assimilate() flow
assimilate(opts) (BorgAssimilationManager.js:151-266):
- Guard. A second call while assimilated logs a warning and returns, so the alert mode recorded by the first call is kept.
- Prior alert mode.
_priorAlertMode = themeManager.getAlertMode(), read before theborg_alertswap (nullwithout a ThemeManager). - Sound.
playBorgSound('borg_assimilate', sound)(:80-85):soundas a string plays throughsoundManager.playSource(sound, 'borg_assimilate')(asset key,media-source://id or URL; the master switch and thealertscategory apply, the scheme does not);'none'ornullis silent; left out,soundManager.play('borg_assimilate')resolves it through overrides and the scheme (the default scheme maps it to nothing). - Palette hue. With
paletteHueset, the runtimeborg_alerttransform getshueShiftandhueAnchor.centerHueset to it (the rest ofhueAnchorkept). The built-inborg_alerttransform is hue 110, strength 0.95, saturation x0.65, lightness x0.72, anchor range 35 (alertModeTransform.js:101-113). - Palette and font start together, not awaited yet:
ThemeManager.setAlertMode('borg_alert', { transitionStyle })(defaultblur_fade) and, unlessfontSwap: false,injectBorgFont(). The palette change is local to this browser:ThemeManager.setAlertMode()never writesinput_select.lcards_alert_mode(that iswindow.lcards.setAlertMode()'s job). - Intro. Skipped when
borgIntroSupported()is false (noHTMLCanvasElement.transferControlToOffscreenor noWorker), because an intro that cannot draw would still take every click. Otherwise:- The intro layers are
{ ...DEFAULTS.intro, ...intro }, withcanvasmerged key by key over the default canvas params. Abackdroporcolorleft out ofintrokeeps its default; passnullto drop it. - The canvas always plays
borg-assimilationviasem.apply(): anypresetinintro.canvasis removed and ignored. backdropandcolorlayers with apresetgo throughsem.applySlot().- The canvas slot element (
[data-lcards-se-slot="canvas"]insem.portal) getspointer-events: autoand a click listener. The method waits on a promise resolved by that click, bydurationms whenduration > 0, or bydeassimilate()through the stored_introDismiss. - Then all three slots are cleared.
- The intro layers are
- Wait for the palette and font promises (
Promise.allSettled, so a failed font load does not stop the sequence). - Persistent layers. If
deassimilate()ran in the meantime, stop here. Otherwise every layer ofpersistentLayers ?? DEFAULTS.persistentLayerswith apresetis applied withsem.applySlot().{}applies nothing.
The defaults (DEFAULTS, :38-71):
| Stage | Default |
|---|---|
intro.canvas | siteCount: 8, tendrilsPerSite: 5, tendrilLength: 600, particleCount: 2, color: 'var(--lcars-martian)', glowColor: 'var(--lcards-yellow)' (the rest from the preset's own defaults, see Screen Effect System) |
intro.backdrop | saturate, amount: '200%' |
intro.color | color-tint, rgba(0,60,0,0.25) |
persistentLayers | canvas glitch (intensity: 0.08, maxShift: 400, bandHeight: 3, fps: 20), color color-tint rgba(0, 60, 0, 0.10), backdrop saturate 200% |
outroLayers | canvas glitch (duration: 1200, intensity: 0.4, opacity: 0.7) |
outroDuration | 1200 ms |
deassimilate() flow
deassimilate(opts) (:287-350):
- Guard. Not assimilated: warning, return.
_assimilated = falsefirst, so anassimilate()still waiting on its intro skips its persistent layers.- A pending intro is dismissed at once through
_introDismiss(). - Sound:
playBorgSound('borg_deassimilate', sound). - Outro (unless
withOutro: false): every layer ofoutroLayers ?? DEFAULTS.outroLayerswith apresetis applied withsem.applySlot(), then the method waitsMath.max(1200, ...layer.duration)ms:outroDurationis a minimum. Thedurationkey also reaches the preset as a param; the outro slots are not timed by SEM and stay until step 7. - Palette:
resetAlertModeTransform('borg_alert')drops anypaletteHue, thenThemeManager.setAlertMode(mode, { transitionStyle: revertTransitionStyle })(defaultfade_only), wheremodeis_priorAlertMode, the alert mode active whenassimilate()started. It isgreen_alertwhen none was recorded (no ThemeManager, an empty value) or when the recorded mode is itself a Borg alert (its name containsborg)._priorAlertModeis reset, so the next assimilation records afresh. - Font (only if it was swapped):
revertBorgFont()removes the<style id="lcards-borg-font-override">. Effects:sem.clear()clears every slot, including effects started separately (atrigger_effect).
Font swap
injectBorgFont() (src/core/themes/borgFontAssimilation.js:25-49) loads the lcards_borg font through assetManager.loadFont('lcards_borg'), then appends one <style id="lcards-borg-font-override"> to document.head:
:root {
--lcars-font: 'lcards_borg', monospace !important;
--lcars-fallback-font: 'lcards_borg', monospace !important;
}!important beats the HA-LCARS theme's own values. Text in a font other than these two variables keeps its font. The call is idempotent (one style tag at most); revertBorgFont() removes it.
loadFont() only links the stylesheet, and the face downloads when text is first drawn in it. When the overlay assimilates on a disconnect, neither can be fetched, so its warm-up downloads the font and the intro chunk beforehand (Connection Overlay: Warm-up). An assimilate() from an action or the console runs while connected and needs none of that.
Disconnect tolerance
In the connection overlay's Borg mode (message.mode: 'borg'), assimilation is the "connection lost" display. ConnectionOverlayService._onDisconnected() (src/core/services/ConnectionOverlayService.js:700-758) treats it exactly like the standard overlay:
- It waits
disconnect_delay_ms(default 2500) first. If the connection is back before the timer fires, nothing is shown:_doReconnected()cancels the timer, and the timer callback also checks_isDisconnected. - Then
activate()callsborgAssimilationManager.assimilate(borgOptsFromLayers(message.borgLayers)). borgOptsFromLayers()(ConnectionOverlayService.js:165-172) splitsborgLayers:paletteHue(only when not null) andfontSwap(defaulttrue) become options, everything else (canvas,backdrop,color) becomesintro. The Test button in the connectivity tab uses the same function, so the test and a real disconnect honour the same settings.- Reconnects go through the same 1 second debounce as the standard overlay (
_onReconnected()), so a flapping connection during a Home Assistant restart does not assimilate and restore repeatedly._doReconnected()then callsdeassimilate()only whenisAssimilatedis true, and thereconnectedbanner is not used in this mode.
See Connection Overlay System.
API
| Member | Returns | Description |
|---|---|---|
assimilate(opts?) | Promise<void> | Run the sequence above. Resolves after the persistent layers are applied (or skipped). |
deassimilate(opts?) | Promise<void> | Revert. Resolves after the font and effects are cleared. |
isAssimilated | boolean | True from the start of assimilate() until the start of deassimilate(). |
assimilate() options: duration (ms, 0 = click only), transitionStyle (flash, fade_only, blur_fade, off; default blur_fade), intro, persistentLayers, paletteHue (0 to 359, default null), fontSwap (default true), sound. deassimilate() options: withOutro (default true), outroLayers, revertTransitionStyle (default fade_only), sound. Layer maps use the trigger_effect shape { slot: { preset, ...params } }. Full tables: Borg Assimilation, Console API.
Debugging
The manager has no getDebugInfo(). Use:
window.lcards.borg.status // true while assimilated
window.lcards.borg.assimilate({ duration: 5000, fontSwap: false })
window.lcards.borg.deassimilate({ withOutro: false })
window.lcards.core.themeManager.currentAlertMode // 'borg_alert' while assimilated
document.getElementById('lcards-borg-font-override') // the font style tag, or null
window.lcards.core.screenEffectManager._slots // which SEM slots are activeThe intro draws on its own canvas, inserted right after the SEM canvas slot with pointer-events: none (so the click still reaches the slot); that canvas carries data-lcards-renderer (webgl or canvas), which tells which worker draws it (BorgAssimilationEffect.js:89-111). Logs are tagged [BorgAssimilationManager] and [BorgFont].
See also
- Borg Assimilation and Borg actions: the user docs
- Screen Effect System: the
borg-assimilationpreset and its renderers - Connection Overlay System: Borg mode on disconnect
- Theme System: alert modes and palette transforms
- Sound System: the
borg_assimilate/borg_deassimilateevents