New HA integration (integration/custom_components/luma_home/) with: - WS API: luma/get_config (Lovelace→v2 bridge), luma/pair, luma/pair_status - Config flow with dashboard URL path setting 8 HACS frontend cards (cards/) matching TV app visual spec: - toggle, range, climate, media, curtain, action, vacuum, weather - Glass card design: rgba(36,40,48,0.75) bg, 22px radius, accent glows Pairing page (pairing/luma-pair.html) for TV token provisioning. Web dashboard (web-dashboard/) — legacy config editor (deprecated). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
121 lines
5.6 KiB
JavaScript
121 lines
5.6 KiB
JavaScript
const LUMA_CLIMATE_VERSION = '0.1.0';
|
|
|
|
class LumaClimateCard extends HTMLElement {
|
|
set hass(hass) { this._hass = hass; this._render(); }
|
|
|
|
setConfig(config) {
|
|
if (!config.entity) throw new Error('Entity is required');
|
|
this._config = { entity: config.entity, name: config.name || '', size: config.size || '1x1',
|
|
accent_color: config.accent_color || '', icon: config.icon || '',
|
|
tap_action: config.tap_action || { action: 'more-info' },
|
|
hold_action: config.hold_action || { action: 'more-info' }, ...config };
|
|
this._render();
|
|
}
|
|
|
|
getCardSize() { return (this._config?.size === '1x2' || this._config?.size === '2x2') ? 4 : 2; }
|
|
static getStubConfig() { return { entity: '', name: '', size: '1x1' }; }
|
|
connectedCallback() { if (!this.shadowRoot) this.attachShadow({ mode: 'open' }); this._render(); }
|
|
|
|
_getState() { return this._hass?.states?.[this._config?.entity]; }
|
|
|
|
_getAccent() {
|
|
if (this._config?.accent_color) return this._config.accent_color;
|
|
const s = this._getState();
|
|
if (!s) return '#bbbbbb';
|
|
switch (s.state) {
|
|
case 'heat': case 'heat_cool': case 'auto': return '#f0a060';
|
|
case 'cool': return '#60b0f0';
|
|
default: return '#bbbbbb';
|
|
}
|
|
}
|
|
|
|
_getFillColor() {
|
|
const s = this._getState();
|
|
if (!s) return 'transparent';
|
|
switch (s.state) {
|
|
case 'heat': case 'heat_cool': case 'auto': return 'rgba(240,96,64,0.28)';
|
|
case 'cool': return 'rgba(64,144,240,0.28)';
|
|
default: return 'rgba(240,160,96,0.15)';
|
|
}
|
|
}
|
|
|
|
_isActive() {
|
|
const s = this._getState();
|
|
return s && s.state !== 'off' && s.state !== 'unavailable';
|
|
}
|
|
|
|
_handleClick() {
|
|
if (!this._hass || !this._config) return;
|
|
const ev = new Event('hass-more-info', { composed: true });
|
|
ev.detail = { entityId: this._config.entity };
|
|
this.dispatchEvent(ev);
|
|
}
|
|
|
|
_render() {
|
|
if (!this.shadowRoot || !this._config) return;
|
|
const s = this._getState();
|
|
const isActive = this._isActive();
|
|
const accent = this._getAccent();
|
|
const fill = this._getFillColor();
|
|
const name = this._config.name || s?.attributes?.friendly_name || '';
|
|
const icon = this._config.icon || 'mdi:thermometer';
|
|
const currentTemp = s?.attributes?.current_temperature ?? '--';
|
|
const targetTemp = s?.attributes?.temperature ?? '--';
|
|
const hvac = s?.state || 'off';
|
|
const modeLabel = { heat: 'Heat', cool: 'Cool', heat_cool: 'Auto', auto: 'Auto', off: 'Off' }[hvac] || hvac;
|
|
|
|
this.shadowRoot.innerHTML = `
|
|
<style>
|
|
:host { display: block; --accent: ${accent}; }
|
|
.card {
|
|
position: relative; overflow: hidden; background: rgba(36,40,48,0.75);
|
|
border: 1px solid rgba(255,255,255,0.10); border-radius: 22px; padding: 16px;
|
|
cursor: pointer; transition: border-color .15s, box-shadow .15s;
|
|
height: 100%; min-height: 140px; display: flex; flex-direction: column;
|
|
justify-content: space-between; box-shadow: 0 2px 6px rgba(0,0,0,.06);
|
|
}
|
|
.card:hover { border-color: rgba(255,255,255,0.18); box-shadow: 0 8px 28px rgba(0,0,0,.28); }
|
|
.card.active { border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
|
|
.glow {
|
|
position: absolute; top: -20px; left: -20px; width: 200px; height: 200px;
|
|
border-radius: 50%; pointer-events: none; opacity: 0; transition: opacity .2s;
|
|
background: radial-gradient(circle, ${fill} 0%, transparent 70%);
|
|
}
|
|
.card.active .glow { opacity: 1; }
|
|
.top { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
|
|
.icon-circle {
|
|
width: 48px; height: 48px; border-radius: 24px; display: flex;
|
|
align-items: center; justify-content: center; flex-shrink: 0;
|
|
background: ${isActive ? `color-mix(in srgb, var(--accent) 20%, transparent)` : 'rgba(255,255,255,0.08)'};
|
|
}
|
|
.icon-circle ha-icon { --mdc-icon-size: 28px; color: var(--accent); }
|
|
.info { flex: 1; min-width: 0; }
|
|
.mode-label { font-size: 12px; font-weight: 400; letter-spacing: 0.04em; color: ${isActive ? 'var(--accent)' : 'rgba(232,232,232,0.45)'}; }
|
|
.name { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
|
|
.bottom { position: relative; z-index: 1; }
|
|
.now { font-size: 12px; font-weight: 400; letter-spacing: 0.02em; color: rgba(232,232,232,0.55); margin-bottom: 2px; }
|
|
.target { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: ${isActive ? '#fff' : 'rgba(187,187,187,0.5)'}; }
|
|
</style>
|
|
<div class="card ${isActive ? 'active' : ''}">
|
|
<div class="glow"></div>
|
|
<div class="top">
|
|
<div class="icon-circle"><ha-icon icon="${icon}"></ha-icon></div>
|
|
<div class="info">
|
|
<div class="mode-label">${modeLabel}</div>
|
|
<div class="name">${name}</div>
|
|
</div>
|
|
</div>
|
|
<div class="bottom">
|
|
<div class="now">Now ${currentTemp}°C</div>
|
|
<div class="target">${targetTemp}°</div>
|
|
</div>
|
|
</div>`;
|
|
this.shadowRoot.querySelector('.card').addEventListener('click', () => this._handleClick());
|
|
}
|
|
}
|
|
|
|
customElements.define('luma-climate-card', LumaClimateCard);
|
|
window.customCards = window.customCards || [];
|
|
window.customCards.push({ type: 'luma-climate-card', name: 'Luma Climate', description: 'Luma-style climate/thermostat card with temperature display.', preview: true });
|
|
console.info(`%c LUMA-CLIMATE-CARD %c v${LUMA_CLIMATE_VERSION} `, 'background:#f0a060;color:#111;font-weight:bold', 'background:#161a22;color:#f0a060');
|