From 5f986fb9bdbaf05b22cf4a97b616cd2c1a119ee4 Mon Sep 17 00:00:00 2001 From: Gh61 Date: Wed, 22 Nov 2023 21:16:16 +0100 Subject: [PATCH] style(braces): stroustrup --- .eslintrc.json | 1 + src/controls/big-switch.ts | 3 +- src/controls/brightness-rollup.ts | 12 ++++-- src/controls/color-temp-mode-selector.ts | 3 +- src/controls/color-temp-picker.ts | 39 ++++++++++++------- src/controls/dialog-light-tile.ts | 3 +- src/controls/dialog-scene-tile.ts | 8 +++- src/controls/dialog.ts | 27 ++++++++----- src/controls/history-state-manager.ts | 21 +++++++---- src/controls/light-detail.ts | 21 +++++++---- src/controls/pointer-drag-helper.ts | 3 +- src/core/action-handler.ts | 3 +- src/core/colors/background.ts | 6 ++- src/core/colors/color-extended.ts | 3 +- src/core/colors/color.ts | 48 ++++++++++++++++-------- src/core/effect-queue.ts | 4 +- src/core/error-info.ts | 6 ++- src/core/global-lights.ts | 3 +- src/core/hass-text-template.ts | 9 +++-- src/core/icon-helper.ts | 9 +++-- src/core/light-container.ts | 18 ++++++--- src/core/light-controller.ts | 15 +++++--- src/core/light-features.ts | 3 +- src/core/view-utils.ts | 12 ++++-- src/hue-like-light-card.ts | 17 ++++++--- src/localize/localize.ts | 3 +- src/types/config.ts | 14 +++++-- src/types/theme-helper.ts | 6 ++- src/types/types-config.ts | 9 +++-- 29 files changed, 222 insertions(+), 107 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 809cdd8..86c43b1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,6 +29,7 @@ "@typescript-eslint/lines-between-class-members": "off", "@typescript-eslint/keyword-spacing": ["error", {"overrides": { "this": { "before": false }}}], "@typescript-eslint/explicit-member-accessibility": "error", + "@typescript-eslint/brace-style": ["error", "stroustrup"], "react/jsx-filename-extension": "off", "import/extensions": "off", diff --git a/src/controls/big-switch.ts b/src/controls/big-switch.ts index 630e467..f34e65e 100644 --- a/src/controls/big-switch.ts +++ b/src/controls/big-switch.ts @@ -99,7 +99,8 @@ export class HueBigSwitch extends LitElement { this.checked = !this.reversed; fireEvent(this, 'change'); }); - } else { + } + else { this._mc.on('swiperight', () => { if (this.disabled) return; this.checked = !this.reversed; diff --git a/src/controls/brightness-rollup.ts b/src/controls/brightness-rollup.ts index 9df9d91..cbaa940 100644 --- a/src/controls/brightness-rollup.ts +++ b/src/controls/brightness-rollup.ts @@ -162,7 +162,8 @@ export class HueBrightnessRollup extends LitElement { private onBarMouseDown(ev: MouseEvent | TouchEvent, isTouch: boolean) { if (isTouch) { this._clickPosition = new TouchPoint((ev).changedTouches[0]); - } else { + } + else { this._clickPosition = new MousePoint((ev)); } @@ -185,7 +186,8 @@ export class HueBrightnessRollup extends LitElement { if (this._isMouseDown) { if (!this._hasMouseMoved) { this.toggleBar(!this._isOpened, false); - } else { + } + else { this.toggleBar(false, true); } } @@ -207,7 +209,8 @@ export class HueBrightnessRollup extends LitElement { let currentPos: Point; if (isTouch) { currentPos = new TouchPoint((ev).changedTouches[0]); - } else { + } + else { currentPos = new MousePoint(ev); } @@ -408,7 +411,8 @@ export class HueBrightnessRollup extends LitElement { this.clearWheelTimeouts(false); this.disconnectListeners(); this.toggleBar(false, true); // close bar - } else { + } + else { // enable back this.connectListeners(); } diff --git a/src/controls/color-temp-mode-selector.ts b/src/controls/color-temp-mode-selector.ts index 0aa028e..9807d89 100644 --- a/src/controls/color-temp-mode-selector.ts +++ b/src/controls/color-temp-mode-selector.ts @@ -43,7 +43,8 @@ export class HueColorTempModeSelector extends LitElement { public selectPossibleMode() { if (this.showColor) { this.mode = 'color'; - } else if (this.showTemp) { + } + else if (this.showTemp) { this.mode = 'temp'; } } diff --git a/src/controls/color-temp-picker.ts b/src/controls/color-temp-picker.ts index c841bc3..a7cbc57 100644 --- a/src/controls/color-temp-picker.ts +++ b/src/controls/color-temp-picker.ts @@ -25,7 +25,8 @@ class HueColorWheelCache { const dataUrl = canvas.toDataURL(); // we're using dataUrl, because in raw format, the image exceeds localStorage size limit try { localStorage.setItem(key, dataUrl); - } catch (e) { + } + catch (e) { console.error(e); } } @@ -40,7 +41,8 @@ class HueColorWheelCache { dataUrl }; } - } catch (e) { + } + catch (e) { console.error(e); } @@ -82,7 +84,8 @@ export class HueColorTempPicker extends LitElement { // if browser (or test engine) not support ResizeObserver if (typeof ResizeObserver == 'undefined') { this._ro = null; - } else { + } + else { this._ro = new ResizeObserver(() => this.onResize()); } } @@ -182,7 +185,8 @@ export class HueColorTempPicker extends LitElement { }; img.src = cacheItem.dataUrl!; - } else { + } + else { const image = ctx.createImageData(2 * radius, 2 * radius); const data = image.data; @@ -232,7 +236,8 @@ export class HueColorTempPicker extends LitElement { let point; if ('changedTouches' in ev) { point = new TouchPoint(ev.changedTouches[0]); - } else { + } + else { point = new MousePoint(ev); } @@ -256,7 +261,8 @@ export class HueColorTempPicker extends LitElement { public getColorAndValue(x: number, y: number, radius: number) { if (this.mode == 'color') { return this.getColorAndHSV(x, y, radius); - } else if (this.mode == 'temp') { + } + else if (this.mode == 'temp') { return this.getTempAndKelvin(x, y, radius); } @@ -405,9 +411,11 @@ export class HueColorTempPicker extends LitElement { const coef = (max / min) / 65; if (t <= 0.1) { addon = this.linearScale(t * 10, 0, coef); - } else if (t <= 0.97) { + } + else if (t <= 0.97) { addon = coef - this.linearScale((t - 0.1) / 0.9, 0, 2 * coef); - } else { + } + else { addon = -coef + this.linearScale((t - 0.97) / 0.03, 0, coef); } @@ -431,7 +439,8 @@ export class HueColorTempPicker extends LitElement { if (midValue < targetValue) { low = t; - } else { + } + else { high = t; } @@ -523,7 +532,8 @@ export class HueColorTempPicker extends LitElement { offset = maxOffset - offset; if (lower) { value -= offset / 360; - } else { + } + else { value += offset / 360; } } @@ -699,7 +709,8 @@ export class HueColorTempPickerMarker { if ('hsv' in colorAndValue) { const [hue, saturation, value] = colorAndValue.hsv; this._color = new Color(hue, saturation, value, 1, 'hsv'); - } else { + } + else { const [red, green, blue] = colorAndValue.color; this._color = new Color(red, green, blue); } @@ -745,7 +756,8 @@ export class HueColorTempPickerMarker { public refresh() { if (this.mode == 'temp') { this.temp = this.temp; - } else { + } + else { this.color = this.color; } } @@ -861,7 +873,8 @@ export class HueColorTempPickerMarker { if (this._isOff) { this._markerG.style.color = 'rgb(0,0,0)'; this._iconPath.style.fill = Consts.LightColor.toString(); - } else { + } + else { this._markerG.style.color = this._color.toString(); // for temp view I want only one change of foreground in the middle of the wheel diff --git a/src/controls/dialog-light-tile.ts b/src/controls/dialog-light-tile.ts index 106640f..95af8c1 100644 --- a/src/controls/dialog-light-tile.ts +++ b/src/controls/dialog-light-tile.ts @@ -140,7 +140,8 @@ export class HueDialogLightTile extends HueDialogTile { bfg.foreground.toString() ); } - } else { + } + else { this.style.removeProperty( '--hue-light-background' ); diff --git a/src/controls/dialog-scene-tile.ts b/src/controls/dialog-scene-tile.ts index 11b5ad1..990ecb3 100644 --- a/src/controls/dialog-scene-tile.ts +++ b/src/controls/dialog-scene-tile.ts @@ -58,8 +58,12 @@ export class HueDialogSceneTile extends HueDialogTile { const animationMs = (HueDialogSceneTile.animationSeconds * 1000); this._effectQueue.addEffect(0, () => sceneElement.classList.add('clicked')); this._effectQueue.addEffect(3000, () => sceneElement.classList.add('unclicked')); - this._effectQueue.addEffect(animationMs, () => { sceneElement.classList.add('stop-color-animate'); sceneElement.classList.remove('clicked'); }); - this._effectQueue.addEffect(50, () => { sceneElement.classList.remove('stop-color-animate', 'unclicked'); }); + this._effectQueue.addEffect(animationMs, () => { + sceneElement.classList.add('stop-color-animate'); sceneElement.classList.remove('clicked'); + }); + this._effectQueue.addEffect(50, () => { + sceneElement.classList.remove('stop-color-animate', 'unclicked'); + }); this._effectQueue.start(); } diff --git a/src/controls/dialog.ts b/src/controls/dialog.ts index 0d376e7..888df7d 100644 --- a/src/controls/dialog.ts +++ b/src/controls/dialog.ts @@ -92,7 +92,8 @@ export class HueDialog extends IdLitElement { this._lightDetailHistoryStep = new HueHistoryStep(show, hide, HueLightDetail.ElementName); HueHistoryStateManager.instance.addStep(this._lightDetailHistoryStep); - } else if (this._selectedLight == ev.detail.lightContainer) { + } + else if (this._selectedLight == ev.detail.lightContainer) { this.hideLightDetail(); } } @@ -118,7 +119,8 @@ export class HueDialog extends IdLitElement { if (show) { contentDiv.style.overflowY = 'hidden'; contentDiv.scrollBy({ top: contentDiv.scrollHeight, behavior: 'smooth' }); - } else { + } + else { contentDiv.style.overflowY = ''; } } @@ -160,7 +162,8 @@ export class HueDialog extends IdLitElement { if (isBefore) { tileScroller.scrollBy({ left: elStart - tileScrollerStart, behavior: 'smooth' }); - } else { + } + else { tileScroller.scrollBy({ left: elEnd - tileScrollerEnd, behavior: 'smooth' }); } } @@ -201,7 +204,8 @@ export class HueDialog extends IdLitElement { const haRoot = haDom.length ? haDom[0].shadowRoot : null; if (haRoot) { haRoot.appendChild(this); - } else { + } + else { document.body.appendChild(this); } @@ -218,7 +222,8 @@ export class HueDialog extends IdLitElement { if (haDialog) { // if dialog closed - will call onDialogClose event haDialog.close(); - } else { + } + else { // no haDialog found - use legacy way this.onDialogClose(); } @@ -517,7 +522,8 @@ export class HueDialog extends IdLitElement { this._lightDetailElement = detailElement; } - } else if (throwError) { + } + else if (throwError) { throw new Error('Cannot create backdrop and lightDetail. Surface not found.'); } } @@ -563,10 +569,12 @@ export class HueDialog extends IdLitElement { const offColor = this._config.getOffColor(); if (!offColor.isThemeColor()) { offBackground = new Background([offColor.getBaseColor()]); - } else { + } + else { offBackground = null; } - } else { + } + else { offBackground = new Background([new Color(Consts.DialogOffColor)]); } @@ -594,7 +602,8 @@ export class HueDialog extends IdLitElement { '--hue-text-color', bfg.foreground.toString() ); - } else { + } + else { this.style.removeProperty('--hue-text-color'); } } diff --git a/src/controls/history-state-manager.ts b/src/controls/history-state-manager.ts index 7aca63f..f90fb63 100644 --- a/src/controls/history-state-manager.ts +++ b/src/controls/history-state-manager.ts @@ -208,7 +208,8 @@ class HistoryStack { this._pointer = i; found = true; break; - } else { + } + else { // not found, but is on the path - should be exited toExit.push(item); } @@ -216,7 +217,8 @@ class HistoryStack { if (!found) { // clear items toExit.length = 0; - } else { + } + else { this.logState('Moved to ' + id); return { found, @@ -243,7 +245,8 @@ class HistoryStack { // clear items toEnter.length = 0; logMessage('NOT moved to ' + id); - } else { + } + else { this.logState('Moved to ' + id); } @@ -305,16 +308,19 @@ export class HueHistoryStateManager { // move to the current state moveResult = this._states.moveTo(state.hueId); - } else if (state != null) { + } + else if (state != null) { moveResult = this._states.moveToExternal(state); if (!moveResult.found) { // our stack is ruined, reset everything moveResult = this._states.resetBeforeStart(); - } else { + } + else { // don't fire any functions moveResult.found = false; } - } else { + } + else { // we're at the very beginning moveResult = this._states.resetBeforeStart(); } @@ -377,7 +383,8 @@ export class HueHistoryStateManager { // save oldItem's position into newItem newStep.position = replaceResult.oldItem?.position; - } else { // replace not possible, classic push + } + else { // replace not possible, classic push // push it to stack this._states.push(newStep); diff --git a/src/controls/light-detail.ts b/src/controls/light-detail.ts index 6864ee6..dab7480 100644 --- a/src/controls/light-detail.ts +++ b/src/controls/light-detail.ts @@ -64,7 +64,8 @@ export class HueLightDetail extends IdLitElement { if (lightFeatures.isOnlyBrightness()) { this._modeSelector.mode = 'brightness'; this.toggleFullSizedBrightness(true); - } else { + } + else { this._modeSelector.selectPossibleMode(); this.toggleFullSizedBrightness(false); } @@ -93,7 +94,8 @@ export class HueLightDetail extends IdLitElement { if (this.lightContainer.color) { this._colorMarker.color = this.lightContainer.color; } - } else if (this.lightContainer.isColorModeTemp()) { + } + else if (this.lightContainer.isColorModeTemp()) { if (setMode) { this._modeSelector.mode = 'temp'; } @@ -119,7 +121,8 @@ export class HueLightDetail extends IdLitElement { if (ev.detail.mode == 'temp') { this.lightContainer.colorTemp = ev.detail.newTemp; - } else if (ev.detail.mode == 'color') { + } + else if (ev.detail.mode == 'color') { this.lightContainer.color = ev.detail.newColor; } } @@ -151,7 +154,8 @@ export class HueLightDetail extends IdLitElement { this.classList.remove('visible'); if (instant) { this.style.display = 'none'; - } else { + } + else { this._hideTimeout = setTimeout(() => { this._hideTimeout = null; this.style.display = 'none'; @@ -261,7 +265,8 @@ export class HueLightDetail extends IdLitElement { const checked = target.checked; if (checked) { ctrl.turnOn(); - } else { + } + else { ctrl.turnOff(); } } @@ -351,7 +356,8 @@ export class HueLightDetail extends IdLitElement { const addMargin = verticalSpace / 2; colorPicker.style.marginTop = (HueLightDetail.colorPickerMarginTop + addMargin) + 'px'; colorPicker.style.marginBottom = (HueLightDetail.colorPickerMarginBottom + addMargin) + 'px'; - } else { + } + else { colorPicker.style.marginTop = ''; colorPicker.style.marginBottom = ''; } @@ -377,7 +383,8 @@ export class HueLightDetail extends IdLitElement { rollup.width = rollupSize; rollup.height = rollup.heightOpened = size; rollup.iconSize = HueLightDetail.rollupBigIconSize; - } else { + } + else { rollup.style.width = ''; rollup.width = HueLightDetail.rollupWidth; rollup.height = HueLightDetail.rollupHeight; diff --git a/src/controls/pointer-drag-helper.ts b/src/controls/pointer-drag-helper.ts index f613524..33dadd0 100644 --- a/src/controls/pointer-drag-helper.ts +++ b/src/controls/pointer-drag-helper.ts @@ -44,7 +44,8 @@ export class PointerDragHelper { document.addEventListener('touchmove', this._onDragMove); document.addEventListener('touchend', this._onDragEnd); ev.preventDefault(); - } else { + } + else { document.addEventListener('mousemove', this._onDragMove); document.addEventListener('mouseup', this._onDragEnd); } diff --git a/src/core/action-handler.ts b/src/core/action-handler.ts index 87d645f..05753e7 100644 --- a/src/core/action-handler.ts +++ b/src/core/action-handler.ts @@ -66,7 +66,8 @@ export class ActionHandler { // if is on, get first onLight if (this._ctrl.isOn()) { entityId = this._ctrl.getLitLights()[0].getEntityId(); - } else { + } + else { entityId = this._config.getEntities()[0]; } } diff --git a/src/core/colors/background.ts b/src/core/colors/background.ts index 41b9b2b..efbe233 100644 --- a/src/core/colors/background.ts +++ b/src/core/colors/background.ts @@ -14,10 +14,12 @@ export class Background { throw new Error('ColorExtended cannot be used in Background. Resolve it first.'); } if (b instanceof Color) { return [b]; - } else if (b instanceof Background) { + } + else if (b instanceof Background) { // eslint-disable-next-line no-underscore-dangle return b._colors; - } else { + } + else { throw new Error('Only array of Colors or Backgrounds is supported for new Background(...).'); } }); diff --git a/src/core/colors/color-extended.ts b/src/core/colors/color-extended.ts index da56e44..75a8751 100644 --- a/src/core/colors/color-extended.ts +++ b/src/core/colors/color-extended.ts @@ -9,7 +9,8 @@ export class ColorExtended extends Color { if (colorName == ColorExtended.themeColor) { super(0, 0, 0); this._isThemeColor = true; - } else { + } + else { super(colorName); this._isThemeColor = false; } diff --git a/src/core/colors/color.ts b/src/core/colors/color.ts index fc181b4..63cbb19 100644 --- a/src/core/colors/color.ts +++ b/src/core/colors/color.ts @@ -14,14 +14,16 @@ export class Color { if (typeof colorOrRedOrHue == 'string') { this.parse(colorOrRedOrHue); this.setOpacity(opacityOrGreenOrSaturation ?? this._opacity); - } else if (mode == 'rgb') { + } + else if (mode == 'rgb') { this.setRgb( colorOrRedOrHue, opacityOrGreenOrSaturation ?? 0, blueOrValue ?? 0 ); this.setOpacity(opacity); - } else if (mode == 'hsv') { + } + else if (mode == 'hsv') { this.setHsv( colorOrRedOrHue, opacityOrGreenOrSaturation ?? 0, @@ -189,7 +191,8 @@ export class Color { if (isHex4) this.setOpacity((colorValues[3] * 16 + colorValues[3]) / 255); - } else if (isHex6 || isHex8) { + } + else if (isHex6 || isHex8) { this.setRgb( colorValues[0] * 16 + colorValues[1], colorValues[2] * 16 + colorValues[3], @@ -199,11 +202,13 @@ export class Color { this.setOpacity((colorValues[6] * 16 + colorValues[7]) / 255); } - } else if (colorId.startsWith('rgb')) { + } + else if (colorId.startsWith('rgb')) { const parts = colorId.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,?\s*(\d*(?:\.\d+\s*)?)\)$/); if (!parts) { throw new Error('Unrecognized color format rgb[a](...): ' + colorId); - } else { + } + else { // [ str, r, g, b, a|undefined ] this.setRgb( parseInt(parts[1]), @@ -214,7 +219,8 @@ export class Color { this.setOpacity(parseFloat(parts[4])); } } - } else { + } + else { if (allowNames) { // small hack: https://stackoverflow.com/a/47355187/1341409 const ctx = document.createElement('canvas').getContext('2d'); @@ -253,15 +259,20 @@ export class Color { let r1 = 0, g1 = 0, b1 = 0; if (hue1 >= 0 && hue1 <= 1) { ([r1, g1, b1] = [chroma, x, 0]); - } else if (hue1 >= 1 && hue1 <= 2) { + } + else if (hue1 >= 1 && hue1 <= 2) { ([r1, g1, b1] = [x, chroma, 0]); - } else if (hue1 >= 2 && hue1 <= 3) { + } + else if (hue1 >= 2 && hue1 <= 3) { ([r1, g1, b1] = [0, chroma, x]); - } else if (hue1 >= 3 && hue1 <= 4) { + } + else if (hue1 >= 3 && hue1 <= 4) { ([r1, g1, b1] = [0, x, chroma]); - } else if (hue1 >= 4 && hue1 <= 5) { + } + else if (hue1 >= 4 && hue1 <= 5) { ([r1, g1, b1] = [x, 0, chroma]); - } else if (hue1 >= 5 && hue1 <= 6) { + } + else if (hue1 >= 5 && hue1 <= 6) { ([r1, g1, b1] = [chroma, 0, x]); } @@ -291,7 +302,8 @@ export class Color { let h = 0, s; if (diff == 0) { h = s = 0; - } else { + } + else { s = diff / v; const rr = diffc(rabs); const gg = diffc(gabs); @@ -299,14 +311,17 @@ export class Color { if (rabs === v) { h = bb - gg; - } else if (gabs === v) { + } + else if (gabs === v) { h = (1 / 3) + rr - bb; - } else if (babs === v) { + } + else if (babs === v) { h = (2 / 3) + gg - rr; } if (h < 0) { h += 1; - } else if (h > 1) { + } + else if (h > 1) { h -= 1; } } @@ -350,7 +365,8 @@ export class Color { Math.round(g1), Math.round(b1) ]; - } else { + } + else { const k = (kelvin - tres) / (end - tres); // normalize const r2 = linearScale(k, tresRgb[0], endRgb[0]); const g2 = linearScale(k, tresRgb[1], endRgb[1]); diff --git a/src/core/effect-queue.ts b/src/core/effect-queue.ts index ae3a320..875d27e 100644 --- a/src/core/effect-queue.ts +++ b/src/core/effect-queue.ts @@ -32,7 +32,9 @@ export class HueEffectQueue { public start() { let i = 0; - const callback = () => { this.planEffect(++i, callback); }; + const callback = () => { + this.planEffect(++i, callback); + }; this.planEffect(i, callback); } diff --git a/src/core/error-info.ts b/src/core/error-info.ts index 82d8248..296df18 100644 --- a/src/core/error-info.ts +++ b/src/core/error-info.ts @@ -5,10 +5,12 @@ export class ErrorInfo { public constructor(er: unknown) { if (typeof er === 'string') { this._message = er; - } else if (er instanceof Error) { + } + else if (er instanceof Error) { this._message = er.message; this._stack = er.stack; - } else { + } + else { this._message = er?.toString() || 'UNKNOWN ERROR'; } } diff --git a/src/core/global-lights.ts b/src/core/global-lights.ts index 87d5f3c..3fe0ea7 100644 --- a/src/core/global-lights.ts +++ b/src/core/global-lights.ts @@ -12,7 +12,8 @@ export class GlobalLights { //console.log(`[GlobalLights] Creating instance for '${entity_id}'`); instance = new LightContainer(entity_id); this._containers[entity_id] = instance; - } else { + } + else { //console.log(`[GlobalLights] Reusing instance for '${entity_id}'`); } return instance; diff --git a/src/core/hass-text-template.ts b/src/core/hass-text-template.ts index 3aa0e7f..4fd8688 100644 --- a/src/core/hass-text-template.ts +++ b/src/core/hass-text-template.ts @@ -17,7 +17,8 @@ class VariableTemplatePart implements IHassTextTemplate { if (firstDot != lastDot) { this._textOrEntity = templatePart.substring(0, lastDot); this._attribute = templatePart.substring(lastDot + 1); - } else { + } + else { this._textOrEntity = templatePart; } } @@ -25,7 +26,8 @@ class VariableTemplatePart implements IHassTextTemplate { public resolveToString(hass: HomeAssistant | null) { if (!hass) { return ''; - } else { + } + else { const entity = hass.states[this._textOrEntity]; if (!entity) { // error indication @@ -132,7 +134,8 @@ export class HassTextTemplate implements IHassTextTemplate { // change state to inside variable insideVariable = true; - } else { + } + else { // searching for end of variable part index = templateText.indexOf('}}', lastIndex); if (index < 0) diff --git a/src/core/icon-helper.ts b/src/core/icon-helper.ts index b9bb436..d5192d1 100644 --- a/src/core/icon-helper.ts +++ b/src/core/icon-helper.ts @@ -16,11 +16,14 @@ export class IconHelper { if (lightCount <= 1) { lightIcon = hasHueIcons ? this.HueOneIcon : this.DefaultOneIcon; - } else if (lightCount <= 2) { + } + else if (lightCount <= 2) { lightIcon = hasHueIcons ? this.HueTwoIcon : this.DefaultTwoIcon; - } else if (lightCount <= 3) { + } + else if (lightCount <= 3) { lightIcon = hasHueIcons ? this.HueThreeIcon : this.DefaultMoreIcon; - } else { + } + else { lightIcon = hasHueIcons ? this.HueMoreIcon : this.DefaultMoreIcon; } diff --git a/src/core/light-container.ts b/src/core/light-container.ts index 7a522fb..de76e15 100644 --- a/src/core/light-container.ts +++ b/src/core/light-container.ts @@ -151,7 +151,8 @@ export class LightContainer extends NotifyBase implements ISingl if (on) { this.notifyTurnOn(); - } else { + } + else { this.notifyTurnOff(); } this._hass.callService('light', on ? 'turn_on' : 'turn_off', { entity_id: this._entity_id }); @@ -177,7 +178,8 @@ export class LightContainer extends NotifyBase implements ISingl // just to be sure if (value < 0) { value = 0; - } else if (value > 100) { + } + else if (value > 100) { value = 100; } @@ -265,7 +267,8 @@ export class LightContainer extends NotifyBase implements ISingl // just to be sure if (newTemp < minTemp) { newTemp = minTemp; - } else if (newTemp > maxTemp) { + } + else if (newTemp > maxTemp) { newTemp = maxTemp; } @@ -290,7 +293,8 @@ export class LightContainer extends NotifyBase implements ISingl if (attr.hs_color) { const [h, s] = attr.hs_color; result = new Color(h, s / 100, 1, 1, 'hsv'); - } else if (attr.rgb_color) { + } + else if (attr.rgb_color) { const [r, g, b] = attr.rgb_color; result = new Color(r, g, b); } @@ -309,7 +313,8 @@ export class LightContainer extends NotifyBase implements ISingl if (newColor.getOriginalMode() == 'hsv') { mode = HassLightColorMode.hs; serviceData.hs_color = [newColor.getHue(), newColor.getSaturation() * 100]; - } else { + } + else { mode = HassLightColorMode.rgb; serviceData.rgb_color = [newColor.getRed(), newColor.getGreen(), newColor.getBlue()]; } @@ -329,7 +334,8 @@ export class LightContainer extends NotifyBase implements ISingl if (this.isColorModeTemp() && (temp = this.colorTemp)) { const [r, g, b] = Color.hueTempToRgb(temp); bgColor = new Color(r, g, b); - } else if (this.isColorModeColor() && (color = this.color)) { + } + else if (this.isColorModeColor() && (color = this.color)) { bgColor = color; } diff --git a/src/core/light-controller.ts b/src/core/light-controller.ts index 11b12de..3b00580 100644 --- a/src/core/light-controller.ts +++ b/src/core/light-controller.ts @@ -83,7 +83,8 @@ export class LightController extends NotifyBase implements ILig if (litLights.length == 1) { litLights[0].brightnessValue = value; return; - } else if (litLights.length == 0) { // when no light is on, set value to all lights + } + else if (litLights.length == 0) { // when no light is on, set value to all lights this._lights.forEach(l => l.brightnessValue = value); return; } @@ -177,13 +178,17 @@ export class LightController extends NotifyBase implements ILig return new HassTextTemplate(result); } result = ''; - } else if (lit == 0) { + } + else if (lit == 0) { result = localize(this.hass, 'card.description.noLightsOn'); - } else if (lit == total) { + } + else if (lit == total) { result = localize(this.hass, 'card.description.allLightsOn'); - } else if (lit == 1) { + } + else if (lit == 1) { result = localize(this.hass, 'card.description.oneLightOn'); - } else { + } + else { result = localize(this.hass, 'card.description.someLightsAreOn', '%s', lit.toString()); } diff --git a/src/core/light-features.ts b/src/core/light-features.ts index 91cf3d5..02e248f 100644 --- a/src/core/light-features.ts +++ b/src/core/light-features.ts @@ -85,7 +85,8 @@ export class LightFeaturesCombined implements ILightFeatures { const f = features[i]; if (f.isOnlyBrightness()) { isBrightness = true; - } else if (!f.isEmpty()) { + } + else if (!f.isEmpty()) { // not brightness and not empty return false; } diff --git a/src/core/view-utils.ts b/src/core/view-utils.ts index 48351a2..7b709ed 100644 --- a/src/core/view-utils.ts +++ b/src/core/view-utils.ts @@ -87,11 +87,13 @@ export class ViewUtils { if (value != null) { ctrl.brightnessValue = parseInt(value); } - } else { // isToggle + } + else { // isToggle const checked = (target as HTMLInputElement).checked; if (checked) { ctrl.turnOn(); - } else { + } + else { ctrl.turnOff(); } } @@ -115,7 +117,8 @@ export class ViewUtils { let foreground: Color | null; if (currentBackground == null) { foreground = null; - } else { + } + else { const fgx = this.calculateForeground(ctrl, currentBackground, assumeShadow); foreground = fgx.foreground; } @@ -155,7 +158,8 @@ export class ViewUtils { if (ctrl.isOff()) { if (foreground == Consts.DarkColor) { foreground = Consts.DarkOffColor; - } else { + } + else { foreground = Consts.LightOffColor; } } diff --git a/src/hue-like-light-card.ts b/src/hue-like-light-card.ts index 5d26b55..f50e4ed 100644 --- a/src/hue-like-light-card.ts +++ b/src/hue-like-light-card.ts @@ -65,7 +65,8 @@ export class HueLikeLightCard extends LitElement implements LovelaceCard { this._error = undefined; action(); - } catch (e) { + } + catch (e) { this._error = new ErrorInfo(e); this.requestUpdate(); // render error @@ -86,7 +87,8 @@ export class HueLikeLightCard extends LitElement implements LovelaceCard { const offColor = this._config.getOffColor(); if (!offColor.isThemeColor()) { this._offBackground = new Background([offColor.getBaseColor()]); - } else { + } + else { this._offBackground = null; } @@ -279,7 +281,8 @@ export class HueLikeLightCard extends LitElement implements LovelaceCard { if (card == null) { // wait for card element this._haShadow = null; - } else { + } + else { // since HA 2022.11 default ha-card has no shadow card.classList.add('new-borders'); } @@ -396,9 +399,13 @@ export class HueLikeLightCard extends LitElement implements LovelaceCard { if (tapArea && !this._mc) { this._mc = new Manager(tapArea); this._mc.add(new Press()); - this._mc.on('press', ():void => { this.cardHolded(); }); + this._mc.on('press', ():void => { + this.cardHolded(); + }); this._mc.add(new Tap()); - this._mc.on('tap', ():void => { this.cardClicked(); }); + this._mc.on('tap', ():void => { + this.cardClicked(); + }); } } diff --git a/src/localize/localize.ts b/src/localize/localize.ts index 99018f4..b31a464 100644 --- a/src/localize/localize.ts +++ b/src/localize/localize.ts @@ -53,7 +53,8 @@ export function localize(hassOrLanguage:HomeAssistant | string, resource: keyof let lang: string; if (typeof hassOrLanguage == 'string') { lang = hassOrLanguage; - } else { + } + else { lang = hassOrLanguage.language || defaultLang; } diff --git a/src/types/config.ts b/src/types/config.ts index 7d109ba..34ccd13 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -175,7 +175,9 @@ export class HueLikeLightCardConfig implements HueLikeLightCardConfigInterface { public readonly iconSize: number; public readonly showSwitch: boolean; public readonly slider: SliderType; - public get scenes() { return this._scenes || []; } + public get scenes() { + return this._scenes || []; + } public readonly sceneOrder: SceneOrder; public readonly offClickAction: ClickAction; public readonly offClickData: ClickActionData; @@ -222,7 +224,8 @@ export class HueLikeLightCardConfig implements HueLikeLightCardConfigInterface { this.entities && this.entities.forEach(e => { if (typeof e == 'string') { ents.push(e); - } else if (e.entity) { + } + else if (e.entity) { ents.push(e.entity); } }); @@ -273,7 +276,9 @@ export class HueLikeLightCardConfig implements HueLikeLightCardConfigInterface { try { // get entities, and create ordered list based on order of entities in config const entities = removeDuplicites(this.getEntities()); - const lightRelations = entities.map(entityId => { return { entityId }; }) as EntityRelations[]; + const lightRelations = entities.map(entityId => { + return { entityId }; + }) as EntityRelations[]; // load all areas await Promise.all(lightRelations.map(async relation => { @@ -303,7 +308,8 @@ export class HueLikeLightCardConfig implements HueLikeLightCardConfigInterface { // set to config this._scenes = HueLikeLightCardConfig.getScenesArray(loadedScenes); - } catch (error) { + } + catch (error) { console.error('Cannot load scenes from HA.'); console.error(error); } diff --git a/src/types/theme-helper.ts b/src/types/theme-helper.ts index 947a00d..2c85542 100644 --- a/src/types/theme-helper.ts +++ b/src/types/theme-helper.ts @@ -65,7 +65,8 @@ export class ThemeHelper { applyThemesOnElement(element, themes, theme); if (theme != Consts.ThemeDefault) { element.dataset.themeLocal = theme; - } else { + } + else { delete element.dataset.themeLocal; } @@ -137,7 +138,8 @@ export class ThemeHelper { ); break; } - } else { + } + else { element.style.setProperty( targetVariable, `var(${possibleVar})` diff --git a/src/types/types-config.ts b/src/types/types-config.ts index 9607ff6..f57197b 100644 --- a/src/types/types-config.ts +++ b/src/types/types-config.ts @@ -39,12 +39,14 @@ export class ClickActionData { public constructor(plainConfig: string | Record | ClickActionData | undefined) { if (typeof plainConfig == 'string') { this._onlyValue = plainConfig; - } else if (plainConfig instanceof ClickActionData) { + } + else if (plainConfig instanceof ClickActionData) { // eslint-disable-next-line no-underscore-dangle this._onlyValue = plainConfig._onlyValue; // eslint-disable-next-line no-underscore-dangle this._valueStore = plainConfig._valueStore; - } else { + } + else { this._valueStore = plainConfig || {}; } } @@ -112,7 +114,8 @@ export class SceneData { public constructor(configOrEntityId: SceneConfig | string) { if (typeof configOrEntityId == 'string') { this._config = new SceneConfig(configOrEntityId); - } else { + } + else { this._config = configOrEntityId; } }