From f6147a078784a1b74558205d5267666760c278e9 Mon Sep 17 00:00:00 2001 From: Gemini Bot Date: Fri, 21 Nov 2025 12:13:59 +0100 Subject: [PATCH] Initial commit: Add Pstryk Energy Card v4.1.0 - Add main card implementation with full/compact/super_compact modes - Support for sparkline and bars widgets with effects - Price color coding based on best/worst price ranges - Alert system for high/low price thresholds - Polish/English translations support - HACS integration configuration - Development guidelines in AGENTS.md --- AGENTS.md | 27 ++ README.md | 94 ++++ hacs.json | 5 + pstryk-card.js | 1230 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1356 insertions(+) create mode 100644 AGENTS.md create mode 100644 README.md create mode 100644 hacs.json create mode 100644 pstryk-card.js diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..8455996 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,27 @@ +# Agent Guidelines for Pstryk Energy Card + +## Build/Test Commands +- No build system - single JavaScript file (`pstryk-card.js`) +- Test by adding card to Home Assistant dashboard +- Debug mode: set `debug: true` in card config +- No linting/formatting tools configured + +## Code Style Guidelines +- **Language**: Vanilla JavaScript ES6+ (no frameworks) +- **File structure**: Single file with embedded CSS in template literals +- **Class naming**: PascalCase (e.g., `PstrykCard`) +- **Method naming**: camelCase with underscore prefix for private methods (e.g., `_getTranslations`) +- **Variables**: camelCase, use const/let appropriately +- **Comments**: Polish comments for user-facing text, English for technical notes +- **Error handling**: Throw descriptive Error objects in `setConfig()` for validation +- **Translations**: Support PL/EN via `_getTranslations()` method +- **CSS**: Use CSS custom properties for theming, embed in ` + + + ${titleHtml} + +
+
+ ${buyAlert && !isSuperCompact ? `
${this.translate('alert')}
` : ''} + ${isSuperCompact ? ` +
+
+ +
+
+ ${this.formatPrice(buyPrice)} +
+
+ ` : ` +
+ +
+
${this.translate('buy_price')}
+
+ ${this.formatPrice(buyPrice)} +
+ ${attributeHtml(buyAttribute)} + ${buyWidgetHtml} + `} +
+ +
+ ${sellAlert && !isSuperCompact ? `
${this.translate('alert')}
` : ''} + ${isSuperCompact ? ` +
+
+ +
+
+ ${this.formatPrice(sellPrice)} +
+
+ ` : ` +
+ +
+
${this.translate('sell_price')}
+
+ ${this.formatPrice(sellPrice)} +
+ ${attributeHtml(sellAttribute)} + ${sellWidgetHtml} + `} +
+
+ + ${legendHtml} +
+ `; + + // Dodaj event listenery po renderowaniu + if (this._config.click_action !== 'none') { + this.shadowRoot.querySelectorAll('.price-box').forEach((box, index) => { + const entityId = index === 0 ? this._config.buy_entity : this._config.sell_entity; + box.addEventListener('click', () => this.handleClick(entityId)); + }); + } + } +} + +// Rejestracja karty +customElements.define('pstryk-card', PstrykCard); + +// Dodaj do okna dla łatwego debugowania +window.customCards = window.customCards || []; +window.customCards.push({ + type: 'pstryk-card', + name: 'Pstryk Energy Card', + description: 'Display energy prices with color coding, widgets (sparkline/bars), and alerts', + preview: true, + version: '4.1.0' +});